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.0.tar.gz (15.8 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.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ontology_verbalizer-1.1.0.tar.gz
Algorithm Hash digest
SHA256 9a0678afc4f1a9c1f90f857e8d895cab2afd7bf593ae63c9cd72d71f749fb54c
MD5 1bfd0f13e1b5fd028676077ada08eabe
BLAKE2b-256 2d6f8a7b5ee0c2e07343e25e752a97d6946199edf12a9990d1a262bfb25c6c4e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ontology_verbalizer-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b6ea923a3e0bdf3152a1fffc4fb3caba50e40b0b54dab74910a442ddab9b5f3
MD5 81a392910251d7249e36dc2f106ac5fd
BLAKE2b-256 d4448483c114e63959c18103d3f8e96e150153ebc82a91d0fdae11478ada055c

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