2727import java .util .Set ;
2828import java .util .concurrent .ConcurrentHashMap ;
2929import org .apache .jena .datatypes .RDFDatatype ;
30+ import org .apache .jena .datatypes .TypeMapper ;
3031import org .apache .jena .datatypes .xsd .XSDDatatype ;
3132import org .apache .jena .datatypes .xsd .impl .RDFLangString ;
3233import org .apache .jena .graph .Graph ;
@@ -46,40 +47,37 @@ public class CimProfileRegistryStd implements CimProfileRegistry {
4647
4748 private static final Query typedPropertiesQuery = QueryFactory .create (
4849 """
49- PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
50- PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
51- PREFIX cims: <http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#>
52-
53- SELECT ?rdfType ?property ?cimDatatype ?primitiveType ?referenceType
54- WHERE
55- {
56- {
57- ?property rdfs:domain ?rdfType;
58- rdfs:range ?referenceType;
59- OPTIONAL {
60- ?property cims:AssociationUsed ?associationUsed
61- }
62- FILTER(!BOUND(?associationUsed) || ?associationUsed = "Yes")
63- }
64- UNION
65- {
66- ?property rdfs:domain ?rdfType;
67- cims:dataType ?cimDatatype.
68- {
69- ?cimDatatype cims:stereotype "CIMDatatype".
70- [] rdfs:domain ?cimDatatype;
71- rdfs:label ?label;
72- #rdfs:label "value";
73- cims:dataType/cims:stereotype "Primitive";
74- cims:dataType/rdfs:label ?primitiveType.
75- FILTER (!bound(?label) || str(?label) = "value")
76- }
77- UNION
50+ PREFIX cims: <http://iec.ch/TC57/1999/rdf-schema-extensions-19990926#>
51+ PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
52+ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
53+ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
54+
55+ SELECT ?rdfType ?property ?cimDatatype ?primitiveType ?referenceType
56+ WHERE
7857 {
79- ?cimDatatype cims:stereotype "Primitive";
80- rdfs:label ?primitiveType.
58+ ?rdfType rdf:type rdfs:Class .
59+ ?property rdf:type rdf:Property ;
60+ rdfs:domain ?rdfType .
61+ {
62+ ?property rdfs:range ?referenceType.
63+ FILTER NOT EXISTS { ?property cims:AssociationUsed "No" } # Filter out associations that are not used as properties
64+ }
65+ UNION
66+ {
67+ ?property cims:dataType ?cimDatatype.
68+ {
69+ ?cimDatatype cims:stereotype "Primitive";
70+ rdfs:label ?primitiveType.
71+ }
72+ UNION
73+ {
74+ ?cimDatatype cims:stereotype "CIMDatatype".
75+ BIND(IRI(CONCAT(STR(?cimDatatype), ".value")) AS ?parentTypeValue)
76+ ?parentTypeValue rdfs:domain ?cimDatatype;
77+ cims:dataType/cims:stereotype "Primitive";
78+ cims:dataType/rdfs:label ?primitiveType.
79+ }
8180 }
82- }
8381 }
8482 """ );
8583 private final ErrorHandler errorHandler ;
@@ -323,14 +321,21 @@ private Map<Node, PropertyInfo> getTypedProperties(Graph g) {
323321 final var cimDatatype = vars .get ("cimDatatype" );
324322 final var primitiveType = vars .get ("primitiveType" );
325323 final var referenceType = vars .get ("referenceType" );
324+ final var rdfDataType = primitiveType != null
325+ // retrieve CIM specific primitive type mapping
326+ ? getXsdDatatype (primitiveType .getLiteralLexicalForm ())
327+ // if no cimDatatype is given, but a referenceType is given
328+ : cimDatatype == null && referenceType != null
329+ // then this may be an XSD datatype defined as rdf:range
330+ // if it cannot be mapped, we treat it as a reference type
331+ ? TypeMapper .getInstance ().getTypeByName (referenceType .getURI ())
332+ : null ;
326333 map .put (property , new PropertyInfo (
327334 rdfType ,
328335 property ,
329336 cimDatatype ,
330- primitiveType != null
331- ? getXsdDatatype (primitiveType .getLiteralLexicalForm ())
332- : null ,
333- referenceType ));
337+ rdfDataType ,
338+ rdfDataType != null ? null : referenceType ));
334339 });
335340 return Collections .unmodifiableMap (map );
336341 }
0 commit comments