diff --git a/src/AasxCore.Samm2_2_0/SammClasses.cs b/src/AasxCore.Samm2_2_0/SammClasses.cs index ea16b4061..55b2c1685 100644 --- a/src/AasxCore.Samm2_2_0/SammClasses.cs +++ b/src/AasxCore.Samm2_2_0/SammClasses.cs @@ -1171,6 +1171,8 @@ public static class Constants { public static string NamespaceURN = "urn:samm:org.eclipse.esmf.samm:"; + public static string PredicateA = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + public static Type[] AddableCharacteristic = { typeof(Trait), diff --git a/src/AasxPackageLogic/DispEditHelperModules.cs b/src/AasxPackageLogic/DispEditHelperModules.cs index 2db295c33..5838193f9 100644 --- a/src/AasxPackageLogic/DispEditHelperModules.cs +++ b/src/AasxPackageLogic/DispEditHelperModules.cs @@ -3533,7 +3533,7 @@ public static List ImportSammModelParseRdfCollection( if (collPtr != null && (collPtr.NodeType == NodeType.Uri || collPtr.NodeType == NodeType.Literal)) { // only a single member is given - lsr.Add(createInstance?.Invoke(RdfHelper.GetLiteralStrValue(collPtr), false)); + lsr.Add(createInstance?.Invoke(RdfHelper.GetTerminalStrValue(collPtr), false)); } else { @@ -3589,7 +3589,21 @@ public static List ImportSammModelParseRdfCollection( public static class RdfHelper { - public static string GetLiteralStrValue(INode node) + /// + /// Dirty. Used for the generation of names of nodes for anonymouse node instances + /// of the parsed graph. + /// + private static int _anonymousNodeIndex = 1; + + public static bool IsTerminalNode(INode node) + { + if (node == null) + return false; + return node.NodeType == NodeType.Uri + || node.NodeType == NodeType.Literal; + } + + public static string GetTerminalStrValue(INode node) { if (node == null) return ""; @@ -3597,8 +3611,15 @@ public static string GetLiteralStrValue(INode node) return ln.Value; return node.ToSafeString(); } + + public static string GenerateAnonymousId(string topic) + { + return $"SAMM_auto_{(_anonymousNodeIndex++):00000}"; + } } + + public static void ImportSammModelToConceptDescriptions( Aas.Environment env, string fn) @@ -3629,7 +3650,7 @@ public static void ImportSammModelToConceptDescriptions( } // find all potential SAMM elements " :xxx a bamm:XXXX" - foreach (var trpSammElem in g.GetTriplesWithPredicate(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"))) + foreach (var trpSammElem in g.GetTriplesWithPredicate(new Uri(Samm.Constants.PredicateA))) { // check, if there is a SAMM type behind the object var sammElemUri = trpSammElem.Object.ToString(); @@ -3678,9 +3699,10 @@ public static void ImportSammModelToConceptDescriptions( pred: new VDS.RDF.UriNode(new Uri(propSearchUri)))) { // now let the property type decide, how to - // put in the property + // put data into the property - var objStr = RdfHelper.GetLiteralStrValue(trpProp.Object); + var objStr = RdfHelper.GetTerminalStrValue(trpProp.Object); + var isTerminalNode = RdfHelper.IsTerminalNode(trpProp.Object); // List of Samm.LangString if (pii.PropertyType.IsAssignableTo(typeof(List))) @@ -3745,8 +3767,33 @@ public static void ImportSammModelToConceptDescriptions( // just SammReference if (pii.PropertyType.IsAssignableTo(typeof(Samm.SammReference))) { - // simply set the value - pii.SetValue(sammInst, new SammReference(objStr)); + // anonymous node or note + if (isTerminalNode) + { + // simply set the value + pii.SetValue(sammInst, new SammReference(objStr)); + } + else + { + // in order to be valid anonymous node, there needs to + // the "a" relationship behind it + var trpA = g.GetTriplesWithSubjectPredicate( + subj: trpProp.Object, + pred: new UriNode(new Uri(Samm.Constants.PredicateA)))?.FirstOrDefault(); + + if (trpA == null) + continue; + + // assume to have an anonymous node behind the node + // make a nice id + var newNodeid = RdfHelper.GenerateAnonymousId(""); + + // set this as reference .. + pii.SetValue(sammInst, new SammReference(newNodeid)); + + // and recurse with this node as a starting point + ; + } } // just string @@ -3809,7 +3856,7 @@ public static void ImportSammModelToConceptDescriptions( subj: trpSammElem.Subject, pred: new VDS.RDF.UriNode(new Uri(elemPred)))) { - elemName = RdfHelper.GetLiteralStrValue(trpProp.Object); + elemName = RdfHelper.GetTerminalStrValue(trpProp.Object); } // Aspect is another special case