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
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}
}

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.1.1.tar.gz (15.5 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.1.1-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ontology_verbalizer-1.1.1.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.12.8 Linux/6.8.0-1017-azure

File hashes

Hashes for ontology_verbalizer-1.1.1.tar.gz
Algorithm Hash digest
SHA256 03a8c06897f89b0754fd805ad858efa342a26aceff6a771364c337f12097a112
MD5 87053de9785f9872c8e0085dc3085655
BLAKE2b-256 da5a3836ed9ae4bb1458b23088f9647f85cc7b8d49bed8cd9f0847944e5ae034

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ontology_verbalizer-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.12.8 Linux/6.8.0-1017-azure

File hashes

Hashes for ontology_verbalizer-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7cdc5a76b807ae4dc9495a0b498f75827491444bb92b71394eb9f262de39842
MD5 9b7db68c06f050cf0a31a72e38221548
BLAKE2b-256 b988c52350eb00dc2ce92c848d0ffe80a88260847c7408b755707ff3f871a16b

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