_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q250700 | _build_enum_type | train | def _build_enum_type(var, property_path=None):
""" Builds schema definitions for enum type values.
:param var: The enum type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:return: The built schema definition
:rtype: Dict[str, Any]
... | python | {
"resource": ""
} |
q250701 | _build_string_type | train | def _build_string_type(var, property_path=None):
""" Builds schema definitions for string type values.
:param var: The string type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The buil... | python | {
"resource": ""
} |
q250702 | _build_integer_type | train | def _build_integer_type(var, property_path=None):
""" Builds schema definitions for integer type values.
:param var: The integer type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The b... | python | {
"resource": ""
} |
q250703 | _build_number_type | train | def _build_number_type(var, property_path=None):
""" Builds schema definitions for number type values.
:param var: The number type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The buil... | python | {
"resource": ""
} |
q250704 | _build_array_type | train | def _build_array_type(var, property_path=None):
""" Builds schema definitions for array type values.
:param var: The array type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The built s... | python | {
"resource": ""
} |
q250705 | _build_object_type | train | def _build_object_type(var, property_path=None):
""" Builds schema definitions for object type values.
:param var: The object type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The buil... | python | {
"resource": ""
} |
q250706 | _build_type | train | def _build_type(type_, value, property_path=None):
""" Builds the schema definition based on the given type for the given value.
:param type_: The type of the value
:param value: The value to build the schema definition for
:param List[str] property_path: The property path of the current type,
... | python | {
"resource": ""
} |
q250707 | _build_var | train | def _build_var(var, property_path=None):
""" Builds a schema definition for a given config var.
:param attr._make.Attribute var: The var to generate a schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:raises ValueError: When... | python | {
"resource": ""
} |
q250708 | _build_config | train | def _build_config(config_cls, property_path=None):
""" Builds the schema definition for a given config class.
:param class config_cls: The config class to build a schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:raises Valu... | python | {
"resource": ""
} |
q250709 | _build | train | def _build(value, property_path=None):
""" The generic schema definition build method.
:param value: The value to build a schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:return: The built schema definition
:rtype: Dict... | python | {
"resource": ""
} |
q250710 | _get_types | train | def _get_types(type_):
""" Gathers all types within the ``TYPE_MAPPINGS`` for a specific ``Types`` value.
:param Types type_: The type to retrieve
:return: All types within the ``TYPE_MAPPINGS``
:rtype: list
"""
return list(
| python | {
"resource": ""
} |
q250711 | decode_bytes | train | def decode_bytes(string):
""" Decodes a given base64 string into bytes.
:param str string: The string to decode
:return: The decoded bytes
:rtype: bytes
| python | {
"resource": ""
} |
q250712 | is_config_var | train | def is_config_var(var):
""" Checks if the given value is a valid ``file_config.var``.
:param var: The value to check
:return: True if the given value is | python | {
"resource": ""
} |
q250713 | is_config_type | train | def is_config_type(type_):
""" Checks if the given type is ``file_config.config`` decorated.
:param type_: The type to check
:return: True if | python | {
"resource": ""
} |
q250714 | is_enum_type | train | def is_enum_type(type_):
""" Checks if the given type is an enum type.
:param type_: The type to check
:return: True if the type is a enum type, otherwise False
:rtype: bool | python | {
"resource": ""
} |
q250715 | is_regex_type | train | def is_regex_type(type_):
""" Checks if the given type is a regex type.
:param type_: The type to check
:return: True if the type is a regex type, otherwise False
:rtype: bool
"""
return (
callable(type_)
| python | {
"resource": ""
} |
q250716 | is_union_type | train | def is_union_type(type_):
""" Checks if the given type is a union type.
:param type_: The type to check
:return: True if the type is a union type, otherwise False | python | {
"resource": ""
} |
q250717 | is_string_type | train | def is_string_type(type_):
""" Checks if the given type is a string type.
:param type_: The type to check
:return: True if the type is a string type, otherwise False
:rtype: bool
"""
| python | {
"resource": ""
} |
q250718 | is_array_type | train | def is_array_type(type_):
""" Checks if the given type is a array type.
:param type_: The type to check
:return: True if the type is a array type, otherwise False
:rtype: bool
"""
array_types = _get_types(Types.ARRAY)
if is_typing_type(type_):
return type_ in | python | {
"resource": ""
} |
q250719 | is_object_type | train | def is_object_type(type_):
""" Checks if the given type is a object type.
:param type_: The type to check
:return: True if the type is a object type, otherwise False
:rtype: bool
"""
object_types = _get_types(Types.OBJECT)
if is_typing_type(type_):
return type_ in | python | {
"resource": ""
} |
q250720 | typecast | train | def typecast(type_, value):
""" Tries to smartly typecast the given value with the given type.
:param type_: The type to try to use for the given value
:param value: The value to try and typecast to the given type
:return: The typecasted value if possible, otherwise just the original value
"""
... | python | {
"resource": ""
} |
q250721 | clean | train | def clean(ctx):
""" Clean built docs.
"""
clean_command = f"make clean"
with ctx.cd(ctx.docs.directory.as_posix()):
report.info(ctx, | python | {
"resource": ""
} |
q250722 | build_news | train | def build_news(ctx, draft=False, yes=False):
""" Build towncrier newsfragments.
"""
report.info(ctx, "docs.build-news", "building changelog from news fragments")
build_command = f"towncrier --version {ctx.metadata['version']}"
if draft:
report.warn(
ctx,
"docs.build-... | python | {
"resource": ""
} |
q250723 | build | train | def build(ctx, output="html"):
""" Build docs.
"""
with ctx.cd(ctx.docs.directory.as_posix()):
build_command = f"make {output}"
| python | {
"resource": ""
} |
q250724 | view | train | def view(ctx):
""" Build and view docs.
"""
report.info(ctx, "docs.view", f"viewing documentation")
| python | {
"resource": ""
} |
q250725 | INIParser._encode_var | train | def _encode_var(cls, var):
""" Encodes a variable to the appropriate string format for ini files.
:param var: The variable to encode
:return: The ini representation of the variable
:rtype: str
"""
if isinstance(var, str):
if any(_ | python | {
"resource": ""
} |
q250726 | INIParser._decode_var | train | def _decode_var(cls, string):
""" Decodes a given string into the appropriate type in Python.
:param str string: The string to decode
:return: The decoded value
"""
str_match = cls.quoted_string_regex.match(string)
if str_match:
return string.strip("'" if st... | python | {
"resource": ""
} |
q250727 | INIParser._build_dict | train | def _build_dict(
cls, parser_dict, delimiter=DEFAULT_DELIMITER, dict_type=collections.OrderedDict
):
""" Builds a dictionary of ``dict_type`` given the ``parser._sections`` dict.
:param dict parser_dict: The ``parser._sections`` mapping
:param str delimiter: The delimiter for nested... | python | {
"resource": ""
} |
q250728 | INIParser._build_parser | train | def _build_parser(
cls,
dictionary,
parser,
section_name,
delimiter=DEFAULT_DELIMITER,
empty_sections=False,
):
""" Populates a parser instance with the content of a dictionary.
:param dict dictionary: The dictionary to use for populating the parser i... | python | {
"resource": ""
} |
q250729 | INIParser.from_dict | train | def from_dict(
cls,
dictionary,
root_section="root",
delimiter=DEFAULT_DELIMITER,
empty_sections=False,
):
""" Create an instance of ``INIParser`` from a given dictionary.
:param dict dictionary: The dictionary to create an instance from
:param str ro... | python | {
"resource": ""
} |
q250730 | INIParser.to_dict | train | def to_dict(self, delimiter=DEFAULT_DELIMITER, dict_type=collections.OrderedDict):
""" Get the dictionary representation of the current parser.
:param str delimiter: The delimiter used for nested dictionaries,
defaults to ":", optional
:param class dict_type: The dictionary type to ... | python | {
"resource": ""
} |
q250731 | INIParser.to_ini | train | def to_ini(self):
""" Get the ini string of the current parser.
:return: The ini string of the | python | {
"resource": ""
} |
q250732 | format | train | def format(ctx):
""" Auto format package source files.
"""
isort_command = f"isort -rc {ctx.package.directory!s}"
black_command = | python | {
"resource": ""
} |
q250733 | check | train | def check(ctx):
""" Check built package is valid.
"""
check_command = | python | {
"resource": ""
} |
q250734 | licenses | train | def licenses(
ctx,
summary=False,
from_classifier=False,
with_system=False,
with_authors=False,
with_urls=False,
):
""" List dependency licenses.
"""
licenses_command = "pip-licenses --order=license"
report.info(ctx, "package.licenses", "listing licenses of package dependencies"... | python | {
"resource": ""
} |
q250735 | version | train | def version(ctx, version=None, force=False):
""" Specify a new version for the package.
.. important:: If no version is specified, will take the most recent parsable git
tag and bump the patch number.
:param str version: The new version of the package.
:param bool force: If True, skips version... | python | {
"resource": ""
} |
q250736 | stub | train | def stub(ctx):
""" Generate typing stubs for the package.
"""
report.info(ctx, "package.stub", f"generating typing stubs for package")
ctx.run(
f"stubgen --include-private --no-import "
| python | {
"resource": ""
} |
q250737 | s | train | def s(obj):
"""Helper to normalize linefeeds in strings."""
if isinstance(obj, bytes):
| python | {
"resource": ""
} |
q250738 | parse_config | train | def parse_config(file_path):
"""Loads the configuration file given as parameter"""
config_parser = configparser.ConfigParser()
config_parser.read(file_path)
plugin_config = {}
options = config_parser.options(CONFIG_OPTION)
for option in options:
try:
plugin_config[option] = c... | python | {
"resource": ""
} |
q250739 | start_plugin | train | def start_plugin(file_path=None):
"""This function initialize the Ocean plugin"""
if os.getenv('CONFIG_PATH'):
file_path = os.getenv('CONFIG_PATH')
else:
file_path = file_path
if file_path is not None:
config = parse_config(file_path) | python | {
"resource": ""
} |
q250740 | Segment.store | train | def store(self, extractions: List[Extraction], attribute: str, group_by_tags: bool = True) -> None:
"""
Records extractions in the container, and for each individual extraction inserts a
ProvenanceRecord to record where the extraction is stored.
Records the "output_segment" in the proven... | python | {
"resource": ""
} |
q250741 | loadRule | train | def loadRule(rule_json_object):
""" Method to load the rules - when adding a new rule it must be added to the if statement within this method. """
name = rule_json_object['name']
rule_type = rule_json_object['rule_type']
validation_regex = None
required = False
removehtml = False
include_end... | python | {
"resource": ""
} |
q250742 | OntologyNamespaceManager.parse_uri | train | def parse_uri(self, text: str) -> URIRef:
"""
Parse input text into URI
:param text: can be one of
1. URI, directly return
2. prefix:name, query namespace for prefix, return expanded URI
3. name, use default namespace to expand it and return it
... | python | {
"resource": ""
} |
q250743 | OntologyNamespaceManager.bind | train | def bind(self, prefix: str, namespace: str, override=True, replace=False):
"""
bind a given namespace to the prefix, forbids same prefix with different namespace
:param prefix:
:param namespace:
:param override: if override, rebind, even if the given namespace is already bound t... | python | {
"resource": ""
} |
q250744 | ETK.parse_json_path | train | def parse_json_path(self, jsonpath):
"""
Parse a jsonpath
Args:
jsonpath: str
Returns: a parsed json path
"""
if jsonpath not in self.parsed:
try:
self.parsed[jsonpath] = self.parser(jsonpath)
| python | {
"resource": ""
} |
q250745 | ETK.load_glossary | train | def load_glossary(file_path: str, read_json=False) -> List[str]:
"""
A glossary is a text file, one entry per line.
Args:
file_path (str): path to a text file containing a glossary.
read_json (bool): set True if the glossary is in json format
Returns: List of the... | python | {
"resource": ""
} |
q250746 | ETK.load_spacy_rule | train | def load_spacy_rule(file_path: str) -> Dict:
"""
A spacy rule file is a json file.
Args:
file_path (str): path to a text file containing a spacy rule sets.
| python | {
"resource": ""
} |
q250747 | ETK.load_ems | train | def load_ems(self, modules_paths: List[str]):
"""
Load all extraction modules from the path
Args:
modules_path: str
Returns:
"""
all_em_lst = []
if modules_paths:
for modules_path in modules_paths:
em_lst = []
... | python | {
"resource": ""
} |
q250748 | ETK.classes_in_module | train | def classes_in_module(module) -> List:
"""
Return all classes with super class ExtractionModule
Args:
module:
Returns: List of classes
"""
md = module.__dict__
return [
md[c] for c in md if (
isinstance(md[c], type) a... | python | {
"resource": ""
} |
q250749 | Document.summary | train | def summary(self, html_partial=False):
"""Generate the summary of the html docuemnt
:param html_partial: return only the div of the document, don't wrap
in html and body tags.
"""
try:
ruthless = True
#Added recall priority flag
... | python | {
"resource": ""
} |
q250750 | ExtractableBase.list2str | train | def list2str(self, l: List, joiner: str) -> str:
"""
Convert list to str as input for tokenizer
Args:
l (list): list for converting
joiner (str): join the elements using this string to separate them.
Returns: the value of the list as a string
"""
... | python | {
"resource": ""
} |
q250751 | ExtractableBase.dict2str | train | def dict2str(self, d: Dict, joiner: str) -> str:
"""
Convert dict to str as input for tokenizer
Args:
d (dict): dict for converting
joiner (str): join the elements using this string to separate them.
Returns: the value of the dict as a string
"""
... | python | {
"resource": ""
} |
q250752 | Extractable.get_tokens | train | def get_tokens(self, tokenizer: Tokenizer) -> List[Token]:
"""
Tokenize this Extractable.
If the value is a string, it returns the tokenized version of the string. Else, convert to string with
get_string method
As it is common to need the same tokens for multiple extractors, th... | python | {
"resource": ""
} |
q250753 | AlignmentHelper.uri_from_fields | train | def uri_from_fields(prefix, *fields):
"""Construct a URI out of the fields, concatenating them after removing offensive characters.
When all the | python | {
"resource": ""
} |
q250754 | parse_phone | train | def parse_phone(parts, allow_multiple=False):
"""
Parse the phone number from the ad's parts
parts -> The backpage ad's posting_body, separated into substrings
allow_multiple -> If false, arbitrarily chooses the most commonly occurring phone
"""
# Get text substitutions (ex: 'three' -> '3')
t... | python | {
"resource": ""
} |
q250755 | DateExtractor._wrap_extraction | train | def _wrap_extraction(self, date_object: datetime.datetime,
original_text: str,
start_char: int,
end_char: int
) -> Extraction or None:
"""
wrap the final result as an Extraction and return
"""
... | python | {
"resource": ""
} |
q250756 | DateExtractor._remove_overlapped_date_str | train | def _remove_overlapped_date_str(self, results: List[List[dict]]) -> List[Extraction]:
"""
some string may be matched by multiple date templates,
deduplicate the results and return a single list
"""
res = []
all_results = []
for x in results:
all_resul... | python | {
"resource": ""
} |
q250757 | custom_decode | train | def custom_decode(encoding):
"""Overrides encoding when charset declaration
or charset determination is a subset of a larger
charset. Created because of issues with Chinese websites"""
encoding = encoding.lower()
alternates = {
'big5': 'big5hkscs',
'gb2312': 'gb18030',
| python | {
"resource": ""
} |
q250758 | KGSchema.iso_date | train | def iso_date(d) -> str:
"""
Return iso format of a date
Args:
d:
Returns: str
"""
if isinstance(d, datetime):
return d.isoformat()
elif isinstance(d, date):
return datetime.combine(d, datetime.min.time()).isoformat()
e... | python | {
"resource": ""
} |
q250759 | KGSchema.is_valid | train | def is_valid(self, field_name, value) -> (bool, object):
"""
Return true if the value type matches or can be coerced to the defined type in schema, otherwise false.
If field not defined, return none
Args:
field_name: str
value:
Returns: bool, value, wher... | python | {
"resource": ""
} |
q250760 | KGSchema.is_date | train | def is_date(v) -> (bool, date):
"""
Boolean function for checking if v is a date
Args:
v:
Returns: bool
"""
if isinstance(v, date):
return True, v
try:
reg = r'^([0-9]{4})(?:-(0[1-9]|1[0-2])(?:-(0[1-9]|[1-2][0-9]|3[0-1])(?:T' ... | python | {
"resource": ""
} |
q250761 | KGSchema.is_location | train | def is_location(v) -> (bool, str):
"""
Boolean function for checking if v is a location format
Args:
v:
Returns: bool
"""
def convert2float(value):
try:
float_num = float(value)
return float_num
except... | python | {
"resource": ""
} |
q250762 | Document.select_segments | train | def select_segments(self, jsonpath: str) -> List[Segment]:
"""
Dereferences the json_path inside the document and returns the selected elements.
This method should compile and cache the compiled json_path in case the same path
is reused by multiple extractors.
Args:
| python | {
"resource": ""
} |
q250763 | GdeltModule.attribute_value | train | def attribute_value(self, doc: Document, attribute_name: str):
"""
Access data using attribute name rather than the numeric indices
Returns: the value for | python | {
"resource": ""
} |
q250764 | all_cities | train | def all_cities():
"""
Get a list of all Backpage city names.
Returns:
list of city names as Strings
"""
cities = []
fname = pkg_resources.resource_filename(__name__, 'resources/CityPops.csv')
with open(fname, 'rU') as csvfile:
| python | {
"resource": ""
} |
q250765 | city_nums | train | def city_nums():
"""
Get a dictionary of Backpage city names mapped to their 'legend' value.
Returns:
dictionary of Backpage city names mapped to their numeric value
"""
city_nums = {}
first_row = 1
num = 0
fname = pkg_resources.resource_filename(__name__, 'resources/Distance_Matrix.csv')
with op... | python | {
"resource": ""
} |
q250766 | date_clean | train | def date_clean(date, dashboard_style=False):
"""
Clean the numerical date value in order to present it.
Args:
boo: numerical date (20160205)
Returns:
| python | {
"resource": ""
} |
q250767 | date_range | train | def date_range(start, end, boo):
"""
Return list of dates within a specified range, inclusive.
Args:
start: earliest date to include, String ("2015-11-25")
end: latest date to include, String ("2015-12-01")
boo: if true, output list contains Numbers (20151230); if false, list contains Strings ("2015-... | python | {
"resource": ""
} |
q250768 | ethnicities_clean | train | def ethnicities_clean():
""" Get dictionary of unformatted ethnicity types mapped to clean corresponding ethnicity strings """
eths_clean = {}
fname = pkg_resources.resource_filename(__name__, 'resources/Ethnicity_Groups.csv')
with open(fname, 'rU') as csvfile:
reader = csv.reader(csvfile, delimiter = ',')... | python | {
"resource": ""
} |
q250769 | formal_cities | train | def formal_cities(reverse=False):
"""
Get a dictionary that maps all Backpage city names to their presentable, formal names.
Returns:
dictionary of Backpage city names mapped to formal city names
"""
output = {}
fname = pkg_resources.resource_filename(__name__, 'resources/Formal_City_Name_Pairs.csv')
... | python | {
"resource": ""
} |
q250770 | get_lats | train | def get_lats():
"""
Get a dictionary that maps Backpage city names to their respective latitudes.
Returns:
dictionary that maps city names (Strings) to latitudes (Floats)
"""
lats = {}
fname = pkg_resources.resource_filename(__name__, 'resources/Latitudes-Longitudes.csv')
with open(fname, 'rb') as cs... | python | {
"resource": ""
} |
q250771 | get_longs | train | def get_longs():
"""
Get a dictionary that maps Backpage city names to their respective longitudes.
Returns:
dictionary that maps city names (Strings) to longitudes (Floats)
"""
longs = {}
fname = pkg_resources.resource_filename(__name__, 'resources/Latitudes-Longitudes.csv')
with open(fname, 'rb') a... | python | {
"resource": ""
} |
q250772 | get_regions | train | def get_regions():
"""
Get a dictionary of state names mapped to their respective region numeric values.
New England -> 0
Mid Atlantic -> 1
Midwest East -> 2
Midwest West -> 3
Southeast -> 4
Southwest -> 5
Mountain West -> 6
Pacific -> 7
Alaska -> 8
Hawaii -> 9
Returns:
dictionary of sta... | python | {
"resource": ""
} |
q250773 | populations | train | def populations():
"""
Get a dictionary of Backpage city names mapped to their citizen populations.
Returns:
dictionary of Backpage city names mapped to their populations (integers)
"""
city_pops = {}
fname = pkg_resources.resource_filename(__name__, 'resources/CityPops.csv')
with open(fname, | python | {
"resource": ""
} |
q250774 | state_names | train | def state_names():
""" Get the set of all US state names """
names = set()
fname = pkg_resources.resource_filename(__name__, 'resources/States.csv')
with open(fname, 'rU') as csvfile:
| python | {
"resource": ""
} |
q250775 | state_nums | train | def state_nums():
"""
Get a dictionary of state names mapped to their 'legend' value.
Returns:
dictionary of state names mapped to their numeric value
"""
st_nums = {}
fname = pkg_resources.resource_filename(__name__, 'resources/States.csv')
with open(fname, 'rU') as csvfile:
| python | {
"resource": ""
} |
q250776 | states | train | def states():
"""
Get a dictionary of Backpage city names mapped to their respective states.
Returns:
dictionary of Backpage city names mapped to their states
"""
| python | {
"resource": ""
} |
q250777 | today | train | def today(boo):
"""
Return today's date as either a String or a Number, as specified by the User.
Args:
boo: if true, function returns Number (20151230); if false, returns String ("2015-12-30")
Returns:
either a Number or a string, dependent upon the user's | python | {
"resource": ""
} |
q250778 | GlossaryExtractor._generate_ngrams_with_context | train | def _generate_ngrams_with_context(self, tokens: List[Token]) -> chain:
"""Generates the 1-gram to n-grams tuples of the list of tokens"""
chained_ngrams_iter = self._generate_ngrams_with_context_helper(iter(tokens), 1)
for n in range(2, self._ngrams + 1):
ngrams_iter = tee(tokens, n)... | python | {
"resource": ""
} |
q250779 | GlossaryExtractor._populate_trie | train | def _populate_trie(self, values: List[str]) -> CharTrie:
"""Takes a list and inserts its elements into a new trie and returns it"""
if self._default_tokenizer:
| python | {
"resource": ""
} |
q250780 | GlossaryExtractor._generate_ngrams_with_context_helper | train | def _generate_ngrams_with_context_helper(ngrams_iter: iter, ngrams_len: int) -> map:
"""Updates the end index"""
return | python | {
"resource": ""
} |
q250781 | GlossaryExtractor._combine_ngrams | train | def _combine_ngrams(ngrams, joiner) -> str:
"""Construct keys for checking in trie"""
if isinstance(ngrams, str):
| python | {
"resource": ""
} |
q250782 | SpacyRuleExtractor.extract | train | def extract(self, text: str) -> List[Extraction]:
"""
Extract from text
Args:
text (str): input str to be extracted.
Returns:
List[Extraction]: the list of extraction or the empty list if there are no matches.
"""
doc = self._tokenizer.tokenize_... | python | {
"resource": ""
} |
q250783 | SpacyRuleExtractor._load_matcher | train | def _load_matcher(self) -> None:
"""
Add constructed spacy rule to Matcher
"""
for id_key in self._rule_lst:
if self._rule_lst[id_key].active:
| python | {
"resource": ""
} |
q250784 | Utility.make_json_serializable | train | def make_json_serializable(doc: Dict):
"""
Make the document JSON serializable. This is a poor man's implementation that handles dates and nothing else.
This method modifies the given document in place.
Args:
doc: A Python Dictionary, typically a CDR object.
Returns... | python | {
"resource": ""
} |
q250785 | BlackListFilter.filter | train | def filter(self, extractions, case_sensitive=False) -> List[Extraction]:
"""filters out the extraction if extracted value is in the blacklist"""
filtered_extractions = []
if not isinstance(extractions, list):
extractions = [extractions]
for extraction in extractions:
... | python | {
"resource": ""
} |
q250786 | rdf_generation | train | def rdf_generation(kg_object) -> str:
"""
Convert input knowledge graph object into n-triples RDF
:param kg_object: str, dict, or json object
:return: n-triples RDF | python | {
"resource": ""
} |
q250787 | OntologyDatatypeProperty.is_legal_object | train | def is_legal_object(self, data_type: str) -> bool:
"""
Do data_type validation according to the rules of the XML xsd schema.
Args:
data_type:
Returns:
"""
data_type = str(data_type)
| python | {
"resource": ""
} |
q250788 | Ontology.get_entity | train | def get_entity(self, uri: str) -> OntologyClass:
"""
Find an ontology entity based on URI
:param uri: URIRef or str
| python | {
"resource": ""
} |
q250789 | Ontology.merge_with_master_config | train | def merge_with_master_config(self, config, defaults={}, delete_orphan_fields=False) -> dict:
"""
Merge current ontology with input master config.
:param config: master config, should be str or dict
:param defaults: a dict that sets default color and icon
:param delete_orphan_fie... | python | {
"resource": ""
} |
q250790 | phone_text_subs | train | def phone_text_subs():
"""
Gets a dictionary of dictionaries that each contain alphabetic number manifestations mapped to their actual
Number value.
Returns:
dictionary of dictionaries containing Strings mapped to Numbers
"""
Small = {
'zero': 0,
'zer0': 0,
'one': 1,
'two': 2,
'th... | python | {
"resource": ""
} |
q250791 | SentenceExtractor.extract | train | def extract(self, text: str) -> List[Extraction]:
"""
Splits text by sentences.
Args:
text (str): Input text to be extracted.
Returns:
List[Extraction]: the list of extraction or the empty list if there are no matches.
"""
doc = self._parser(tex... | python | {
"resource": ""
} |
q250792 | TableExtraction.gen_html | train | def gen_html(row_list):
""" Return html table string from a list of data rows """
table = "<table>"
for row in row_list:
table += "<tr>"
cells = row["cells"]
for c | python | {
"resource": ""
} |
q250793 | HTMLContentExtractor.extract | train | def extract(self, html_text: str, strategy: Strategy=Strategy.ALL_TEXT) \
-> List[Extraction]:
"""
Extracts text from an HTML page using a variety of strategies
Args:
html_text (str): html page in string
strategy (enum[Strategy.ALL_TEXT, Strategy.MAIN_CONTENT... | python | {
"resource": ""
} |
q250794 | clean_part_ethn | train | def clean_part_ethn(body):
"""
Prepare a string to be parsed for ethnicities.
Returns a "translated" string (e.g. all instances of "china" converted to "chinese")
"""
# patterns that can create false positive situations
patterns_to_remove = [r'black ?or ?african', r'african ?or ?black', r'no ?black', ... | python | {
"resource": ""
} |
q250795 | KnowledgeGraph._add_doc_value | train | def _add_doc_value(self, field_name: str, jsonpath: str) -> None:
"""
Add a value to knowledge graph by giving a jsonpath
Args:
field_name: str
jsonpath: str
Returns:
"""
path = self.origin_doc.etk.parse_json_path(jsonpath)
matches = path... | python | {
"resource": ""
} |
q250796 | KnowledgeGraph.add_value | train | def add_value(self, field_name: str, value: object = None, json_path: str = None,
json_path_extraction: str = None, keep_empty: bool = False) -> None:
"""
Add a value to knowledge graph.
Input can either be a value or a json_path. If the input is json_path, the helper function ... | python | {
"resource": ""
} |
q250797 | KnowledgeGraph.get_values | train | def get_values(self, field_name: str) -> List[object]:
"""
Get a list of all the values of a field.
Args:
field_name:
Returns: the list of values (not the keys)
"""
result = list()
| python | {
"resource": ""
} |
q250798 | KnowledgeGraph.context_resolve | train | def context_resolve(self, field_uri: str) -> str:
"""
According to field_uri to add corresponding context and return a resolvable field_name
:param field_uri:
:return: a field_name that can be resolved with kg's @context
"""
from rdflib.namespace import split_uri
... | python | {
"resource": ""
} |
q250799 | Tokenizer.tokenize_to_spacy_doc | train | def tokenize_to_spacy_doc(self, text: str) -> Doc:
"""
Tokenize the given text, returning a spacy doc. Used for spacy rule extractor
Args:
text (string):
Returns: Doc
"""
if not self.keep_multi_space:
| python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.