Package: zodiac-sutime
sutimePython wrapper for Stanford CoreNLP'sSUTimeJava library.Build StatusCircleCI BuildsPyPICode QualityInstallation>>pipinstallsetuptools_scmjpype1# install pre-reqs>>pipinstallsutime
>># use package pom.xml to install all Java dependencies via Maven into ./jars>>mvndependency:copy-dependencies-DoutputDirectory=./jarsRun the following command to add the Spanish language model:>>mvndependency:copy-dependencies-DoutputDirectory=./jars-PspanishSupported LanguagesSUTime currently supports only English, British and Spanish (Source).
This Python wrapper is prepared to support the other CoreNLP languages (e.g. German) as well as soon as they get added to SUTime.
The following command can be used to download the language models forarabic,chinese,english,french,german, andspanish:>>mvndependency:copy-dependencies-DoutputDirectory=./jars-P<language>However, SUTime only supports a subset (default model andspanish) of CoreNLP's languages and the other language models will get ignored.ExampleimportjsonimportosfromsutimeimportSUTimeif__name__=='__main__':test_case=u'I need a desk for tomorrow from 2pm to 3pm'jar_files=os.path.join(os.path.dirname(__file__),'jars')sutime=SUTime(jars=jar_files,mark_time_ranges=True)print(json.dumps(sutime.parse(test_case),sort_keys=True,indent=4))Result:[{"end":26,"start":18,"text":"tomorrow","type":"DATE","value":"2016-10-14"},{"end":42,"start":27,"text":"from 2pm to 3pm","type":"DURATION","value":{"begin":"T14:00","end":"T15:00"}}]Other examples can be found in thetestdirectory.FunctionsSUTime(jars=None,jvm_started=False,mark_time_ranges=False,include_range=False,jvm_flags=None,language='english')"""jars: List of paths to the SUTime Java dependencies.jvm_started: Optional attribute to specify if the JVM has already beenstarted (with all Java dependencies loaded).mark_time_ranges: Optional attribute to specify CoreNLP propertyzodiac-sutime.markTimeRanges. Default is False."Tells zodiac-sutime to mark phrases such as 'From January to March'instead of marking 'January' and 'March' separately"include_range: Optional attribute to specify CoreNLP propertyzodiac-sutime.includeRange. Default is False."Tells zodiac-sutime to mark phrases such as 'From January to March'instead of marking 'January' and 'March' separately"jvm_flags: Optional attribute to specify an iterable of string flagsto be provided to the JVM at startup. For example, this may beused to specify the maximum heap size using '-Xmx'. Has no effectif jvm_started is set to True. Default is None.language: Optional attribute to select language. The following optionsare supported: english (/en), british, spanish (/es). Default isenglish."""sutime.parse(input_str,reference_date=''):"""Parses datetime information out of string input.It invokes the SUTimeWrapper.annotate() function in Java.Args:input_str: The input as string that has to be parsed.reference_date: Optional reference data for SUTime.Returns:A list of dicts with the result from the SUTimeWrapper.annotate()call."""CreditThe team behind Stanford CoreNLPfor their awesome work and tools for the NLP communityLuis Nell (Github: originell) and teamfor maintaining JPype as interface between Python and JavaContributionsRené Springer: Support for reference dateConstantine Lignos: Support for JVM flags, adoption of CircleCI 2.0, fix for mutable default argument, fix for test executionLicenseGPLv3+ (check the LICENSE file)