Beispiel #1
0
    def __init__(self, syncon, lemma, positions, type=None, type_=None):
        """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 = []
        if not (type or type_):
            raise MissingArgumentError("Missing required argument type")

        self._type = EntityType(key=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))
Beispiel #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 = PhraseType(key=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))
    def __init__(self, value, score, positions):
        self._value = value
        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, "MainPhrase.position")

            self._positions.append(Position(**position))
    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))
    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))
    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 not (id or id_):
            raise MissingArgumentError("Missing required argument: id")
        self._id = id_ or 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))
    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))
    def __init__(self, key):
        if key not in ENTITY_TYPE_VALUES:
            raise EValueError(key, "Entity.key")

        self._key = key
Beispiel #9
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 = PosTag(key=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)