Skip to content

Commit

Permalink
changed ContextFreeGrammar to CFG, WeightedGrammar to PCFG, and Stati…
Browse files Browse the repository at this point in the history
…sticalGrammar to ProbabilisticGrammar
  • Loading branch information
stevenbird committed May 31, 2014
1 parent 045e481 commit af68c53
Show file tree
Hide file tree
Showing 21 changed files with 113 additions and 111 deletions.
6 changes: 3 additions & 3 deletions nltk/app/chartparser_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
SteppingChartParser, TopDownInitRule, TopDownPredictRule,
TreeEdge)
from nltk.tree import Tree
from nltk.grammar import Nonterminal, ContextFreeGrammar
from nltk.grammar import Nonterminal, CFG
from nltk.util import in_idle
from nltk.draw.util import (CanvasFrame, ColorizedList,
EntryDialog, MutableOptionMenu,
Expand Down Expand Up @@ -2038,7 +2038,7 @@ def load_grammar(self, *args):
grammar = pickle.load(infile)
else:
with open(filename, 'r') as infile:
grammar = ContextFreeGrammar.fromstring(infile.read())
grammar = CFG.fromstring(infile.read())
self.set_grammar(grammar)
except Exception as e:
tkinter.messagebox.showerror('Error Loading Grammar',
Expand Down Expand Up @@ -2230,7 +2230,7 @@ def top_down_strategy(self, *e):
self.apply_strategy(self._TD_STRATEGY, TopDownPredictEdgeRule)

def app():
grammar = ContextFreeGrammar.fromstring("""
grammar = CFG.fromstring("""
# Grammatical productions.
S -> NP VP
VP -> VP PP | V NP | V
Expand Down
4 changes: 2 additions & 2 deletions nltk/app/rdparser_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,8 @@ def app():
Create a recursive descent parser demo, using a simple grammar and
text.
"""
from nltk.grammar import ContextFreeGrammar
grammar = ContextFreeGrammar.fromstring("""
from nltk.grammar import CFG
grammar = CFG.fromstring("""
# Grammatical productions.
S -> NP VP
NP -> Det N PP | Det N
Expand Down
4 changes: 2 additions & 2 deletions nltk/app/srparser_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ def app():
text.
"""

from nltk.grammar import Nonterminal, Production, ContextFreeGrammar
from nltk.grammar import Nonterminal, Production, CFG
nonterminals = 'S VP NP PP P N Name V Det'
(S, VP, NP, PP, P, N, Name, V, Det) = [Nonterminal(s)
for s in nonterminals.split()]
Expand All @@ -796,7 +796,7 @@ def app():
Production(Det, ['my']),
)

grammar = ContextFreeGrammar(S, productions)
grammar = CFG(S, productions)

# tokenize the sentence
sent = 'my dog saw a man in the park with a statue'.split()
Expand Down
4 changes: 2 additions & 2 deletions nltk/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,10 +803,10 @@ def load(resource_url, format='auto', cache=True, verbose=False,
if format == 'text':
resource_val = string_data
elif format == 'cfg':
resource_val = nltk.grammar.ContextFreeGrammar.fromstring(
resource_val = nltk.grammar.CFG.fromstring(
string_data, encoding=encoding)
elif format == 'pcfg':
resource_val = nltk.grammar.WeightedGrammar.fromstring(
resource_val = nltk.grammar.PCFG.fromstring(
string_data, encoding=encoding)
elif format == 'fcfg':
resource_val = nltk.grammar.FeatureGrammar.fromstring(
Expand Down
14 changes: 7 additions & 7 deletions nltk/draw/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from tkinter import (Button, Canvas, Entry, Frame, IntVar, Label,
Scrollbar, Text, Tk, Toplevel)

from nltk.grammar import (ContextFreeGrammar, _read_cfg_production,
from nltk.grammar import (CFG, _read_cfg_production,
Nonterminal, nonterminals)
from nltk.tree import Tree
from nltk.draw.tree import TreeSegmentWidget, tree_to_treesegment
Expand Down Expand Up @@ -157,7 +157,7 @@ class CFGEditor(object):
def __init__(self, parent, cfg=None, set_cfg_callback=None):
self._parent = parent
if cfg is not None: self._cfg = cfg
else: self._cfg = ContextFreeGrammar(Nonterminal('S'), [])
else: self._cfg = CFG(Nonterminal('S'), [])
self._set_cfg_callback = set_cfg_callback

self._highlight_matching_nonterminals = 1
Expand Down Expand Up @@ -482,7 +482,7 @@ def _ok(self, *e):
def _apply(self, *e):
productions = self._parse_productions()
start = Nonterminal(self._start.get())
cfg = ContextFreeGrammar(start, productions)
cfg = CFG(start, productions)
if self._set_cfg_callback is not None:
self._set_cfg_callback(cfg)

Expand Down Expand Up @@ -666,7 +666,7 @@ def mainloop(self, *args, **kwargs):
self._top.mainloop(*args, **kwargs)

def demo2():
from nltk import Nonterminal, Production, ContextFreeGrammar
from nltk import Nonterminal, Production, CFG
nonterminals = 'S VP NP PP P N Name V Det'
(S, VP, NP, PP, P, N, Name, V, Det) = [Nonterminal(s)
for s in nonterminals.split()]
Expand All @@ -691,7 +691,7 @@ def demo2():
Production(N, ['dog']), Production(N, ['statue']),
Production(Det, ['my']),
)
grammar = ContextFreeGrammar(S, productions)
grammar = CFG(S, productions)

text = 'I saw a man in the park'.split()
d=CFGDemo(grammar, text)
Expand All @@ -702,12 +702,12 @@ def demo2():
######################################################################

def demo():
from nltk import Nonterminal, ContextFreeGrammar
from nltk import Nonterminal, CFG
nonterminals = 'S VP NP PP P N Name V Det'
(S, VP, NP, PP, P, N, Name, V, Det) = [Nonterminal(s)
for s in nonterminals.split()]

grammar = ContextFreeGrammar.fromstring("""
grammar = CFG.fromstring("""
S -> NP VP
PP -> P NP
NP -> Det N
Expand Down
Loading

0 comments on commit af68c53

Please sign in to comment.