Coder Social home page Coder Social logo

ontology-visualization's Introduction

Ontology Visualization

Example

./ontology_viz.py -o test.dot test.ttl -O ontology.ttl
dot -Tpng -o test.png test.dot
  • Use -o to indicate the path of output file
  • Use -O to indicate the input ontology (Optional).
  • Use -C to indicate the configuration file (Optional).
    • max_label_length: config the max length of labels. If the text exceeds the length, exceeded part will be replaced with “…”. Default value is 0.
    • blacklist: config the predicate that you don’t want to see in the graph.
    • class_inference_in_object: config the predicate that can inference the object is a Class, even if the class doesn’t defined in the ontology.
    • label_property: config the predicate that used for labeling nodes, if such a label exists, it will display inside the node.
    • tooltip_property: config the predicate that contains the tooltip texts.
    • bnode_regex: a list of regexes, if an uri matches, then it will be dispaly as a blank node without its uri nor label. It can be useful if you have a lot of reifications.
    • colors: config the colors of nodes
      • class, literal, instance can accept HEX value(e.g. "#ff0000" ), MATLAB style(e.g. "r" ), and color name (e.g. "red" ).
      "colors": {
        "class": "#ff0000",
        "literal": "r",
        "instance": "red",
      }
              
      • instance can also accept a dict value to specify the color of each class instance. And use "default" to to set color for undefined instances.
      "instance": {
        "https://tac.nist.gov/tracks/SM-KBP/2018/ontologies/SeedlingOntology#Facility": "#a6cee3",
        "default": "#ffff99"
      }
              
      • filled: config whether fill the node, default value: true.
  • Classes defined in the ontology will be omitted in the output graph. This action can be switched with argument -V.

Useful Graphviz flags

  • -K to specify which layout algorithm to use. E.g. -Kneato and -Ksfdp . Notice that inorder to use sfdp layout algorithm, you will need to build your graphviz with GTS.
  • -T to specify the output format.
  • -G to set a graph attribute. E.g. -Goverlap=prism

Requirements

In order to use this tool, you’ll need to make sure you have rdflib installed.

In order to convert dot into png or svg image, you will need Graphviz.

ontology-visualization's People

Contributors

fatestigma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ontology-visualization's Issues

add a couple of examples

Could you please add a couple of output examples? Before I see something, I have little incentive to try the tool.

`ontology_viz.py` hangs

Calling ontology_viz.py it is not responding with output. If I Ctrl+C abort the process, I get the following error:

Traceback (most recent call last):
  File "/home/ch/repos2/ontology-visualization/ontology_viz.py", line 23, in <module>
    common_ns = {URIRef(ns) for ns in (RDF, RDFS, SKOS, SCHEMA, XSD, DOAP, FOAF)}
  File "/home/ch/repos2/ontology-visualization/ontology_viz.py", line 23, in <setcomp>
    common_ns = {URIRef(ns) for ns in (RDF, RDFS, SKOS, SCHEMA, XSD, DOAP, FOAF)}
  File "/usr/lib/python3/dist-packages/rdflib/term.py", line 223, in __new__
    if not _is_valid_uri(value):
  File "/usr/lib/python3/dist-packages/rdflib/term.py", line 76, in _is_valid_uri
    if c in uri: return False
  File "/usr/lib/python3/dist-packages/rdflib/namespace.py", line 173, in __getitem__
    return self.term(key)
  File "/usr/lib/python3/dist-packages/rdflib/namespace.py", line 219, in term
    return URIRef("%s_%s" % (self.uri, i))
KeyboardInterrupt

However, the fork https://github.com/fatestigma/ontology-visualization works (and immediately responds).
Tested on Ubuntu 20.04, with Python 3.8.10, and python3-rdflib 4.2.2-5.

dot -Tpng -o test.png test.dot - command not found

Hi,

When I copy/paste ./ontology_viz.py -o test.dot test.ttl -O ontology.ttl in my terminal, I get:

[WARNING] Class http://dig.isi.edu/Time_Span doesn't exist in the ontology!
[WARNING] Property http://dig.isi.edu/at_some_time_within_date doesn't exist in the ontology!

When I copy/paste dot -Tpng -o test.png test.dot, I get:
dot: command not found

Any suggestions?
Thanks!

Problem if no namespace is used

When I put the following standard example in a file and read it in I get an exception, because the tool expects that there are namespace prefixes for all URIs:

    @prefix dc: <http://purl.org/dc/elements/1.1/> . 
    @prefix ex: <http://example.org/stuff/1.0/> . 

    <http://www.w3.org/TR/rdf-syntax-grammar> ex:editor 
        [ ex:fullName "Dave Beckett"; 
          ex:homePage <http://purl.org/net/dajobe/> ]; 
          dc:title "RDF/XML Syntax Specification (Revised)" . 

When I add tow more namespace prefixes everything is fine.

AttributeError: term 'uri' not in namespace 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'

I want to convert uls_review_after.ttl into after.dot
I found out following error:

$ python ./ontology_viz.py -o after.dot uls_review_after.ttl ontology.ttl
Traceback (most recent call last):
  File "./ontology_viz.py", line 23, in <module>
    common_ns = set(map(lambda ns: ns.uri, (RDF, RDFS, SKOS, SCHEMA, XSD, DOAP, FOAF)))
  File "./ontology_viz.py", line 23, in <lambda>
    common_ns = set(map(lambda ns: ns.uri, (RDF, RDFS, SKOS, SCHEMA, XSD, DOAP, FOAF)))
  File "/home/midannii/.conda/envs/midan2/lib/python3.7/site-packages/rdflib/namespace/__init__.py", line 212, in __getattr__
    return cls.__getitem__(name)
  File "/home/midannii/.conda/envs/midan2/lib/python3.7/site-packages/rdflib/namespace/__init__.py", line 202, in __getitem__
    raise AttributeError(f"term '{name}' not in namespace '{cls._NS}'")
AttributeError: term 'uri' not in namespace 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'

Can't split a URI that ends in a Forward Slash?

I have some partial turtle that looks like this:

@prefix fedoraObject: <http://[LocalFedoraRepository]/> .
@prefix utkevents: <http://[address-to-triplestore]/events/> .
@prefix utktitles: <http://[address-to-triplestore]/titles/> .
@prefix utksubjects: <http://[address-to-triplestore]/subjects/> .
@prefix utkspatial: <http://[address-to-triplestore]/spatial/> .
@prefix utknotes: <http://[address-to-triplestore]/notes/> .
@prefix utknames: <http://[address-to-triplestore]/names/> .
@prefix utkphysicalcollections: <http://[address-to-triplestore]/physicalcollections/> .
@prefix rdfs: <https://www.w3.org/TR/rdf-schema/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix bf: <http://id.loc.gov/ontologies/bibframe/> .
@prefix relators: <http://id.loc.gov/vocabulary/relators> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix geojson: <https://purl.org/geojson/vocab#> .
@prefix pcdm: <http://pcdm.org/models#> .
@prefix dbo: <http://dbpedia.org/ontology/> .
@prefix dce: <http://purl.org/dc/elements/1.1/> .
@prefix identifiers: <http://id.loc.gov/vocabulary/identifiers> .
@prefix edm: <http://www.europeana.eu/schemas/edm/> .
@prefix rdau: <http://rdaregistry.info/Elements/u/#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix dcmitype: <http://purl.org/dc/dcmitype/> .
@prefix owl: <https://www.w3.org/2002/07/owl#> .

<fedoraObject:tq/57/nr/06/tq57nr067>
    dce:title utktitles:1 ;
    identifiers:local "0012_000463_000214", "record_spc_4489", "Slide 1", "Film 96" ;
    dcterms:identifier "knoxgardens:115" ;
    dcterms:abstract "Photograph slide of the Tennessee state tree, the tulip tree" ;
    bf:provisionActivity utkevents:1, utkevents:2, utkevents:3 ;
    edm:hastype <http://vocab.getty.edu/aat/300134977> ;
    rdau:extent "3 1/4 x 5 inches" ;
    dce:format "image/jp2" ;
    relators:pht utknames:1 ;
    dcterms:subject utksubjects:1, utksubjects:2, utksubjects:3, utksubjects:4 ;
    dcterms:spatial utkspatial:1 ;
    bf:Note utknotes:1 ;
    pcdm:memberOf <fedoraObject:jk/88/99/adklasd908ads> ;
    relators:rps <http://id.loc.gov/authorities/names/no2014027633> ;
    bf:physicalLocation "University of Tennessee, Knoxville. Special Collections" ;
    edm:rights <http://rightsstatements.org/vocab/CNE/1.0/> .

When I try to create my dot file from this

$ ./ontology_viz.py -o tulip.dot ~/PycharmProjects/utk_hyrax_investigation/docs/test.ttlC 

it fails with ValueError: Can't split 'http://rightsstatements.org/vocab/CNE/1.0/'.

If I remove the trailing slash in the URI, the dot file is created just fine. As you can see in here, it says the URI should be http://rightsstatements.org/vocab/CNE/1.0/. Am I misunderstanding the error here?

The ontology option has no effect

Hi,

It seems like the ontology option has no effect on the output of the graph. What is it supposed to be doing?

Edit: Just to clarify, what I mean is the result of the visual graph looks exactly the same regardless of if I give it an ontology or not.

AttributeError: term 'uri' not in namespace 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'

Hi, I know this is the same issue than #13 but it didn't open when I commented back the issue, so I'm reopening a new one, sorry if I'm doing this wrong.

On Windows 10, with the following pip list:

Package    Version
---------- -------
graphviz   0.20.1
isodate    0.6.1
pip        22.3
pyparsing  3.0.9
rdflib     6.2.0
setuptools 58.1.0
six        1.16.0

Running the example provided in readme.md:
python .\ontology_viz.py -o test.dot test.ttl -O ontology.ttl

Will trigger this error:

Traceback (most recent call last):
  File "C:\Users\David Traparic\Documents\prog\ontology\ontology-visualization\ontology_viz.py", line 23, in <module>
    common_ns = set(map(lambda ns: ns.uri, (RDF, RDFS, SKOS, SCHEMA, XSD, DOAP, FOAF)))
  File "C:\Users\David Traparic\Documents\prog\ontology\ontology-visualization\ontology_viz.py", line 23, in <lambda>
    common_ns = set(map(lambda ns: ns.uri, (RDF, RDFS, SKOS, SCHEMA, XSD, DOAP, FOAF)))
  File "C:\Users\David Traparic\Documents\prog\ontology\ontoenv\lib\site-packages\rdflib\namespace\__init__.py", line 238, in __getattr__
    return cls.__getitem__(name)
  File "C:\Users\David Traparic\Documents\prog\ontology\ontoenv\lib\site-packages\rdflib\namespace\__init__.py", line 229, in __getitem__
    raise AttributeError(f"term '{name}' not in namespace '{cls._NS}'")
AttributeError: term 'uri' not in namespace 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'

I tried different rdflib version, 6.1.1 will trigger the same error, whereas 6.0.1 and 5.0.0 will trigger another error:

Traceback (most recent call last):
  File "C:\Users\David Traparic\Documents\prog\ontology\ontology-visualization\ontology_viz.py", line 6, in <module>
    from rdflib.plugins.sparql import prepareQuery
  File "C:\Users\David Traparic\Documents\prog\ontology\ontoenv\lib\site-packages\rdflib\plugins\sparql\__init__.py", line 33, in <module>
    from . import parser
  File "C:\Users\David Traparic\Documents\prog\ontology\ontoenv\lib\site-packages\rdflib\plugins\sparql\parser.py", line 184, in <module>
    Param('prefix', PN_PREFIX)) + Suppress(':').leaveWhitespace()
  File "C:\Users\David Traparic\Documents\prog\ontology\ontoenv\lib\site-packages\rdflib\plugins\sparql\parserutils.py", line 114, in __init__
    self.name = name
AttributeError: can't set attribute 'name'

Do you have any ideas why this happens ?

Bugs and enhancements

Bugs:

  • RDF prefix does not work properly: some URIs get converted to prefix:fragment, some are ns1:fragment (this is ok according to the definition of W3C), but some are still the full URIs.
  • Some BNodes still show arbitrary IDs (would be better if BNode is shown as "blank").

Enhancements:

  • Support converting a node to BNode based on regex. e.g., there are <URI1> <URI2> <URI3>, but I don't want to see the full URI of URI1, then I can add this filter and it will be converted to a BNode which will show as "blank". Notice this is not blacklist, because I still want to see this node but just don't want to see it's full URI.
  • Blacklist supports only subjects and objects (I'm not sure here), it would be better to support all subject, predicate and object URIs. Also, if a node has no connection (e.g., all its predicates are in blacklist), it can be hidden (I think this should be an option).

BTW, correct me if the feature is already there or I used it in the wrong way.

Problem with rdflib 6.0.0

With the last version of rdflib (6.0.0), I now have a the following error:

AttributeError: term 'uri' not in namespace 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'

The error is triggered from ontology_viz.py line 23. Indeed, it seems that in rdflib 6.0.0, Namespaces no longer have a .uri attribute.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.