Esempio n. 1
0
 def scanner(self, state, chart_index):
     # given a POS rule, see if the current word is that POS
     # then add it to the next chart: Verb-->book * [0,1]
     # advancing the dot
     #if self.debug:
     #print "    scanner considering:" ,
     #state.printme()
     pos = state.get_next_symbol()
     if chart_index < len(self.words):
         word = self.words[chart_index]
         rule = self.get_word_pos(word, pos)
         ##print "    scanner considering:" , word, rule
         if rule != None:
             if not self.is_rule_in_state(rule,
                                          self.chart[chart_index + 1]):
                 new_rule = RuleState(pos, [word], 1, chart_index,
                                      chart_index + 1, rule.get_semantics(),
                                      rule.get_semantics_txt())
                 if self.debug:
                     print "scanner adding to: ", chart_index + 1
                     print "scanner   :",
                     new_rule.printme()
                 self.chart[chart_index + 1].append(new_rule)
             else:
                 if True:  #self.debug:
                     print "  canner not adding",
                     state.printme()
Esempio n. 2
0
	def scanner(self, state, chart_index):
		# given a POS rule, see if the current word is that POS
		# then add it to the next chart: Verb-->book * [0,1]
		# advancing the dot
		pos=state.get_next_symbol()
		if chart_index < len(self.words):
			word=self.words[chart_index]
			rule=self.get_word_pos(word, pos)
			if rule != None:
				if not self.is_rule_in_state(rule, self.chart[chart_index + 1]):
					new_rule = RuleState(pos, [word], 1, chart_index, chart_index + 1, rule.get_semantics())
					print "scanner   :",
					new_rule.printme()
					self.chart[chart_index + 1].append(new_rule)
Esempio n. 3
0
    def __init__(self, words, rules, terminals):
        self.words = words
        self.terminals = terminals
        self.rules = rules
        self.trees = []  # completed parses
        self.chart = []
        for w in words:
            self.chart.append([])
        self.chart.append([])
        self.chart.append([])

        startState = RuleState.parse_RuleState("gamma-->S-->None")
        self.chart.append([])
        self.chart[0].append(startState)

        self.debug = False  #True

        if False:  # self.debug:
            for t in self.terminals:
                t.printme()
            for r in self.rules:
                r.printme()

        #if self.debug:
        print "----", words
Esempio n. 4
0
	def __init__(self, words, rules, terminals):
		self.words = words
		self.terminals = terminals
		self.rules = rules
		self.trees=[] # completed parses
		self.chart=[]
		for w in words:
			self.chart.append([])
		self.chart.append([])
		self.chart.append([])

		startState = RuleState.parse_RuleState("gamma-->S-->None")
		self.chart.append([])
		self.chart[0].append(startState)


		self.debug=False #True


		if False: # self.debug:
			for t in  self.terminals:
				t.printme()
			for r in self.rules:	
				r.printme()

		#if self.debug:
		print "----", words
Esempio n. 5
0
 def scanner(self, state, chart_index):
     # given a POS rule, see if the current word is that POS
     # then add it to the next chart: Verb-->book * [0,1]
     # advancing the dot
     pos = state.get_next_symbol()
     if chart_index < len(self.words):
         word = self.words[chart_index]
         rule = self.get_word_pos(word, pos)
         if rule != None:
             if not self.is_rule_in_state(rule,
                                          self.chart[chart_index + 1]):
                 new_rule = RuleState(pos, [word], 1, chart_index,
                                      chart_index + 1, rule.get_semantics())
                 print "scanner   :",
                 new_rule.printme()
                 self.chart[chart_index + 1].append(new_rule)
Esempio n. 6
0
	def __init__(self, words, rules, terminals):
		self.words = words
		self.terminals = terminals
		self.rules = rules
		self.chart=[]
		for w in words:
			self.chart.append([])
		self.chart.append([])
		startState = RuleState.parse_RuleState("gamma-->S,x")
		self.chart.append([])
		self.chart[0].append(startState)
Esempio n. 7
0
 def __init__(self, words, rules, terminals):
     self.words = words
     self.terminals = terminals
     self.rules = rules
     self.chart = []
     for w in words:
         self.chart.append([])
     self.chart.append([])
     startState = RuleState.parse_RuleState("gamma-->S,x")
     self.chart.append([])
     self.chart[0].append(startState)
Esempio n. 8
0
	def scanner(self, state, chart_index):
		# given a POS rule, see if the current word is that POS
		# then add it to the next chart: Verb-->book * [0,1]
		# advancing the dot
		#if self.debug:
			#print "    scanner considering:" ,
			#state.printme()
		pos=state.get_next_symbol()
		if chart_index < len(self.words):
			word=self.words[chart_index]
			rule=self.get_word_pos(word, pos)
			##print "    scanner considering:" , word, rule
			if rule != None:
				if not self.is_rule_in_state(rule, self.chart[chart_index + 1]):
					new_rule = RuleState(pos, [word], 1, chart_index, chart_index + 1, rule.get_semantics(), rule.get_semantics_txt())
					if self.debug:
						print "scanner adding to: ", chart_index + 1
						print "scanner   :",
						new_rule.printme()
					self.chart[chart_index + 1].append(new_rule)
				else :
					if True: #self.debug:
						print "  canner not adding",
						state.printme()
Esempio n. 9
0
    line = "bs"
    while (F and line != ""):
        line = F.readline().rstrip()
        if (len(line) > 0 and line[0] != "#"):
            rules_string = rules_string + line
    F.close
    return rules_string


if (len(sys.argv) < 2):
    print "need an argument for the grammar file name:"
    exit

grammar_filename = sys.argv[1]
grammar_string = read_file(grammar_filename)
(terminal_strings, nonterminal_strings) = eval(grammar_string)
rules = []
for s in nonterminal_strings:
    rules.append(RuleState.parse_RuleState(s))

terminals = []
for s in terminal_strings:
    # the terminal rules have pipes, but the nonterminals have spaces
    s = re.sub("\|", " ", s) + ",x"
    #print "---------->", s
    terminals.append(RuleState.parse_RuleState(s))

words = "book that flight".split(" ")
e = Early(words, rules, terminals)
e.early()
Esempio n. 10
0
File: test.py Progetto: ryrency/Misc
#!/usr/bin/python

from ruleState import RuleState
from early import Early
import sys

r = RuleState("x-->test,x")
r.Test()
Esempio n. 11
0



### main ###

if (len(sys.argv) < 3):
	print "need an argument for the grammar filename and the data filename:"
	exit 

grammar_filename = sys.argv[1]
grammar_string = read_file(grammar_filename)
(terminal_strings, nonterminal_strings) = eval(grammar_string)
rules = []
for s in nonterminal_strings:
	rules.append(RuleState.parse_RuleState(s))

terminals = []
for s in terminal_strings:
	# the terminal rules have pipes, but the nonterminals have spaces
	s=re.sub("\|", " ", s) + ",x"	
	#print "---------->", s
	terminals.append(RuleState.parse_RuleState(s))

words_string = read_txt_file(sys.argv[2])
words_list = eval(words_string)

for w in words_list:
	##print w
	words = w.split()
	e = Early(words, rules, terminals) 
Esempio n. 12
0
File: test.py Progetto: ryrency/Misc
#!/usr/bin/python

from ruleState import RuleState
from early import Early
import sys

r = RuleState.parse_RuleState("x-->test,x")
r.Test()
Esempio n. 13
0
#!/usr/bin/python


from ruleState import RuleState
from early import Early
import sys


r = RuleState.parse_RuleState("x-->test,x")
r.Test()