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 (
dict
ofstr
toattr.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
,attrs
will not search the class body for attributes and will not remove any attributes from it.If these is an ordered dict (
dict
on Python 3.6+,collections.OrderedDict
otherwise), 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
repr
output.repr (bool) – Create a
__repr__
method with a human readable representation ofattrs
attributes..str (bool) – Create a
__str__
method that is identical to__repr__
. This is usually not necessary except forException
s.cmp (bool) – Create
__eq__
,__ne__
,__lt__
,__le__
,__gt__
, and__ge__
methods that compare the class as if it were a tuple of itsattrs
attributes. But the attributes are only compared, if the types of both classes are identical!hash (
bool
orNone
) –If
None
(default), the__hash__
method is generated according how cmp and frozen are set.If both are True,
attrs
will 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
attrs
to create one (e.g. if the class is immutable even though you didn’t freeze it programmatically) by passingTrue
or 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 theattrs
attributes. 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.FrozenInstanceError
is 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
self
in__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
slots
is 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
attrs
encounters a field that is set to anattr.ib()
but lacks a type annotation, anattr.exceptions.UnannotatedAttributeError
is 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 ofFactory
also works as expected.Attributes annotated as
typing.ClassVar
are ignored.kw_only (bool) – Make all attributes keyword-only (Python 3+) in the generated
__init__
(ifinit
isFalse
, 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.
attrs
will 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 theargs
attribute,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
None
as 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 aDeprecationWarning
if the classes compared are subclasses of each other.__eq
and__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'¶
-