Before I show the code I'm working with, I want to say that I can usually tell when I'm going to get an error. It's when I have a rule like the following:
DetP -> DetP PP
S -> S Conj S
VP -> VP PP
It's usually when an item is on both sides of the arrow. If I test a sentence after changing a rule to make it like that, I'll get infinite recursion. Based on my reading, though, that should be allowed. And I also have rules like
AdjP -> Adj NP | Adj AdjP
which didn't cause errors, so I'm confused.
Here is my code.
import nltk
import spacy
import re
nlp = spacy.load('en_core_web_lg')
def make_grammar_string(sentence):
doc = nlp(sentence.lower())
nouns = [f'"{token.text}"' for token in doc if token.pos_ == 'NOUN']
verbs = [f'"{token.text}"' for token in doc if token.pos_ == 'VERB']
adjs = [f'"{token.text}"' for token in doc if token.pos_ == 'ADJ']
preps = [f'"{token.text}"' for token in doc if token.pos_ == 'ADP']
dets = [f'"{token.text}"' for token in doc if token.pos_ == 'DET']
advs = [f'"{token.text}"' for token in doc if token.pos_ == 'ADV']
prons = [f'"{token.text}"' for token in doc if token.pos_ == 'PRON']
auxes = [f'"{token.text}"' for token in doc if token.pos_ == 'AUX']
advs = [f'"{token.text}"' for token in doc if token.pos_ == "ADV"]
grammar_string = f"""
S -> DetP VP | DetP VP CS
CS -> Conj S
NP -> Pron | N
VP -> V DetP | V | V DetP PP | V PP | Aux DetP | Aux DetP PP | Aux PP
AdjP -> Adj NP | Adj AdjP
DetP -> Det NP | Det AdjP | Det AdvP
PP -> P DetP
AdvP -> Adv AdjP | Adv Adj
V -> {' | '.join(verbs)}
Det -> {' | '.join(dets)} | ε
Adj -> {' | '.join(adjs)}
N -> {' | '.join(nouns)}
P -> {' | '.join(preps)}
Pron -> {' | '.join(prons)}
Aux -> {' | '.join(auxes)}
Adv -> {' | '.join(advs)}
Conj -> "and" | "but" | "or"
"""
return grammar_string
def make_sentence_tree(grammar_string, sentence):
doc = nlp(re.sub(r'[.,?:;]', '', sentence.lower()))
input = [token.text for token in doc]
# print(grammar_string)
# print(input)
grammar1 = nltk.CFG.fromstring(grammar_string)
print(grammar1.productions())
trees = []
rd_parser = nltk.RecursiveDescentParser(grammar1)
for tree in rd_parser.parse(input):
trees.append(tree)
trees.sort(key=lambda x: len(list(x.subtrees())))
t = trees[0]
t.pretty_print()
s = "The boy kicked the ball down the street"
mst = lambda s: make_sentence_tree(make_grammar_string(s), s)
mst(s)
The traceback is
Traceback (most recent call last):
File "/Users/gbcrockett/Desktop/python/conlang/nltk_practice.py", line 104, in <module>
mst(s)
File "/Users/crobotnik/Desktop/python/conlang/nltk_practice.py", line 103, in <lambda>
mst = lambda s: make_sentence_tree(make_grammar_string(s), s)
File "/Users/crobotnik/Desktop/python/conlang/nltk_practice.py", line 79, in make_sentence_tree
for tree in rd_parser.parse(input):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 130, in _parse
yield from self._match(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 168, in _match
yield from self._parse(rtext[1:], newtree, frontier[1:])
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 130, in _parse
yield from self._match(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 168, in _match
yield from self._parse(rtext[1:], newtree, frontier[1:])
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 130, in _parse
yield from self._match(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 168, in _match
yield from self._parse(rtext[1:], newtree, frontier[1:])
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 130, in _parse
yield from self._match(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 168, in _match
yield from self._parse(rtext[1:], newtree, frontier[1:])
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 225, in _expand
yield from self._parse(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/parse/recursivedescent.py", line 126, in _parse
yield from self._expand(remaining_text, tree, frontier)
......
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/tree/tree.py", line 544, in convert
children = [cls.convert(child) for child in tree]
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/tree/tree.py", line 544, in <listcomp>
children = [cls.convert(child) for child in tree]
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/tree/tree.py", line 544, in convert
children = [cls.convert(child) for child in tree]
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nltk/tree/tree.py", line 544, in <listcomp>
children = [cls.convert(child) for child in tree]
RecursionError: maximum recursion depth exceeded
I asked ChatGPT, and it recommended making a rule like S' in the case of
S -> S Conj S
So S' -> Conj S, then S -> S S'. It also said that S -> S Conj S is fine the way it is, depending on when I asked it. ChatGPT seemed confused. I'm not sure if a rule like S -> S Conj S or DetP -> DetP PP is doable with nltk. I think it should be doable, but I'm not sure.