예제 #1
0
 def setUp(self):
     io = CKYIO('../../../resources/GRAMMAR.IN','../../../resources/LEXICON.IN'
             ,'../../../resources/SENTENCES.IN')
     outfile = 'OUTFILE.'
     self.parser = CKY(io.readGrammar(), io.readLexicon(), outfile)
     self.parser.matrix=[]
     self.parser.initializeTable(4)
예제 #2
0
class Test(unittest.TestCase):
    
    def setUp(self):
        self.io = CKYIO('../../../resources/GRAMMAR.IN', \
                     '../../../resources/LEXICON.IN', \
                     '../../../resources/SENTENCES.IN')
        
    def tearDown(self):
        self.io = None

    def testReadGrammar(self):
        listGrammar = self.io.readGrammar()
        self.assertEqual(listGrammar[0].getLeft(), \
                                                "S",'Read grammar: Error 1')
        self.assertEqual(listGrammar[0].getRightFirst(), \
                                              "NP", 'Read grammar: Error 2')
        self.assertEqual(listGrammar[0].getRightSecond(), \
                                              "VP", 'Read grammar: Error 3') 

    def testReadLexicon(self):
        listLexicon = self.io.readLexicon()
        self.assertEqual(listLexicon[0].getLeft(), \
                                              "NP", "Read Lexicon: Error 1")
        self.assertEqual(listLexicon[0].getRight(), \
                                           "Fivel", "Read Lexicon: Error 2")
        
    def testReadSentence(self):
        listSentence = self.io.readSentence()
        self.assertEqual(listSentence[0], "Fivel ate the cheese\n", \
                                                   "Read Sentence: Error 1")
예제 #3
0
class Test(unittest.TestCase):
    def setUp(self):
        self.io = CKYIO('../../../resources/GRAMMAR.IN', \
                     '../../../resources/LEXICON.IN', \
                     '../../../resources/SENTENCES.IN')

    def tearDown(self):
        self.io = None

    def testReadGrammar(self):
        listGrammar = self.io.readGrammar()
        self.assertEqual(listGrammar[0].getLeft(), \
                                                "S",'Read grammar: Error 1')
        self.assertEqual(listGrammar[0].getRightFirst(), \
                                              "NP", 'Read grammar: Error 2')
        self.assertEqual(listGrammar[0].getRightSecond(), \
                                              "VP", 'Read grammar: Error 3')

    def testReadLexicon(self):
        listLexicon = self.io.readLexicon()
        self.assertEqual(listLexicon[0].getLeft(), \
                                              "NP", "Read Lexicon: Error 1")
        self.assertEqual(listLexicon[0].getRight(), \
                                           "Fivel", "Read Lexicon: Error 2")

    def testReadSentence(self):
        listSentence = self.io.readSentence()
        self.assertEqual(listSentence[0], "Fivel ate the cheese\n", \
                                                   "Read Sentence: Error 1")
예제 #4
0
 def setUp(self):
     io = CKYIO('../../../resources/GRAMMAR.IN',
                '../../../resources/LEXICON.IN',
                '../../../resources/SENTENCES.IN')
     outfile = 'OUTFILE.'
     self.parser = CKY(io.readGrammar(), io.readLexicon(), outfile)
     self.parser.matrix = []
     self.parser.initializeTable(4)
예제 #5
0
                     help="path of outfile")
 parser.add_argument("-q", "--quiet",
         action="store_false", dest="DEBUG", default=True,
         help="don't print the chart content  [default True]")
 args = parser.parse_args()
 
 #call parser
 # Theory of call:
 #        - args.dest : contains content user entered
 #        - e.g: args.grammar will return file name of file contain grammar
 if args:
     try:
         #Call to main parser
         #Read files
         if(args.algorithm=="c"):
             io = CKYIO(args.grammar, args.lexicon, args.sentence)
             listGrammar  = io.readGrammar()
             listLexicon  = io.readLexicon()
             listSentence = io.readSentence()
             #End read files
             
             #Initialize CYK
             cykInstance = CKY(listGrammar, listLexicon, args.outfile)
             startTime = time.clock()
             #Parse for each sentence INPUT
             for sent in listSentence:
                 cykInstance.syntacticAnalyzer(sent)  
             #End parse
             stopTime = time.clock()
             print "Analysis success. " \
                   "Please check output file! \nTime is: " \
예제 #6
0
 def setUp(self):
     self.io = CKYIO('../../../resources/GRAMMAR.IN', \
                  '../../../resources/LEXICON.IN', \
                  '../../../resources/SENTENCES.IN')
예제 #7
0
                        action="store_false",
                        dest="DEBUG",
                        default=True,
                        help="don't print the chart content  [default True]")
    args = parser.parse_args()

    #call parser
    # Theory of call:
    #        - args.dest : contains content user entered
    #        - e.g: args.grammar will return file name of file contain grammar
    if args:
        try:
            #Call to main parser
            #Read files
            if (args.algorithm == "c"):
                io = CKYIO(args.grammar, args.lexicon, args.sentence)
                listGrammar = io.readGrammar()
                listLexicon = io.readLexicon()
                listSentence = io.readSentence()
                #End read files

                #Initialize CYK
                cykInstance = CKY(listGrammar, listLexicon, args.outfile)
                startTime = time.clock()
                #Parse for each sentence INPUT
                for sent in listSentence:
                    cykInstance.syntacticAnalyzer(sent)
                #End parse
                stopTime = time.clock()
                print "Analysis success. " \
                      "Please check output file! \nTime is: " \
예제 #8
0
 def setUp(self):
     self.io = CKYIO('../../../resources/GRAMMAR.IN', \
                  '../../../resources/LEXICON.IN', \
                  '../../../resources/SENTENCES.IN')
예제 #9
0
'''
Created on 11-12-2011

@author: hoangnm
'''
from cky.utils.ckyIO import CKYIO
from cky.algorithm import ckyAlgorithm

if __name__ == '__main__':
    io = CKYIO('../resources/cky/GRAMMAR.IN', \
            '../resources/cky/LEXICON.IN', \
            '../resources/cky/SENTENCES.IN')
    listOfGrammar = io.readGrammar()
    listOfLexicon = io.readLexicon()
    listOfSentence = io.readSentence()
    outfile = '../resources/cky/OUTFILE.OUT'
    
    cykInstance = ckyAlgorithm.CKY(listOfGrammar,listOfLexicon, outfile)    
    i =0
    for sent in listOfSentence:
        print 'SENTENCE ',i,':' , sent
      
        cykInstance.syntacticAnalyzer(sent)
      
        i=i+1
        print "----------------------------------------------------------------"
    print "DONE"