Commits

Hiroyoshi Komatsu committed c463546 Merge
  • Participants
  • Parent commits 4c6479c, 40f6e75

Comments (0)

Files changed (5)

 # file GENERATED by distutils, do NOT edit
 setup.py
+corenlp/__init__.py
+corenlp/client.py
+corenlp/corenlp.py
+corenlp/default.properties
+corenlp/progressbar.py
- This is a fork of [stanford-corenlp-python](https://github.com/dasmith/stanford-corenlp-python).
+ A Stanford Core NLP Python wrapper
+
+This is a fork of [stanford-corenlp-python](https://github.com/dasmith/stanford-corenlp-python).
 
 ## Edited
    * Update to Stanford CoreNLP v1.3.5
    * Can edit the constants as argument such as Stanford Core NLP directory.
    * Adjust parameters not to timeout in high load
    * Other bug fix
+   * Packaging (beta)
 
 ## Requirements
    * [jsonrpclib](https://github.com/joshmarshall/jsonrpclib)
 
 Then, to launch a server:
 
-    python corenlp.py
+    python corenlp/corenlp.py
 
 Optionally, you can specify a host or port:
 
-    python corenlp.py -H 0.0.0.0 -p 3456
+    python corenlp/corenlp.py -H 0.0.0.0 -p 3456
 
 That will run a public JSON-RPC server on port 3456.
+And you can specify Stanford CoreNLP directory:
 
-Assuming you are running on port 8080, the code in `client.py` shows an example parse:
+    python corenlp/corenlp.py -S stanford-corenlp-full-2013-04-04/
+
+
+Assuming you are running on port 8080 and CoreNLP directory is `stanford-corenlp-full-2013-04-04/` in current directory, the code in `client.py` shows an example parse:
 
     import jsonrpclib
     from simplejson import loads
 
 To use it in a regular script or to edit/debug it (because errors via RPC are opaque), load the module instead:
 
-    from corenlp import *
+    from corenlp import StanfordCoreNLP
     corenlp_dir = "stanford-corenlp-full-2013-04-04/"
     corenlp = StanfordCoreNLP(corenlp_dir)  # wait a few minutes...
     corenlp.parse("Parse it")

File corenlp/__init__.py

+# corenlp
+# Copyright 2013- Hiroyoshi Komatsu
+# See LICENSE for details.
+
+"""
+Stanford CoreNLP Python wrapper
+"""
+__version__ = '1.0.3'
+__author__ = 'Hiroyoshi Komatsu'
+__license__ = 'GNU v2+'
+
+from corenlp import StanfordCoreNLP

File corenlp/corenlp.py

         classname = "edu.stanford.nlp.pipeline.StanfordCoreNLP"
         # include the properties file, so you can change defaults
         # but any changes in output format will break parse_parser_results()
-        props = "-props default.properties"
+        property_name = "default.properties"
+        current_dir_pr = os.path.dirname(os.path.abspath( __file__ )) +"/"+ property_name
+        if os.path.exists(property_name):
+            props = "-props %s" % (property_name)
+        elif os.path.exists(current_dir_pr):
+            props = "-props %s" % (current_dir_pr)
+        else:
+            print "Error! Cannot locate: default.properties"
+            sys.exit(1)
 
         # add and check classpaths
         jars = [corenlp_path +"/"+ jar for jar in jars]
                 print "Error! Cannot locate %s" % jar
                 sys.exit(1)
 
+        # add memory limit on JVM
+        if memory:
+            limit = "-Xmx%s" % memory
+        else:
+            limit = ""
+
         # spawn the server
-        start_corenlp = "%s -Xmx%s -cp %s %s %s" % (java_path, memory, ':'.join(jars), classname, props)
+        start_corenlp = "%s %s -cp %s %s %s" % (java_path, limit, ':'.join(jars), classname, props)
         if VERBOSE: print start_corenlp
         self.corenlp = pexpect.spawn(start_corenlp)
 
 AUTHOR = "Hiroyoshi Komatsu"
 AUTHOR_EMAIL = "hiroyoshi.komat@gmail.com"
 URL = "https://bitbucket.org/torotoki/corenlp-python"
-VERSION = "1.0.1"
+VERSION = "1.0.3"
 
 # Utility function to read the README file.
 # Used for the long_description.  It's nice, because now 1) we have a top level
     author_email=AUTHOR_EMAIL,
     url=URL,
     packages=['corenlp'],
+    package_dir = {'corenlp': 'corenlp'},
+    package_data = {
+        "corenlp": ["default.properties"]
+    },
+    # data_files = [
+    #     ('corenlp', ["default.properties"]),
+    # ],
     # package_data=find_package_data(
     #     PACKAGE,
     #     only_in_packages=False
     # )
     classifiers=[
-        "Intended Audience :: Developers",
         "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
         "Programming Language :: Python",
     ],
-)
+)