Пример #1
0
    def __init__(self,
                 syncon,
                 lemma,
                 positions,
                 type=None,
                 type_=None,
                 relevance=0,
                 attributes=[]):
        """Initialise the Entity object

        To minimise the `abuse` of the Python `type` keyword, the
        initialisation method also accepts `type_`. The former argument
        is used when the initialisation is nested inside other
        data-model classes. In these cases the __init__ receives a
        dictionary containing `type` not `type_`, because that how the
        response the server sends is defined. Otherwise when the object
        can be directly initialised using the second alternative.
        Again, to mitigate this name clash with the keyword the property
        was suffixed with the underscore.

        In the remote case a position dictionary is empty, the Position
        is not initialised to prevent an error to be raised.
        """
        self._syncon = syncon
        self._positions = []
        self._relevance = relevance
        self._attributes = []
        if not (type or type_):
            raise MissingArgumentError("Missing required argument type")

        self._type = (type_ or type)
        self._lemma = lemma

        if not isinstance(positions, list):
            raise ETypeError(positions, list)

        for position in positions:
            if not isinstance(position, dict):
                raise ETypeError(expected=dict, current=position)
            if not position:
                raise EValueError(position, "Entity.positions")

            self._positions.append(Position(**position))

        if not isinstance(attributes, list):
            raise ETypeError(attributes, list)

        for attr in attributes:
            if not isinstance(attr, dict):
                raise ETypeError(expected=dict, current=attr)

            if not attr:
                raise EValueError(attr, "Entity.attributes")

            self._attributes.append(Attribute(**attr))
Пример #2
0
    def __init__(self, tokens, start, end, type=None, type_=None):
        """Initialise the Phrase object

        To minimise the `abuse` of the Python `type` keyword, the
        initialisation method also accepts `type_`. The former argument
        is used when the initialisation is nested inside other
        data-model classes. In these cases the __init__ receives a
        dictionary containing `type` not `type_`, because that how the
        response the server sends is defined. Otherwise when the object
        can be directly initialised using the second alternative.
        Again, to mitigate this name clash with the keyword the
        property was suffixed with the underscore.

        In the remote case a token dictionary is empty, the Token is not
        initialised to prevent an error to be raised.
        """
        super().__init__(start=start, end=end)
        if not (type or type_):
            raise MissingArgumentError("Missing required argument type")

        self._type = (type_ or type)
        self._tokens = []

        if not isinstance(tokens, list):
            raise ETypeError(tokens, list)

        for token in tokens:
            if not isinstance(token, dict):
                raise ETypeError(expected=list, current=token)
            if not token:
                raise EValueError(token, "Phrase.tokens")

            self._tokens.append(Token(**token))
Пример #3
0
    def __init__(self, verb, related=[]):
        self._verb = {}
        self._related = []

        if not isinstance(verb, dict):
            raise ETypeError(verb, dict)
        if not verb:
            raise EValueError(verb, "Relation.verb")
        self._verb = Verb(**verb)

        if not isinstance(related, list):
            raise ETypeError(related, list)

        for rel in related:
            if not isinstance(rel, dict):
                raise ETypeError(expected=dict, current=rel)

            if not rel:
                raise EValueError(rel, "Relation.related")

            self._related.append(Related(**rel))
Пример #4
0
    def __init__(self, description, languages):
        self._description = description
        self._languages = []

        if not isinstance(languages, list):
            raise ETypeError(languages, list)

        for language in languages:
            if not isinstance(language, dict):
                raise ETypeError(expected=list, current=language)
            if not language:
                raise EValueError(language, "Iptc.languages")

            self._languages.append(Language(**language))
Пример #5
0
    def __init__(self, phrases, start, end):
        super().__init__(start=start, end=end)
        self._phrases = []
        if not isinstance(phrases, list):
            raise ETypeError(phrases, list)

        for phrase in phrases:
            if not isinstance(phrase, dict):
                raise ETypeError(expected=dict, current=phrase)

            if not phrase:
                raise EValueError(phrase, "Sentence.phrase")

            self._phrases.append(Phrase(**phrase))
Пример #6
0
    def __init__(self, value, score, positions):
        self._value = value
        self._score = score
        self._positions = []
        if not isinstance(self._positions, list):
            raise ETypeError(self._positions, list)

        for position in positions:
            if not isinstance(position, dict):
                raise ETypeError(expected=dict, current=position)
            if not position:
                raise EValueError(position, "MainLemma.positions")

            self._positions.append(Position(**position))
Пример #7
0
    def __init__(self, name, fields):
        self._name = name
        self._fields = []

        if not isinstance(fields, list):
            raise ETypeError(fields, list)

        for fld in fields:
            if not isinstance(fld, dict):
                raise ETypeError(expected=dict, current=fld)

            if not fld:
                raise EValueError(fld, "Template.fields")
            self.fields.append(Field(**fld))
Пример #8
0
    def __init__(self, namespace, taxonomy):
        self._namespace = namespace
        self._categories = []

        if not isinstance(taxonomy, list):
            raise ETypeError(taxonomy, list)

        for txn in taxonomy:
            if not isinstance(txn, dict):
                raise ETypeError(expected=dict, current=txn)

            if not txn:
                raise EValueError(txn, "Taxonomy.taxonomy")
            self._categories.append(Categories(**txn))
Пример #9
0
    def __init__(
        self,
        namespace,
        label,
        hierarchy,
        frequency,
        score,
        winner,
        positions,
        id=None,
        id_=None,
    ):
        """Initialise the Category object

        To minimise the `abuse` of the Python `type` id, the
        initialisation method also accepts `id_`. The former argument
        is used when the initialisation is nested inside other
        data-model classes. In these cases the __init__ receives a
        dictionary containing `type` not `id_`, because that how the
        response the server sends is defined. Otherwise when the object
        can be directly initialised using the second alternative.

        Again, to mitigate this name clash with the reserved keyword
        the property was suffixed with the underscore.
        """
        if id is None and id_ is None:
            raise MissingArgumentError("Missing required argument: id")
        if id is not None:
            self._id = id
        else:
            self._id = id_

        self._namespace = namespace
        self._label = label
        self._hierarchy = hierarchy
        self._frequency = frequency
        self._score = score
        self._winner = winner
        self._positions = []
        if not isinstance(positions, list):
            raise ETypeError(list, positions)

        for position in positions:
            if not isinstance(position, dict):
                raise ETypeError(dict, position)
            if not position:
                raise EValueError(position, "Category.positions")

            self._positions.append(Position(**position))
Пример #10
0
    def __init__(self, id, label="", categories=[]):
        self._id = id
        self._label = label
        self._categories = []

        if not isinstance(categories, list):
            raise ETypeError(categories, list)

        for ctg in categories:
            if not isinstance(ctg, dict):
                raise ETypeError(expected=dict, current=ctg)

            if not ctg:
                raise EValueError(ctg, "Category.categories")
            self._categories.append(Categories(**ctg))
Пример #11
0
    def __init__(self, name, value, positions=[]):
        self._name = name
        self._value = value

        self._positions = []
        if not isinstance(positions, list):
            raise ETypeError(positions, list)

        for position in positions:
            if not isinstance(position, dict):
                raise ETypeError(expected=dict, current=position)
            if not position:
                raise EValueError(position, "ExtractionField.positions")

            self._positions.append(Position(**position))
Пример #12
0
    def __init__(self, syncon, score, positions, lemma=""):
        self._syncon = syncon
        self._lemma = lemma
        self._score = score
        self._positions = []
        if not isinstance(positions, list):
            raise ETypeError(positions, list)

        for position in positions:
            if not isinstance(position, dict):
                raise ETypeError(expected=dict, current=position)
            if not position:
                raise EValueError(position, "MainSyncon.positions")

            self._positions.append(Position(**position))
Пример #13
0
    def __init__(self, name, description, languages):
        self._name = name
        self._description = description
        self._languages = []

        if not isinstance(languages, list):
            raise ETypeError(languages, list)

        for lng in languages:
            if not isinstance(lng, dict):
                raise ETypeError(expected=dict, current=lng)

            if not lng:
                raise EValueError(lng, "Context.language")
            self._languages.append(ContextLanguage(**lng))
Пример #14
0
    def __init__(self, lemma, syncon, sentiment, items=[]):
        self._lemma = lemma
        self._syncon = syncon
        self._sentiment = sentiment
        self._items = []

        if not isinstance(items, list):
            raise ETypeError(items, list)

        for itm in items:
            if not isinstance(itm, dict):
                raise ETypeError(expected=dict, current=itm)

            if not itm:
                raise EValueError(itm, "Sentiment.items")

            self._items.append(Items(**itm))
Пример #15
0
    def __init__(self, overall, negativity, positivity, items=[]):
        self._overall = overall
        self._negativity = negativity
        self._positivity = positivity
        self._items = []

        if not isinstance(items, list):
            raise ETypeError(items, list)

        for itm in items:
            if not isinstance(itm, dict):
                raise ETypeError(expected=dict, current=itm)

            if not itm:
                raise EValueError(itm, "Sentiment.items")

            self._items.append(Items(**itm))
Пример #16
0
    def __init__(self, syncon, label, properties=[]):
        self._syncon = syncon
        self._label = label
        self._properties = []

        if not isinstance(properties, list):
            raise ETypeError(properties, list)

        for prop in properties:
            if not isinstance(prop, dict):
                import pdb

                pdb.set_trace()
                raise ETypeError(expected=dict, current=prop)
            if not prop:
                raise EValueError(prop, "Knowledge.properties")

            self._properties.append(Property(**prop))
Пример #17
0
    def __init__(self, namespace, template, fields):

        if not template:
            raise MissingArgumentError("Missing required argument: template")
        self._template = template

        self._namespace = namespace
        self._fields = []

        if not isinstance(fields, list):
            raise ETypeError(list, fields)

        for fld in fields:
            if not isinstance(fld, dict):
                raise ETypeError(dict, fld)
            if not fld:
                raise EValueError(fld, "Extraction.fields")

            self._fields.append(ExtractionField(**fld))
Пример #18
0
    def __init__(self, relation, text, lemma, syncon, phrase, relevance, related=[], type=None, type_=None):
        self._relation = relation
        self._text = text
        self._lemma = lemma
        self._syncon = syncon
        self._phrase = phrase
        self._relevance = relevance
        self._type = type or type_
        self._related = []

        if not isinstance(related, list):
            raise ETypeError(related, list)

        for rel in related:
            if not isinstance(rel, dict):
                raise ETypeError(expected=dict, current=rel)

            if not rel:
                raise EValueError(rel, "Relation.related")

            self._related.append(Related(**rel))
Пример #19
0
    def __init__(self,
                 attribute,
                 lemma,
                 syncon,
                 type=None,
                 type_=None,
                 attributes=[]):
        self._attribute = attribute
        self._lemma = lemma
        self._syncon = syncon
        self._type = type_ or type
        self._attributes = []

        if not isinstance(attributes, list):
            raise ETypeError(attributes, list)

        for attr in attributes:
            if not isinstance(attr, dict):
                raise ETypeError(expected=dict, current=attr)

            if not attr:
                raise EValueError(attr, "Entity.attributes")

            self._attributes.append(Attribute(**attr))
Пример #20
0
    def __init__(
        self,
        start,
        end,
        syncon,
        pos,
        lemma,
        dependency,
        paragraph,
        sentence,
        phrase,
        atoms=[],
        morphology=None,
        vsyn=None,
        type=None,
        type_=None,
    ):
        """Initialise the Property object

        To minimise the `abuse` of the Python `type` keyword, the
        initialisation method also accepts `type_`. The former argument
        is used when the initialisation is nested inside other
        data-model classes. In these cases the __init__ receives a
        dictionary containing `type` not `type_`, because that how the
        response the server sends is defined. Otherwise when the object
        can be directly initialised using the second alternative.

        Again, to mitigate this name clash with the reserved keyword
        the property was suffixed with the underscore.
        """
        super().__init__(start=start, end=end)
        self._syncon = syncon
        # by default if only one value is passed, it is considered
        # to be the key
        self._pos = pos
        self._lemma = lemma
        self._atoms = []
        self._vsyn = None

        if not isinstance(dependency, dict):
            raise ETypeError(dependency, dict)
        if not dependency:
            raise EValueError(dependency, "Token.dependency")
        self._dependency = Dependency(**dependency)

        self._morphology = morphology
        self._paragraph = paragraph
        self._sentence = sentence
        self._phrase = phrase
        self._type = type or type_

        if not isinstance(atoms, list):
            raise ETypeError(list, atoms)

        for atom in atoms:
            if not isinstance(atom, dict):
                raise ETypeError(dict, atom)
            if not atom:
                raise EValueError(atom, "Token.atom")

            self._atoms.append(Atom(**atom))

        if vsyn:
            if not isinstance(vsyn, dict):
                raise ETypeError(dict, vsyn)

            self._vsyn = VSyncon(**vsyn)