Skip to main content

IBM Watson Natural Language Understanding + Watson Knowledge Studio tools

Project description

wkstools

wkstools is a small convenience library that provides utilities to efficiently work with entities and relations provided by IBM Natural Language Understanding.

PyPI - License PyPI

Intuition

When using IBM Watson Knowledge Studio (WKS) models in IBM Natural Language Understanding (NLU), in most cases the resulting JSON requires post-processing to work with the extracted entities and relations. This is where wkstools comes to help:

Let's assume you have trained a machine learning model in IBM Watson Knowledge Studio that recognizes relations between quantifiers, numbers and units. "I want a smartphone that weighs no more than 160 g."

If we want to build a tool that allows natural language searches for smartphone against a product database, you need to understand the relevant concepts in a structured manner. For the above example it will be helpful to extract the relations that point from the operator (no more than) to the (value) and the unit (g).

See the intuition.py and nlu_response.json in the exmaples folder to have a running example.

Requirements

  • Python 3.6+
  • Pydantic

Installation

$ pip install wkstools

Usage

Parse entities and relations

To parse the NLU JSON response retrieved from IBM Natural Language Understanding, use:

import wkstools

# Your NLU JSON response to process
nlu_response = '{..., "relations": [{"type": "specifiesValue", ...], "entities": [...]}' 

entities = wkstools.parse_entities(nlu_response)
relations = wkstools.parse_relations(nlu_response)

See the entity and relation models for available fields.

Access specific relations

import wkstools

# Your NLU JSON response to process
nlu_response = '{..., "relations": [{"type": "specifiesValue", ...], "entities": [...]}' 

relations = wkstools.parse_relations(nlu_response)

value_relations = wkstools.get_relations_by_type(relations, "specifiesValue")

Testing

To lint and test, run:

$ ./scripts/test.sh

To get the html coverage report run:

$ ./scripts/test-cov-report.sh

License

This project is licensed under the terms of the MIT license.

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

wkstools-0.1.2.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

wkstools-0.1.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file wkstools-0.1.2.tar.gz.

File metadata

  • Download URL: wkstools-0.1.2.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.24.0

File hashes

Hashes for wkstools-0.1.2.tar.gz
Algorithm Hash digest
SHA256 35059e399d99c0683e051dd95e36cb08be802125f5a4c65f23d448423a266fd7
MD5 918482c7da0e263b482e59a70c410e89
BLAKE2b-256 88be7e1c595b7b8a795931e9b35a3ce1bf2dec30597b5aea0d6e5d8644623036

See more details on using hashes here.

File details

Details for the file wkstools-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: wkstools-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.24.0

File hashes

Hashes for wkstools-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bb2b9fa19c0f71415bda728fe6d5018acdf2f4ece17111db3700d839aa8a1454
MD5 74c0e27cc3bc99d3fb814d9e3243265b
BLAKE2b-256 f331fcb22094473b48d75779d46c51ebef957d865dd2c0bb849315c1935a793e

See more details on using hashes here.

Supported by

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