def tree_to_nltk(intree): """ Given a syntactic tree using the SyntacticTreeNode classes, produces an NLTK tree. This is useful, for example, to display a tree: tree.draw(). You need NLTK installed to be able to do this. """ from jazzparser.utils.base import load_optional_package tree = load_optional_package('nltk.tree', 'NLTK', 'doing NLTK tree operations') def _node_to_nltk_tree(node): if isinstance(node, SyntacticNonTerminal): # Recursive case: build an internal node children = [] for child in node.children: children.append(_node_to_nltk_tree(child)) return tree.Tree("%s" % node.rule, children) elif isinstance(node, SyntacticTreeRoot): # Recursive case (root): build an internal node children = [] for child in node.children: children.append(_node_to_nltk_tree(child)) return tree.Tree("Root", children) elif isinstance(node, SyntacticTerminal): # Base case: build a leaf leaf = tree.Tree("%s" % node.chord, []) if node.category is not None: # Add an extra node to represent the category with one child leaf = tree.Tree("%s" % node.category, [leaf]) return leaf return _node_to_nltk_tree(intree)
def check_pygame(): """ Checks that PyGame can be imported and outputs an error if not. """ load_optional_package('pygame', 'PyGame', "outputing audio")
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with The Jazz Parser. If not, see <http://www.gnu.org/licenses/>. ============================ End license ====================================== """ __author__ = "Mark Granroth-Wilding <*****@*****.**>" from jazzparser.utils.base import load_optional_package # Check NLTK can be imported load_optional_package('nltk', 'NLTK', "load the Jazz Parser NLTK extensions") from .storage import FreqDistStorer, ConditionalProbDistStorer, MLEProbDistStorer, \ ConditionalFreqDistStorer, LaplaceProbDistStorer, \ WittenBellProbDistStorer, GoodTuringProbDistStorer, \ DictionaryProbDistStorer, DictionaryConditionalProbDistStorer, \ MutableProbDistStorer from .hmm import HiddenMarkovModelTaggerStorer from .probability import CutoffFreqDistStorer, CutoffConditionalFreqDistStorer # Any storers defined should be listed here # See the storage module for more info about these STORERS = [ HiddenMarkovModelTaggerStorer, FreqDistStorer, ConditionalProbDistStorer,
The Jazz Parser is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with The Jazz Parser. If not, see <http://www.gnu.org/licenses/>. ============================ End license ====================================== """ __author__ = "Mark Granroth-Wilding <*****@*****.**>" from jazzparser.utils.base import load_optional_package # Check NLTK can be imported load_optional_package('nltk', 'NLTK', "load the Jazz Parser NLTK extensions") from .storage import FreqDistStorer, ConditionalProbDistStorer, MLEProbDistStorer, \ ConditionalFreqDistStorer, LaplaceProbDistStorer, \ WittenBellProbDistStorer, GoodTuringProbDistStorer, \ DictionaryProbDistStorer, DictionaryConditionalProbDistStorer, \ MutableProbDistStorer from .hmm import HiddenMarkovModelTaggerStorer from .probability import CutoffFreqDistStorer, CutoffConditionalFreqDistStorer # Any storers defined should be listed here # See the storage module for more info about these STORERS = [ HiddenMarkovModelTaggerStorer, FreqDistStorer, ConditionalProbDistStorer,