示例#1
0
        def is_name(self):
            """Checks if the text supplied is a name, with certainty.

            :returns: Whether the text is a name
            :rtype: {bool}
            """
            is_name = utils.deep_get(self.data, 'isName', 'value')
            is_certain = utils.deep_get(self.data, 'isName',
                                        'confidence') == 'Certain'
            return is_name and is_certain
示例#2
0
        def is_male_name(self):
            """Checks if a name is male, with certainty.

            :returns: Whether the name is male
            :rtype: {bool}
            """
            is_male = utils.deep_get(self.data, 'isMaleName', 'value')
            is_certain = utils.deep_get(self.data, 'isMaleName',
                                        'confidence') == 'Certain'
            return is_male and is_certain
示例#3
0
        def is_family_name(self):
            """Checks if a name is a family name, with certainty.

            :returns: Whether the name is a family name
            :rtype: {bool}
            """
            is_family_name = utils.deep_get(self.data, 'isFamilyName', 'value')
            is_certain = utils.deep_get(self.data, 'isFamilyName',
                                        'confidence') == 'Certain'
            return is_family_name and is_certain
示例#4
0
        def is_first_name(self):
            """Checks if a name is a first name, with certainty.

            :returns: Whether the name is a first name
            :rtype: {bool}
            """
            is_male = utils.deep_get(self.data, 'isMaleName', 'value')
            is_m_certain = utils.deep_get(self.data, 'isMaleName',
                                          'confidence') == 'Certain'
            is_female = utils.deep_get(self.data, 'isFemaleName', 'value')
            is_f_certain = utils.deep_get(self.data, 'isFemaleName',
                                          'confidence') == 'Certain'
            return (is_male and is_m_certain) or (is_female and is_f_certain)
示例#5
0
 def from_json(cls, r, top_level=False):
     """Builds a `Relation` from a json object."""
     qualifiers = r.get('qualifiers')
     question = r.get('question')
     question_auxiliary = r.get('questionAuxiliary')
     vm_subject_prefix = r.get('verbModifiersSubjectPrefix')
     type_ = utils.deep_get(r, 'subject', 'type')
     subject = (
         Entity.from_json(r['subject']) if type_ == 'entity' else
         Relation.from_json(r['subject']) if type_ == 'relation' else None)
     predicate = Predicate.from_json(r.get('predicate'))
     type_ = utils.deep_get(r, 'object', 'type')
     object_ = (
         Entity.from_json(r['object']) if type_ == 'entity' else
         Relation.from_json(r['object']) if type_ == 'relation' else None)
     vm_object_suffix = r.get('verbModifiersObjectSuffix')
     prepositions = [Preposition.from_json(p)
                     for p in r.get('prepositions', [])
                     if p.get('type') == 'preposition']
     type_ = utils.deep_get(r, 'qualified_object', 'type')
     qualified_object = (
         Entity.from_json(
             r['qualified_object']) if type_ == 'entity' else Relation.from_json(  # noqa
             r['qualified_object']) if type_ == 'relation' else None)
     inferred = r.get('inferred', False)
     nested = r.get('nested', False)
     qualified = r.get('qualified', False)
     artificial_type = r.get('artificialType', None)
     _features = r.get('_features', [])
     confidence = r.get('confidence', 1.0)
     return cls(
         qualifiers,
         question,
         question_auxiliary,
         vm_subject_prefix,
         subject,
         predicate,
         object_,
         vm_object_suffix,
         prepositions,
         qualified_object,
         inferred,
         nested,
         qualified,
         artificial_type,
         _features,
         confidence,
         top_level)
示例#6
0
 def from_json(cls, p):
     """Builds a `Predicate` from a json object."""
     preposition_prefix = p.get('preposition_prefix', [])
     preposition = p.get('preposition')
     type_ = utils.deep_get(p, 'prepositionObject', 'type')
     preposition_object = (
         Entity.from_json(p['prepositionObject']) if type_ == 'entity' else
         Relation.from_json(p['prepositionObject']) if type_ == 'relation'
         else None)
     nested_prepositions = [
         Preposition.from_json(np) for np in p.get(
             'nestedPrepositions',
             []) if np.get('type') == 'preposition']
     index = p.get('index')
     preposition_type = p.get('preposition_type', None)
     return cls(preposition_prefix,
                preposition,
                preposition_object,
                nested_prepositions,
                index,
                preposition_type)
示例#7
0
def test_deep_get_one_level():
    a = {'x': {'a': 1, 'b': '', 'c': {'d': '2'}}, 'y': 5}
    assert utils.deep_get(a, 'x') == {'a': 1, 'b': '', 'c': {'d': '2'}}
    assert utils.deep_get(a, 'y') == 5
示例#8
0
def test_deep_get_not_found():
    a = {'x': {'a': 1, 'b': '', 'c': {'d': '2'}}, 'y': 5}
    assert utils.deep_get(a, 'z') is None
    assert utils.deep_get(a, 'x', 'z') is None
示例#9
0
def test_deep_get_three_levels():
    a = {'x': {'a': 1, 'b': '', 'c': {'d': '2'}}, 'y': 5}
    assert utils.deep_get(a, 'x', 'c', 'd') == '2'
示例#10
0
def test_deep_get_two_levels():
    a = {'x': {'a': 1, 'b': '', 'c': {'d': '2'}}, 'y': 5}
    assert utils.deep_get(a, 'x', 'a') == 1
    assert utils.deep_get(a, 'x', 'b') == ''
    assert utils.deep_get(a, 'x', 'c') == {'d': '2'}