예제 #1
0
def check_subsumption(type1, type2):
    """1) Take two types in the TRIPS ontology as inputs. If one type is a subtype of the other, return the tuple
            (True, type), where type is the type that is a subtype. Otherwise, return the tuple (False, None)."""

    # IMPLEMENT FUNCTION HERE
    # def parent_lookup(goal, p):
    #     if 'parent' in jsontrips.ontology()[p].keys():
    #         if goal in jsontrips.ontology()[p]['parent']:
    #             return True
    #         else:
    #             parent_lookup(goal, jsontrips.ontology()[p]['parent'])
    #     else:
    #         return False
    def parent_lookup(goal, p):
        current = p
        while 'parent' in jsontrips.ontology()[current].keys(
        ) and jsontrips.ontology()[current]['parent'] != "":
            if goal in jsontrips.ontology()[current]['parent']:
                return True
            current = jsontrips.ontology()[current]['parent']
        return False

    if 'parent' in jsontrips.ontology()[type1].keys() and parent_lookup(
            type1, type2):
        return True, type2
    elif 'parent' in jsontrips.ontology()[type2].keys() and parent_lookup(
            type2, type1):
        return True, type1
    else:
        return False, None
예제 #2
0
 def parent_lookup(goal, p):
     current = p
     while 'parent' in jsontrips.ontology()[current].keys(
     ) and jsontrips.ontology()[current]['parent'] != "":
         if goal in jsontrips.ontology()[current]['parent']:
             return True
         current = jsontrips.ontology()[current]['parent']
     return False
예제 #3
0
def load():
    logger.info("Loading ontology")

    ont = jsontrips.ontology()

    logger.info("Loaded ontology")
    logger.info("Loading lexicon")

    lex = jsontrips.lexicon()

    logger.info("Loaded lexicon")
    return Trips(ont, lex)
def similarity_path_dist(type1, type2):
    """2ai) Take two types in the TRIPS ontology as inputs, and return the similarity between them (a number).
              Implement the path distance algorithm in this function."""
    # IMPLEMENT FUNCTION HERE
    l1 = []
    l2 = []
    cur1 = type1
    cur2 = type2
    while 'parent' in jsontrips.ontology()[cur1].keys(
    ) and jsontrips.ontology()[cur1]['parent'] != "":
        l1.append(cur1)
        cur1 = jsontrips.ontology()[cur1]['parent']

    while 'parent' in jsontrips.ontology()[cur2].keys(
    ) and jsontrips.ontology()[cur2]['parent'] != "":
        l2.append(cur2)
        cur2 = jsontrips.ontology()[cur2]['parent']

    l1.reverse()
    l2.reverse()
    index = 0
    while index < len(l1) and index < len(l2) and l1[index] == l2[index]:
        index = index + 1

    return len(l1) + len(l2) - 2 * index
예제 #5
0
import jsontrips

assert type(jsontrips.lexicon()) is dict
assert type(jsontrips.feature_lists()) is dict
assert type(jsontrips.feature_types()) is dict
assert type(jsontrips.lexicon_pos()) is dict
assert type(jsontrips.ontology()) is dict
assert type(jsontrips.syntax_templates()) is dict

assert type(jsontrips.lexicon()) is dict
assert type(jsontrips.feature_lists()) is dict
assert type(jsontrips.feature_types()) is dict
assert type(jsontrips.lexicon_pos()) is dict
assert type(jsontrips.ontology()) is dict
assert type(jsontrips.syntax_templates()) is dict

assert len(jsontrips.lexicon()) > 0
assert len(jsontrips.feature_lists()) > 0
assert len(jsontrips.feature_types()) > 0
assert len(jsontrips.lexicon_pos()) > 0
assert len(jsontrips.ontology()) > 0
assert len(jsontrips.syntax_templates()) > 0