BHoM / RDF_Prototypes

Research project of the Cluster of Excellence "Integrative Computational Design and Construction for Architecture" (IntCDC) https://www.intcdc.uni-stuttgart.de/ **Project Name**: Knowledge Representation for Multi-Disciplinary Co-Design of Buildings. https://www.intcdc.uni-stuttgart.de/research/research-projects/rp-20/
GNU Lesser General Public License v3.0
9 stars 4 forks source link

Support for reading graphs exported from GraphDB #79

Open DiellzaElshani opened 1 year ago

DiellzaElshani commented 1 year ago

Description:

A graph generated from BHoM can be queried and manipulated in GraphDB. However, when a graph generated from BHoM is manipulated in GraphDB it can not be read from "fromTTL" component.

A graph exported from graphDB is saved below. ResultFrom GraphDB query.txt

Reading such graphs would allow having in Grasshopper BHoM objects new properties or links that were generated in Graph environment,.

DiellzaElshani commented 1 year ago

Actually even simple triples should readable and convertable to Custom BHoM objects.

For example, from something like this,

<http://individuals.org/666b52ed-2e08-4c0a-982e-baad32160bfd> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<http://individuals.org/e574f17d-c8fa-4cd4-8387-7480d3b6cda5> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .
<http://individuals.org/791c4755-7867-4ea6-8082-8dc5951d42e8> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> .

We should know that:

1) The ABox URI is: http://individuals.org; 2) There are 3 instances with one property GUID. The GUIDs of these instances are: 666b52ed-2e08-4c0a-982e-baad32160bfd e574f17d-c8fa-4cd4-8387-7480d3b6cda5 9a36b397-cc9d-46df-8799-3f67da45843a

In grasshopper should look like:

image

DiellzaElshani commented 1 year ago

I tried different functions using System.Text.RegularExpressions, and I got some results that look very similar to the one we generate from gh. This result almost work to convert back to BHoM objects from a graph exported from graph DB. image

Finally I understood that for us to be able to read a graph exported form graph DB we only need to fix two things:

  1. Fix the headings, the prefixes on top; and
  2. Fix the individuals representation.

    1) For the headings, the prefixed on top we need to: a) Remove the prefix without abbreviation; the one graphDB exported in the example I sent is: @prefix : <file:/snippet/generated/www.bhom.org/> . b) Add Tbox Uri twice: image

    1. For fixing the individuals representation, we need to do two things: a) Remove the superclasses, upper classes, and interfaces. Else it is counted as more than one object when converted back to BHoM, b) add the xsd data type to each property.

image

Here is also my gh script where I did the tests, it includes some c# components that fix the (1) problem with headings.

GH tests to fix the string.zip (I assume this would solve the problem when we query the whole graph, but I guess querying just some parts will also require similar approach)

DiellzaElshani commented 1 year ago

For now, we proceed with manual download of the construct query result. To do:

  1. Process the un-manipulated graph to ensure that is it compatible with fromTTL parser.
  2. Process the manipulated graph (For example, when adding new custom properties or types), ensure that is it compatible with fromTTL parse (The new added properties should be defined in the Ontology / TBox).

Future step: