All Projects → FraBle → python-sutime

FraBle / python-sutime

Licence: GPL-3.0 license
Python wrapper for Stanford CoreNLP's SUTime

Programming Languages

python
139335 projects - #7 most used programming language
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to python-sutime

Arxiv.py
Python wrapper for the arXiv API
Stars: ✭ 367 (+156.64%)
Mutual labels:  python-wrapper
Crycompare
Python wrapper for CryptoCompare public API
Stars: ✭ 70 (-51.05%)
Mutual labels:  python-wrapper
Pydp
A python wrapper for https://github.com/google/differential-privacy
Stars: ✭ 178 (+24.48%)
Mutual labels:  python-wrapper
Bottlenose
A Python wrapper for the Amazon Product Advertising API.
Stars: ✭ 561 (+292.31%)
Mutual labels:  python-wrapper
Python Documentcloud
A deprecated Python wrapper for the DocumentCloud API
Stars: ✭ 60 (-58.04%)
Mutual labels:  python-wrapper
Pylibfreenect2
A python interface for libfreenect2
Stars: ✭ 117 (-18.18%)
Mutual labels:  python-wrapper
Api
Vulners Python API wrapper
Stars: ✭ 313 (+118.88%)
Mutual labels:  python-wrapper
Tosdatabridge
A collection of resources for pulling real-time streaming data off of TDAmeritrade's ThinkOrSwim(TOS) platform; providing C, C++, Java and Python interfaces.
Stars: ✭ 229 (+60.14%)
Mutual labels:  python-wrapper
Domonit
A Deadly Simple Docker Monitoring Wrapper For Docker API
Stars: ✭ 67 (-53.15%)
Mutual labels:  python-wrapper
Webexteamssdk
Work with the Webex Teams APIs in native Python!
Stars: ✭ 168 (+17.48%)
Mutual labels:  python-wrapper
Pyowm
A Python wrapper around the OpenWeatherMap web API
Stars: ✭ 654 (+357.34%)
Mutual labels:  python-wrapper
Small norb
Python wrapper to small NORB dataset
Stars: ✭ 40 (-72.03%)
Mutual labels:  python-wrapper
Py Solc
Python wrapper around the solc Solidity compiler.
Stars: ✭ 126 (-11.89%)
Mutual labels:  python-wrapper
Yolo3 4 Py
A Python wrapper on Darknet. Compatible with YOLO V3.
Stars: ✭ 504 (+252.45%)
Mutual labels:  python-wrapper
Fbrecog
An unofficial python wrapper for the Facebook face recognition endpoint
Stars: ✭ 184 (+28.67%)
Mutual labels:  python-wrapper
Stanford Openie Python
Stanford Open Information Extraction made simple!
Stars: ✭ 348 (+143.36%)
Mutual labels:  python-wrapper
Python Duckling
Python wrapper for wit.ai's Duckling Clojure library
Stars: ✭ 114 (-20.28%)
Mutual labels:  python-wrapper
Image2text
📋 Python wrapper to grab text from images and save as text files using Tesseract Engine
Stars: ✭ 243 (+69.93%)
Mutual labels:  python-wrapper
Zenpy
Python wrapper for the Zendesk API
Stars: ✭ 222 (+55.24%)
Mutual labels:  python-wrapper
Homematicip Rest Api
A python wrapper for the homematicIP REST API (Access Point Based)
Stars: ✭ 135 (-5.59%)
Mutual labels:  python-wrapper

sutime

Python wrapper for Stanford CoreNLP's SUTime Java library.
Docs are also hosted on GitHub Pages.

Build Status

Travis CI Builds

Travis CI

PyPI

PyPI Version PyPI Downloads

Code Quality

Codacy Badge Scrutinizer Coverity Scan Code Climate maintainability CodeFactor Requirements Status

Installation

>> # Ideally, create a virtual environment before installing any dependencies
>> pip install sutime
>> # Install Java dependencies
>> mvn dependency:copy-dependencies -DoutputDirectory=./jars -f $(python3 -c 'import importlib; import pathlib; print(pathlib.Path(importlib.util.find_spec("sutime").origin).parent / "pom.xml")')

Append -P spanish to the mvn command to include the Spanish language model.

Supported Languages

SUTime 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 for arabic, chinese, english, french, german, and spanish:

>> mvn dependency:copy-dependencies -DoutputDirectory=./jars -f $(python -c 'import importlib; import pathlib; print(pathlib.Path(importlib.util.find_spec("sutime").origin).parent / "pom.xml")') -P <language>

However, SUTime only supports a subset (default model and spanish) of CoreNLP's languages and the other language models will get ignored.

Example

import json
from sutime import SUTime

if __name__ == '__main__':
    test_case = 'I need a desk for tomorrow from 2pm to 3pm'
    sutime = SUTime(mark_time_ranges=True, include_range=True)
    print(json.dumps(sutime.parse(test_case), sort_keys=True, indent=4))

Result:

[
    {
        "end": 26,
        "start": 18,
        "text": "tomorrow",
        "timex-value": "2020-11-03",
        "type": "DATE",
        "value": "2020-11-03"
    },
    {
        "end": 42,
        "start": 27,
        "text": "from 2pm to 3pm",
        "type": "DURATION",
        "value": {
            "begin": "T14:00",
            "end": "T15:00"
        }
    }
]

Other examples can be found in the test directory.

Functions

SUTime(
    jars: Optional[str] = None,
    jvm_started: Optional[bool] = False,
    mark_time_ranges: Optional[bool] = False,
    include_range: Optional[bool] = False,
    jvm_flags: Optional[List[str]] = None,
    language: Optional[str] = 'english',
):
    """
    Args:
        jars (Optional[str]): Path to previously downloaded SUTime Java
            dependencies. Defaults to False.
        jvm_started (Optional[bool]): Flag to indicate that JVM has been
            already started (with all Java dependencies loaded). Defaults
            to False.
        mark_time_ranges (Optional[bool]): SUTime flag for
            sutime.markTimeRanges. Defaults to False.
            "Whether or not to recognize time ranges such as 'July to
            August'"
        include_range (Optional[bool]): SUTime flag for
            sutime.includeRange. Defaults to False.
            "Whether or not to add range info to the TIMEX3 object"
        jvm_flags (Optional[List[str]]): List of flags passed to JVM. For
            example, this may be used to specify the maximum heap size
            using '-Xmx'. Has no effect if `jvm_started` is set to True.
            Defaults to None.
        language (Optional[str]): Selected language. Currently supported
            are: english (/en), british, spanish (/es). Defaults to
            `english`.
    """

sutime.parse(input_str: str, reference_date: Optional[str] = '') -> List[Dict]:
    """Parse datetime information out of string input.

    It invokes the SUTimeWrapper.annotate() function in Java.

    Args:
        input_str (str): The input as string that has to be parsed.
        reference_date (Optional[str]): Optional reference data for SUTime.
            Defaults to `''`.

    Returns:
        A list of dicts with the result from the `SUTimeWrapper.annotate()`
        call.

    Raises:
        RuntimeError: An error occurs when CoreNLP is not loaded.
    """

Credit

Contributions

  • René Springer: Support for reference date
  • Constantine Lignos: Support for JVM flags, adoption of CircleCI 2.0, fix for mutable default argument, fix for test execution
  • Cole Robertson: Updated instructions, JAR requirements, and SUTime JAR imports
  • Ludovico Pestarino: Modified json.loads for compatibility with json data (string handling)

License

  • GPLv3+ (check the LICENSE file)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].