示例#1
0
def dict_answers(a):
    #f contains pre-defined values for problematic cases
    f = {'1011':NO, '4000':NO, '2017':NO, '2008':NO, '2020':NO, '2007':NO, '110':NO, '3081':NO}
    for sent in a:
        lex = Interpretation(Dictionary("dictionaries/dictionary.xml")).interpret(Subtree(sent[1])).lex    
        if lex == ">" or lex == "=":
            f[sent[0]] = YES
        else:
            f[sent[0]] = NO
    return f
示例#2
0
def test_empty_dict():
    # Load the empty dictionary.
    filename = None
    dictionary = Dictionary(filename)
    
    # Rely on WN to create some new lexical relationships.
    print "Looking up poodle, dog ..."
    dictionary.lookup('n', "poodle", "dog")
    print "Looking up dog, mammal .."
    dictionary.lookup('n', "dog", "mammal")

    # View the expanded dictionary.
    print dictionary.to_xml()
示例#3
0
         #  poodle/poodle
         "[N poodle/poodle]",
         #  dog/poodle
         "[N dog/poodle]",
         # poodle/dog
         "[N poodle/dog]",
         # every poodle/dog run/sprint
         """[
              [
               [ (N/(VP/S)) every/every ]
               [ N poodle/dog ]
              ]
              [VP run/sprint]]"""]

if __name__ == "__main__":
    """Command-line parse or a random example."""
    sent = None
    if len(sys.argv) >= 2:
        sent = sys.argv[1]
        print "Your input:"
    else:        
        sent = sents[random.randint(0, len(sents)-1)]
        print "Random choice:"
    sbt = Subtree(sent)
    print "Structure:"
    print sbt.prettify()
    print "Interpretation:"
    print Interpretation(Dictionary(dictionary_filename)).interpret(sbt)

       
示例#4
0
def test_main_dict():
    # Load the dictionary files.
    filename = "dictionaries/dictionary.xml"
    dictionary = Dictionary(filename)
    # View the dictionary.
    print dictionary.to_xml()