Skip to content

Commit

Permalink
Merge pull request #9 from equinor/story/173985-find-boundary-from-types
Browse files Browse the repository at this point in the history
find boundary from types
  • Loading branch information
daghovland authored Aug 22, 2024
2 parents 0a1905a + a6b61b1 commit f806838
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 25 deletions.
21 changes: 21 additions & 0 deletions client/Boundaries/Boundaries/DatalogCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,25 @@ public string CreateBoundaryDatalogRule(string internalComponentLabel, IriRefere
dexpi:PipingOrEquipment [?node].
""";
}


public string CreateConnectedSparqlQuery()
{
return $"select * where {{?s a <{BoundaryGraph}>; <http://sandbox.dexpi.org/rdl/TagNameAssignmentClass> ?tag.}}";
}
public string CreateConnectedDatalogRule(string internalComponentLabel)
{
return $$"""
<{{BoundaryGraph}}> [?node] :-
rdfs:label [?internal, "{{internalComponentLabel}}"],
imf:connectedTo [?internal, ?node],
dexpi:PipingOrEquipment [?node].
<{{BoundaryGraph}}> [?node] :-
<{{BoundaryGraph}}> [?node1],
imf:connectedTo [?node1, ?node],
dexpi:PipingOrEquipment [?node],
NOT dexpi:Equipment [?node1].
""";
}
}
42 changes: 42 additions & 0 deletions client/Boundaries/Boundaries/DexpiApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using IriTools;

namespace Boundaries;

public static class DexpiApi{
public static async Task<string> GetCommissioningPackage(string internalComponentLabel, IriReference[] borderComponentIris, string dexpiFilePath)
{
var datalogCreator = new DatalogCreator();
var datalog = datalogCreator.CreateBoundaryDatalogRule(internalComponentLabel, borderComponentIris);
var conn = RdfoxApi.GetDefaultConnectionSettings();
await RdfoxApi.LoadDatalog(conn, datalog);

var data = File.ReadAllText(dexpiFilePath);
await RdfoxApi.LoadData(conn, data);

var queryString = datalogCreator.CreateCommissioningSparqlQuery();
var result = await RdfoxApi.QuerySparql(conn, queryString);

await RdfoxApi.DeleteData(conn, data);
await RdfoxApi.DeleteDatalog(conn, datalog);
return result;
}


public static async Task<string> GetConnectedEquipment(string internalComponentLabel, string dexpiFilePath)
{
var datalogCreator = new DatalogCreator();
var datalog = datalogCreator.CreateConnectedDatalogRule(internalComponentLabel);
var conn = RdfoxApi.GetDefaultConnectionSettings();
await RdfoxApi.LoadDatalog(conn, datalog);

var data = File.ReadAllText(dexpiFilePath);
await RdfoxApi.LoadData(conn, data);

var queryString = datalogCreator.CreateConnectedSparqlQuery();
var result = await RdfoxApi.QuerySparql(conn, queryString);

await RdfoxApi.DeleteData(conn, data);
await RdfoxApi.DeleteDatalog(conn, datalog);
return result;
}
}
21 changes: 6 additions & 15 deletions client/Boundaries/Boundaries/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ internal class Program
{
private static async Task Main(string[] args)
{
if (args.Length < 3)
if (args.Length < 2)
{
Console.WriteLine(
"Usage \"dotnet run filename-for-dexpi-in-rdf \"label-of-internal-componenet\" iri-of-border-component ... iri-of-border-component ");
Console.WriteLine(
"For example \"dotnet run ../../../rml/pandid.trig \"T4750\" https://assetid.equinor.com/plantx#Nozzle-12 https://assetid.equinor.com/plantx#Nozzle-8 https://assetid.equinor.com/plantx#PlateHeatExchanger-1 https://assetid.equinor.com/plantx#ReciprocatingPump-1");
"For finding a commissioning package from boundary use f.ex. \"dotnet run ../../../rml/pandid.trig \"T4750\" https://assetid.equinor.com/plantx#Nozzle-12 https://assetid.equinor.com/plantx#Nozzle-8 https://assetid.equinor.com/plantx#PlateHeatExchanger-1 https://assetid.equinor.com/plantx#ReciprocatingPump-1\"");
Console.WriteLine("For finding directly connected equipemnt use f.ex. \"dotnet run ../../../rml/pandid.trig \"P4711\"");
return;
}

Expand All @@ -25,21 +26,11 @@ private static async Task Main(string[] args)
}

var borderComponentIris = args.Skip(2).Select(iri => new IriReference(iri)).ToArray();
var datalogCreator = new DatalogCreator();
var datalog = datalogCreator.CreateBoundaryDatalogRule(internalComponentLabel, borderComponentIris);
var conn = RdfoxApi.GetDefaultConnectionSettings();
await RdfoxApi.LoadDatalog(conn, datalog);

var data = File.ReadAllText(dexpiFilePath);
await RdfoxApi.LoadData(conn, data);

var queryString = datalogCreator.CreateCommissioningSparqlQuery();
var result = await RdfoxApi.QuerySparql(conn, queryString);
var result = borderComponentIris.Any() ?
await DexpiApi.GetCommissioningPackage(internalComponentLabel, borderComponentIris, dexpiFilePath)
: await DexpiApi.GetConnectedEquipment(internalComponentLabel, dexpiFilePath);
Console.WriteLine("Commissioning package:");
Console.WriteLine(result);

await RdfoxApi.DeleteData(conn, data);
await RdfoxApi.DeleteDatalog(conn, datalog);

}
}
4 changes: 3 additions & 1 deletion client/Boundaries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ Start a rdfox server from the folder [../../rdfox/](../../rdfox) with the follow
RDFox sandbox ../../rdfox boundaries
```

Then run `dotnet run` and follow instructions
Then run `dotnet run` and follow instructions.

There are two "modes". In both modes you must give an rdf file and the tag of an equipment. If you only give this, it finds all directly connected Equipment. If you also give a list of boundary IRIs it will give all components inside those boundary. Inside is defined as the same side as the equipment with the tag.
13 changes: 13 additions & 0 deletions datalog/surrounding.datalog
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
prefix data: <https://assetid.equinor.com/plantx/document/12345#>


data:connectedEquipment [?node] :-
rdfs:label [?internal, "P4712"],
imf:connectedTo [?internal, ?node],
dexpi:PipingOrEquipment [?node].

data:connectedEquipment [?node] :-
data:connectedEquipment [?node1],
imf:connectedTo [?node1, ?node],
dexpi:PipingOrEquipment [?node],
NOT dexpi:Equipment [?node1].
11 changes: 10 additions & 1 deletion rdfox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Run the rml mapper scripts as described in [../rml/README.md](../rml/README.md)

This will create a file [../rml/pandid.trig](../rml/pandid.trig)

## Running the example
## Running the example commmissioning package
In this folder, run
```
RDFox sandbox . dexpi
Expand All @@ -32,3 +32,12 @@ To run a server for use with [Boundaries cli](../client/Boundaries/Boundaries.sl
RDFox sandbox . boundaries
```
This will load ontology and prefixes, but no data.

## Running the pump connections example
In this folder, run
```
RDFox sandbox . connected
```
This will load ontology and datalog rules, and in addition load the data in [../rml/pandid.trig](../rml/pandid.trig)

There are a lot of warnings about axioms in the IMF ontology that cannot be handled. This can safely be ignored. Other warnings and errors should be checked, especially if the last output is not the expected commissioning package output
6 changes: 6 additions & 0 deletions rdfox/commit-procedure.sparql
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ INSERT {
TT SHACL_DN { schema:shacl ?s ?p ?o} .
FILTER(?p IN (sh:sourceShape, sh:resultMessage, sh:value))
}

INSERT {
?s a <https://rdfox.com/vocabulary#ConstraintViolation> .
} WHERE {
?s a owl:Nothing.
}
9 changes: 9 additions & 0 deletions rdfox/connected.rdfox
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
boundaries.rdfox

import ../datalog/surrounding.datalog
import +p "../rml/pandid.trig"

endpoint start

set output out
select * where {?s a data:connectedEquipment; <http://sandbox.dexpi.org/rdl/TagNameAssignmentClass> ?tag.}
8 changes: 0 additions & 8 deletions rml/element-map.rml.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,4 @@
rr:constant "http://ns.imfid.org/imf#productAspect" ;
rr:termType rr:IRI
];
],

[
rr:predicate "http://ns.imfid.org/imf#partOf";
rr:objectMap [
rr:template "https://assetid.equinor.com/plantx#{../@ID}";
rr:termType rr:IRI
];
].

0 comments on commit f806838

Please sign in to comment.