Skip to main content

A simple python package for accessing the trips ontology and lexicon

Project description

PyTrips PyPI version

Build Status

PyTrips provides a python interface to interacting with the TRIPS ontology and parser.

Installation

pip install pytrips
pip install pytrips[tools] # optional
python -c "import nltk; nltk.download('wordnet')"

Basic Usage

Load the ontology and retrieve a type by name:

from pytrips.ontology import load
ont = load()

catch = ont["catch"] # lookup an ontology type

And then inspect said type:

print(catch)
print(catch.parent)
print(catch.children)
print(catch.arguments)

which should result in:

# ont::catch
# ont::co-motion
# []
# [<TripsRestriction :neutral >, <TripsRestriction :source >, <TripsRestriction :result >, <TripsRestriction :extent >, <TripsRestriction :affected >, <TripsRestriction :agent >]

Check if types subsume each other:

catch < ont["event-of-action"]

# Make sure at least one type is explicitly a TripsType.  The other can be a string.
"food" > ont["bread"]

Or get the lowest common subsumer of two types:

ont["bread"] ^ ont["geo-object"]

For simplicity, lookup words and ontology types in the same way:

ont["person"] # default is to look up an ontology type
ont["ont::person"] # explicitly get the ontology type named "ont::person"
ont["w::person"] # or lookup the list of ontology types that the word "person" can map to

WordNet lookups are similar:

ont["wn::cat%1:06:00::"]
>> [ont::device]

ont["q::cat"] # returns all lexical and wordnet mappings for the word cat in a dictionary
>> {'lex': [ont::nonhuman-animal, ont::medical-diagnostic],
 'wn': [ont::pharmacologic-substance,
  ont::female-person,
  ont::communication-party,
  ont::male-person,
  ont::medication,
  ont::mammal,
  ont::device,
  ont::land-vehicle,
  ont::vomit]}

Or we can specify a part of speech to limit the search:

ont[("q::move", 'v')]
>> {'lex': [ont::cause-move, ont::move, ont::provoke, ont::activity-ongoing],
 'wn': [ont::cause-effect,
  ont::change,
  ont::believe,
  ont::activity-event,
  ont::commerce-sell,
  ont::move,
  ont::progress,
  ont::live,
  ont::suggest]}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytrips-0.5.22.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

pytrips-0.5.22-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file pytrips-0.5.22.tar.gz.

File metadata

  • Download URL: pytrips-0.5.22.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for pytrips-0.5.22.tar.gz
Algorithm Hash digest
SHA256 fb8fd9ae6d0b03472633f39efbfe9cf09be1b9017fb212430f3d20c7c6073fab
MD5 5fdb981ab0ea9d94bfec476c21dd20e0
BLAKE2b-256 f5dfd4fd9184d27cf0cbff116010366b4d68b9aabf49ba95e245ffb3faf711ec

See more details on using hashes here.

File details

Details for the file pytrips-0.5.22-py3-none-any.whl.

File metadata

  • Download URL: pytrips-0.5.22-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for pytrips-0.5.22-py3-none-any.whl
Algorithm Hash digest
SHA256 7b4057e1caf945820e2d64346fa3acea20af2649ab53cb05fa65b76095a21428
MD5 f47953c3e03e3f3b62ea2fde6e1eb971
BLAKE2b-256 5a8fcdbcec887367d4f244ae3f4afa1b687a742111f823415000352c9807d9a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page