本文整理汇总了Python中goose.utils.FileHelper类的典型用法代码示例。如果您正苦于以下问题:Python FileHelper类的具体用法?Python FileHelper怎么用?Python FileHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, language="en"):
# TODO replace 'x' with class
# to generate dynamic path for file to load
if not language in self._cached_stop_words:
path = "text/stopwords-%s.txt" % language
try:
self._cached_stop_words[language] = set(FileHelper.loadResourceFile(path).splitlines())
except:
self._cached_stop_words[language] = set(
FileHelper.loadResourceFile("text/stopwords-en.txt").splitlines()
)
self.STOP_WORDS = self._cached_stop_words[language]
示例2: loadCustomSiteMapping
def loadCustomSiteMapping(self):
# TODO
dataFile = FileHelper.loadResourceFile("images/known-image-css.txt", "xx")
lines = dataFile.splitlines()
for line in lines:
domain, css = line.split('^')
self.customSiteMapping.update({domain:css})
示例3: html_content
def html_content(self, req):
current_test = self.cls._get_current_testname()
path = os.path.join(
os.path.dirname(CURRENT_PATH), "data", "extractors", "images", current_test, "%s.html" % current_test
)
path = os.path.abspath(path)
return FileHelper.loadResourceFile(path)
示例4: __init__
def __init__(self, language='en'):
# TODO replace 'x' with class
# to generate dynamic path for file to load
if not language in self._cached_stop_words:
path = os.path.join('text', 'stopwords-%s.txt' % language)
self._cached_stop_words[language] = set(FileHelper.loadResourceFile(path).splitlines())
self.STOP_WORDS = self._cached_stop_words[language]
示例5: __init__
def __init__(self, language="zh"):
# force zh languahe code
language = "zh"
if not language in self._cached_stop_words:
path = "text/stopwords-%s.txt" % language
self._cached_stop_words[language] = set(FileHelper.loadResourceFile(path).splitlines())
self.STOP_WORDS = self._cached_stop_words[language]
示例6: content
def content(self, req):
current_test = self.cls._get_current_testname()
path = os.path.join(CURRENT_PATH, "data", "extractors",
"%s.html" % current_test)
path = os.path.abspath(path)
content = FileHelper.loadResourceFile(path)
return content
示例7: load_test_file
def load_test_file(self, suffix):
suite, module, cls, func = self.id().split('.')
path = os.path.join(CURRENT_PATH, "data", module, "%s%s" % (func, suffix))
path = os.path.abspath(path)
try:
return FileHelper.loadResourceFile(path)
except IOError:
print "No File"
示例8: content
def content(self, req):
current_test = self.cls._get_current_testname()
path = os.path.join(CURRENT_PATH, "data", "extractors", "%s.html" % current_test)
path = os.path.abspath(path)
content = FileHelper.loadResourceFile(path)
if content is None:
raise Exception ("Test could not be found")
return content
示例9: load_customesite_mapping
def load_customesite_mapping(self):
# TODO
path = os.path.join('images', 'known-image-css.txt')
data_file = FileHelper.loadResourceFile(path)
lines = data_file.splitlines()
for line in lines:
domain, css = line.split('^')
self.custom_site_mapping.update({domain: css})
示例10: loadData
def loadData(self):
"""\
"""
suite, module, cls, func = self.id().split('.')
path = os.path.join(CURRENT_PATH, "data", module, "%s.json" % func)
path = os.path.abspath(path)
content = FileHelper.loadResourceFile(path)
self.data = json.loads(content)
示例11: loadData
def loadData(self):
"""\
"""
test, suite, module, cls, func = self.id().split(".")
path = os.path.join(os.path.dirname(CURRENT_PATH), "data", suite, module, func, "%s.json" % func)
path = os.path.abspath(path)
content = FileHelper.loadResourceFile(path)
self.data = json.loads(content)
示例12: getRawHtml
def getRawHtml(self):
test, suite, module, cls, func = self.id().split('.')
path = os.path.join(
os.path.dirname(CURRENT_PATH),
"data",
suite,
module,
"%s.html" % func)
path = os.path.abspath(path)
content = FileHelper.loadResourceFile(path)
return content
示例13: __init__
def __init__(self, language='en'):
# TODO replace 'x' with class
# to generate dynamic path for file to load
if not language in self._cached_stop_words:
path = os.path.join('text', 'stopwords-%s.txt' % language)
try:
content = FileHelper.loadResourceFile(path)
word_list = content.splitlines()
except IOError:
word_list = []
self._cached_stop_words[language] = set(word_list)
self.STOP_WORDS = self._cached_stop_words[language]
示例14: __init__
def __init__(self, language='en'):
# TODO replace 'x' with class
# to generate dynamic path for file to load
if isinstance(language,str): language = [language]
language = set(language)
self.char_split = False
if 'zh' in language or 'ko' in language or 'ja' in language: self.char_split = True
self.STOP_WORDS = None
for l in language:
if not l in StopWords._cached_stop_words:
path = 'text/stopwords-%s.txt' % l
try:
_stop_list = FileHelper.loadResourceFile(path)
if l in ['zh','ko','ja']: _stop_list = _stop_list.decode('utf-8')
StopWords._cached_stop_words[l] = set(_stop_list.splitlines())
except:
StopWords._cached_stop_words[l] = set()
if self.STOP_WORDS is None: self.STOP_WORDS = StopWords._cached_stop_words[l]
else: self.STOP_WORDS |= StopWords._cached_stop_words[l]
示例15: __init__
def __init__(self, language='en'):
self.PUNCTUATION = re.compile("[^\\p{Ll}\\p{Lu}\\p{Lt}\\p{Lo}\\p{Nd}\\p{Pc}\\s]")
# TODO replace 'x' with class
# to generate dynamic path for file to load
path = 'text/stopwords-%s.txt' % language
self.STOP_WORDS = set(FileHelper.loadResourceFile(path, 'x').splitlines())