# nlg.py import random import datetime from py4j_server import launch_py4j_server from py4j.java_gateway import java_import gateway = launch_py4j_server() # Import the SimpleNLG classes java_import(gateway.jvm, "simplenlg.features.*") java_import(gateway.jvm, "simplenlg.realiser.*") # Define aliases so that we don't have to use the gateway.jvm prefix. NPPhraseSpec = gateway.jvm.NPPhraseSpec PPPhraseSpec = gateway.jvm.PPPhraseSpec SPhraseSpec = gateway.jvm.SPhraseSpec InterrogativeType = gateway.jvm.InterrogativeType Realiser = gateway.jvm.Realiser TextSpec = gateway.jvm.TextSpec Tense = gateway.jvm.Tense Form = gateway.jvm.Form class NLG(object): """ Used to generate natural language. Most of these sections are hard coded. However, some use simpleNLG which is used to string together verbs and nouns. """ def __init__(self, user_name=None): self.user_name = user_name
Python interface to the Stanford Parser. You can access static methods and classes through the gateway.jvm object, or you can add a line like LexicalizedParser = gateway.jvm.LexicalizedParser to this module to create a short alias. Run this file for a demo. """ import os from py4j_server import launch_py4j_server from py4j.java_gateway import java_import gateway = launch_py4j_server() # Import the SimpleNLG classes java_import(gateway.jvm, "edu.stanford.nlp.parser.lexparser.LexicalizedParser") java_import(gateway.jvm, "edu.stanford.nlp.trees.*") java_import(gateway.jvm, "java.util.*") # Define aliases so that we don't have to use the gateway.jvm prefix. LexicalizedParser = gateway.jvm.LexicalizedParser Tree = gateway.jvm.Tree Arrays = gateway.jvm.Arrays ArrayList = Arrays = gateway.jvm.ArrayList def main(): """