Skip to main content

OWL Ontology Verbalizer

PyPI - Version PyPI - Python Version

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
from verbalizer.vocabulary import Vocabulary
from verbalizer import Verbalizer

ontology = Processor.from_file('pizza.ttl')

# create vocabulary and verbalizer
vocab = Vocabulary(ontology, ignore=ignore, rephrased=rephrased)
verbalizer = Verbalizer(vocab)

# start verbalization process
results = Processor.verbalize_with(verbalizer, namespace="pizza", output_dir="./output")

Examples

Expand to see examples

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.

Citation

@inproceedings{zaitoun2024generating,
  title={Generating Ontology-Learning Training-Data through Verbalization},
  author={Zaitoun, Antonio and Sagi, Tomer and Peleg, Mor},
  booktitle={Proceedings of the AAAI Symposium Series},
  volume={4},
  number={1},
  pages={233--241},
  year={2024}
}

Release files for ontology-verbalizer 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ontology-verbalizer 1.1.2
File Size Uploaded
ontology_verbalizer-1.1.2.tar.gz 15.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ontology-verbalizer 1.1.2
File Interpreter ABI Platform
ontology_verbalizer-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size:34.4 kB

Release files / ontology_verbalizer-1.1.2.tar.gz

Download URL ontology_verbalizer-1.1.2.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e0577046d0186ccda096d47b92e67ab6044c4d78dd2d4d68cf65a0aa8c96b774
BLAKE2b-256 checksum
How to use checksums
d0c15c2adb9023602f73984ac3b1ce1b4ea220ccb92660ae4bd6abab98f51ce6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.12.8 Linux/6.8.0-1017-azure

Release files / ontology_verbalizer-1.1.2-py3-none-any.whl

Download URL ontology_verbalizer-1.1.2-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0d4176ca68d5d01edc3d96ee294aa209c3ca9191d86c1e1f7505a7a856509c1
BLAKE2b-256 checksum
How to use checksums
53b99d45dac5d5efa86b002b18f14c2470c848fd12bcfa4c5d8b4654d3b03ab2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.12.8 Linux/6.8.0-1017-azure

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page