Skip to main content

A Python package for ontology verbalization

Project description

OWL Ontology Verbalizer

Installation

pip install ontology-verbalizer

Usage

Configure URIs to ignore or rename

ignore = {
    'http://www.w3.org/2002/07/owl#onDatatype',
    'http://www.w3.org/2000/01/rdf-schema#seeAlso',
    'http://www.w3.org/2000/01/rdf-schema#label',
    'http://www.w3.org/2000/01/rdf-schema#comment',
    'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
    'http://www.w3.org/2000/01/rdf-schema#isDefinedBy',
}

rephrased = {
    'http://www.w3.org/2002/07/owl#equivalentClass': 'is same as',
    'http://www.w3.org/2000/01/rdf-schema#subClassOf': 'is a type of',
    'http://www.w3.org/2002/07/owl#intersectionOf': 'all of',
    'http://www.w3.org/2002/07/owl#unionOf': 'any of',
    'http://www.w3.org/2002/07/owl#disjointWith': 'is different from',
    'http://www.w3.org/2002/07/owl#withRestrictions': 'must be'
}

Configure LLM of choice

from verbalizer.nlp import ChatGptModelParaphrase

model = ChatGptModelParaphrase(api_key='sk-xyz', model='gpt-4o', temperature=0.7)

Perform Verbalization

from verbalizer.process import Processor

ontology = 'pizza.ttl'
name = 'pizza'
processor = Processor(llm=model, vocab_ignore=ignore, vocab_rephrased=rephrased, min_statements=1)
processor.process(name, ontology, output_dir='/path/to/my/output')

OWL Fragment Pseudo Text LLM Text
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:deep_pan_base a owl:Class ; rdfs:subClassOf :pizza_base ; owl:disjointWith :thin_and_crispy_base .

deep pan base is a type of a pizza base.
deep pan base is different from a thin and crispy base.
A deep pan base is a type of pizza base that differs from a thin and crispy base.
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:capricciosa a owl:Class ; rdfs:subClassOf [ a owl:Restriction ; owl:onProperty :has_topping ; owl:someValuesFrom :peperonata_topping ], [ a owl:Restriction ; owl:onProperty :has_topping ; owl:someValuesFrom :olive_topping ], [ a owl:Restriction ; owl:onProperty :has_topping ; owl:someValuesFrom :caper_topping ], [ a owl:Restriction ; owl:onProperty :has_topping ; owl:someValuesFrom :mozzarella_topping ], [ a owl:Restriction ; owl:allValuesFrom [ a owl:Class ; owl:unionOf [ rdf:first :tomato_topping ; rdf:rest [ rdf:first :ham_topping ; rdf:rest [ rdf:first :mozzarella_topping ; rdf:rest [ rdf:first :anchovies_topping ; rdf:rest [ rdf:first :olive_topping ; rdf:rest [ rdf:first :peperonata_topping ; rdf:rest [ rdf:first :caper_topping ; rdf:rest :nil ] ] ] ] ] ] ] ] ; owl:onProperty :has_topping ], [ a owl:Restriction ; owl:onProperty :has_topping ; owl:someValuesFrom :anchovies_topping ], [ a owl:Restriction ; owl:onProperty :has_topping ; owl:someValuesFrom :ham_topping ], [ a owl:Restriction ; owl:onProperty :has_topping ; owl:someValuesFrom :tomato_topping ], :named_pizza ; owl:disjointWith :american, :american_hot, :cajun, :caprina, :fiorentina, :four_seasons, :frutti_di_mare, :giardiniera, :la_reine, :margherita, :mushroom, :napoletana, :parmense, :pollo_ad_astra, :prince_carlo, :quattro_formaggi, :rosa, :siciliana, :sloppy_giuseppe, :soho, :unclosed_pizza, :veneziana .

capricciosa is a type of a named pizza.
capricciosa is a type of at least has topping some a caper topping.
capricciosa is a type of at least has topping some a ham topping.
capricciosa is a type of at least has topping some a mozzarella topping.
capricciosa is a type of at least has topping some a peperonata topping.
capricciosa is a type of at least has topping some a tomato topping.
capricciosa is a type of at least has topping some an anchovies topping.
capricciosa is a type of at least has topping some an olive topping.
capricciosa is a type of only has topping any of (a tomato topping, and a ham topping, and a mozzarella topping, and an anchovies topping, and an olive topping, and a peperonata topping, and a caper topping).
capricciosa is different from (a la reine, and a frutti di mare, and a fiorentina, and a margherita, and a sloppy giuseppe, and a veneziana, and an american hot, and an unclosed pizza, and a mushroom, and a pollo ad astra, and a caprina, and a cajun, and a giardiniera, and an american, and a prince carlo, and a siciliana, and a parmense, and a rosa, and a soho, and a quattro formaggi, and a four seasons, and a napoletana).
Capricciosa is a specific type of pizza that includes various toppings. It features caper, ham, mozzarella, peperonata, tomato, anchovies, and olive toppings. This pizza exclusively contains these toppings and does not have any other toppings. Capricciosa is distinct from other pizzas such as la reine, frutti di mare, fiorentina, margherita, sloppy giuseppe, veneziana, american hot, unclosed pizza, mushroom, pollo ad astra, caprina, cajun, giardiniera, american, prince carlo, siciliana, parmense, rosa, soho, quattro formaggi, four seasons, and napoletana.
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:chicken_topping a owl:Class ; rdfs:subClassOf [ a owl:Restriction ; owl:onProperty :has_spiciness ; owl:someValuesFrom :mild ], :meat_topping ; owl:disjointWith :ham_topping, :hot_spiced_beef_topping, :peperoni_sausage_topping .

chicken topping is a type of a meat topping.
chicken topping is a type of at least has spiciness some a mild.
chicken topping is different from (a peperoni sausage topping, and a hot spiced beef topping, and a ham topping).
Chicken topping is a type of meat topping that has at least some mild spiciness. It is different from pepperoni sausage topping, hot spiced beef topping, and ham topping.

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

ontology_verbalizer-1.0.1.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ontology_verbalizer-1.0.1-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file ontology_verbalizer-1.0.1.tar.gz.

File metadata

  • Download URL: ontology_verbalizer-1.0.1.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1024-azure

File hashes

Hashes for ontology_verbalizer-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9eaefc474f9723c4348c679c2719f9d11a2f38844c73d8c152f7684f36747218
MD5 616520505c189c8724238d88dab79262
BLAKE2b-256 10f7476b6c9275838c84b47bf8ca8d3e37a89cf3605d8cf2b84c76edca3bedf6

See more details on using hashes here.

File details

Details for the file ontology_verbalizer-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: ontology_verbalizer-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1024-azure

File hashes

Hashes for ontology_verbalizer-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e27101f9b9dd85205271018aca4d4bd727c426bb9c28686957a269dde0697a88
MD5 d2d188d22fd327da67045d0ab9323aee
BLAKE2b-256 ce81fdcfc3a7f8b17e1d2ddedcb368742a6d904806c33825809d31baeb810b9e

See more details on using hashes here.

Supported by

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