Skip to content

Commit

Permalink
Convert browse names and use rdfs:subPropertyOf for references.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenwenzel committed Nov 16, 2023
1 parent 3948b86 commit 26489e8
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.milo.opcua.sdk.core.Reference;
import org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName;
import org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass;

import javax.xml.bind.JAXBException;
Expand Down Expand Up @@ -74,6 +75,11 @@ URI toUri(NodeId nodeId) {
return URIs.createURI(nsUri).appendLocalPart(id);
}

URI toUri(QualifiedName name) {
String nsUri = nodeSet.getNamespaceTable().getUri(name.getNamespaceIndex());
return URIs.createURI(nsUri).appendLocalPart(name.getName());
}

/**
* Converts a nodeset to an RDF representation.
*/
Expand Down Expand Up @@ -142,6 +148,10 @@ void convert() {
IResource rdfNode = em.createNamed(toUri(id), nodeType).as(IResource.class);
rdfNode.setRdfsLabel(attrs.getDisplayName().getText());
rdfNode.setRdfsComment(attrs.getDescription().getText());
QualifiedName browseName = attrs.getBrowseName();
if (browseName != null) {
rdfNode.addProperty(UA_NAMESPACE.appendLocalPart("browseName"), toUri(browseName));
}
switch (attrs.getNodeClass()) {
case ReferenceType:
// mark defined references also as object properties
Expand All @@ -166,6 +176,7 @@ void convert() {
}

// map references to RDF
boolean nodeIsReference = attrs.getNodeClass() == NodeClass.ReferenceType;
List<Reference> refs = nodeSet.getExplicitReferences().get(id);
refs.stream().forEach(ref -> {
ExpandedNodeId targetIdExpanded = ref.getTargetNodeId();
Expand All @@ -180,10 +191,11 @@ void convert() {

// convert HasSubType to rdfs:subClassOf
if (PROPERTY_HASSUBTYPE.equals(refUri)) {
URI property = nodeIsReference ? RDFS.PROPERTY_SUBPROPERTYOF : RDFS.PROPERTY_SUBCLASSOF;
if (ref.isForward()) {
em.add(new Statement(rdfTarget, RDFS.PROPERTY_SUBCLASSOF, rdfNode));
em.add(new Statement(rdfTarget, property, rdfNode));
} else {
em.add(new Statement(rdfNode, RDFS.PROPERTY_SUBCLASSOF, rdfTarget));
em.add(new Statement(rdfNode, property, rdfTarget));
}
}

Expand Down

0 comments on commit 26489e8

Please sign in to comment.