Data Source Module¶
The Source module implements the methods to parse a task config, and maps the specific tasks with the metrics according to the config as well as creating a linking to the knowledge base Submodules ———- Currently the Framework only supports CSV Source
sources.CSVSource module¶
-
class
sources.csv_source.CSVSource(*args, **kwargs)¶ Bases:
sources.source.Source-
source_type= 'csv'¶
-
sources.source module¶
-
class
sources.source.Source(source_config, logger, gensim_loader=None)¶ Bases:
abc.ABC-
class
Statistics(entries_found: int, entry_misses: int)¶ Bases:
object
-
create_entry(key, value_type)¶
-
classmethod
from_config(source_config, *args)¶
-
get_entity_vector(entry)¶
-
get_word_vector(entry)¶
-
abstract property
source_type¶ classmethod(function) -> method
Convert a function to be a class method.
A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:
- class C:
@classmethod def f(cls, arg1, arg2, …):
…
It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument.
Class methods are different than C++ or Java static methods. If you want those, see the staticmethod builtin.
-
class
-
sources.source.dataclass(maybe_cls=None, these=None, repr_ns=None, repr=True, cmp=True, hash=None, init=True, slots=False, frozen=False, weakref_slot=True, str=False, *, auto_attribs=True, kw_only=False, cache_hash=False, auto_exc=False)¶ A class decorator that adds dunder-methods according to the specified attributes using
attr.ib()or the these argument.- Parameters
these (
dictofstrtoattr.ib()) –A dictionary of name to
attr.ib()mappings. This is useful to avoid the definition of your attributes within the class body because you can’t (e.g. if you want to add__repr__methods to Django models) or don’t want to.If these is not
None,attrswill not search the class body for attributes and will not remove any attributes from it.If these is an ordered dict (
dicton Python 3.6+,collections.OrderedDictotherwise), the order is deduced from the order of the attributes inside these. Otherwise the order of the definition of the attributes is used.repr_ns (str) – When using nested classes, there’s no way in Python 2 to automatically detect that. Therefore it’s possible to set the namespace explicitly for a more meaningful
reproutput.repr (bool) – Create a
__repr__method with a human readable representation ofattrsattributes..str (bool) – Create a
__str__method that is identical to__repr__. This is usually not necessary except forExceptions.cmp (bool) – Create
__eq__,__ne__,__lt__,__le__,__gt__, and__ge__methods that compare the class as if it were a tuple of itsattrsattributes. But the attributes are only compared, if the types of both classes are identical!hash (
boolorNone) –If
None(default), the__hash__method is generated according how cmp and frozen are set.If both are True,
attrswill generate a__hash__for you.If cmp is True and frozen is False,
__hash__will be set to None, marking it unhashable (which it is).If cmp is False,
__hash__will be left untouched meaning the__hash__method of the base class will be used (if base class isobject, this means it will fall back to id-based hashing.).
Although not recommended, you can decide for yourself and force
attrsto create one (e.g. if the class is immutable even though you didn’t freeze it programmatically) by passingTrueor not. Both of these cases are rather special and should be used carefully.See the Python documentation and the GitHub issue that led to the default behavior for more details.
init (bool) – Create a
__init__method that initializes theattrsattributes. Leading underscores are stripped for the argument name. If a__attrs_post_init__method exists on the class, it will be called after the class is fully initialized.slots (bool) – Create a slots-style class that’s more memory-efficient. See slots for further ramifications.
frozen (bool) –
Make instances immutable after initialization. If someone attempts to modify a frozen instance,
attr.exceptions.FrozenInstanceErroris raised.Please note:
This is achieved by installing a custom
__setattr__method on your class so you can’t implement an own one.True immutability is impossible in Python.
This does have a minor a runtime performance impact when initializing new instances. In other words:
__init__is slightly slower withfrozen=True.If a class is frozen, you cannot modify
selfin__attrs_post_init__or a self-written__init__. You can circumvent that limitation by usingobject.__setattr__(self, "attribute_name", value).
weakref_slot (bool) – Make instances weak-referenceable. This has no effect unless
slotsis also enabled.auto_attribs (bool) –
If True, collect PEP 526-annotated attributes (Python 3.6 and later only) from the class body.
In this case, you must annotate every field. If
attrsencounters a field that is set to anattr.ib()but lacks a type annotation, anattr.exceptions.UnannotatedAttributeErroris raised. Usefield_name: typing.Any = attr.ib(...)if you don’t want to set a type.If you assign a value to those attributes (e.g.
x: int = 42), that value becomes the default value like if it were passed usingattr.ib(default=42). Passing an instance ofFactoryalso works as expected.Attributes annotated as
typing.ClassVarare ignored.kw_only (bool) – Make all attributes keyword-only (Python 3+) in the generated
__init__(ifinitisFalse, this parameter is ignored).cache_hash (bool) – Ensure that the object’s hash code is computed only once and stored on the object. If this is set to
True, hashing must be either explicitly or implicitly enabled for this class. If the hash code is cached, avoid any reassignments of fields involved in hash code computation or mutations of the objects those fields point to after object creation. If such changes occur, the behavior of the object’s hash code is undefined.auto_exc (bool) –
If the class subclasses
BaseException(which implicitly includes any subclass of any exception), the following happens to behave like a well-behaved Python exceptions class:the values for cmp and hash are ignored and the instances compare and hash by the instance’s ids (N.B.
attrswill not remove existing implementations of__hash__or the equality methods. It just won’t add own ones.),all attributes that are either passed into
__init__or have a default value are additionally available as a tuple in theargsattribute,the value of str is ignored leaving
__str__to base classes.
New in version 16.0.0: slots
New in version 16.1.0: frozen
New in version 16.3.0: str
New in version 16.3.0: Support for
__attrs_post_init__.Changed in version 17.1.0: hash supports
Noneas value which is also the default now.New in version 17.3.0: auto_attribs
Changed in version 18.1.0: If these is passed, no attributes are deleted from the class body.
Changed in version 18.1.0: If these is ordered, the order is retained.
New in version 18.2.0: weakref_slot
Deprecated since version 18.2.0:
__lt__,__le__,__gt__, and__ge__now raise aDeprecationWarningif the classes compared are subclasses of each other.__eqand__ne__never tried to compared subclasses to each other.New in version 18.2.0: kw_only
New in version 18.2.0: cache_hash
New in version 19.1.0: auto_exc
-
sources.source.log_unknown_entries(f)¶
Module contents¶
-
class
sources.Source(source_config, logger, gensim_loader=None)¶ Bases:
abc.ABC-
class
Statistics(entries_found: int, entry_misses: int)¶ Bases:
object
-
create_entry(key, value_type)¶
-
classmethod
from_config(source_config, *args)¶
-
get_entity_vector(entry)¶
-
get_word_vector(entry)¶
-
abstract property
source_type¶ classmethod(function) -> method
Convert a function to be a class method.
A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:
- class C:
@classmethod def f(cls, arg1, arg2, …):
…
It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument.
Class methods are different than C++ or Java static methods. If you want those, see the staticmethod builtin.
-
class
-
class
sources.CSVSource(*args, **kwargs)¶ Bases:
sources.source.Source-
source_type= 'csv'¶
-