From 8782de1cd048e7a845c6b9779f532073a76ba6c3 Mon Sep 17 00:00:00 2001 From: Michael Hoffmeister Date: Wed, 1 Nov 2023 13:59:05 +0100 Subject: [PATCH] * before refactoring becaus of anonymous instances --- src/AasxCore.Samm2_2_0/SammClasses.cs | 51 ++++---- src/AasxPackageExplorer/debug.MIHO.script | 2 +- src/AasxPackageLogic/DispEditHelperModules.cs | 116 ++++++++++-------- 3 files changed, 95 insertions(+), 74 deletions(-) diff --git a/src/AasxCore.Samm2_2_0/SammClasses.cs b/src/AasxCore.Samm2_2_0/SammClasses.cs index 49fa866f..6091173e 100644 --- a/src/AasxCore.Samm2_2_0/SammClasses.cs +++ b/src/AasxCore.Samm2_2_0/SammClasses.cs @@ -595,7 +595,7 @@ public class Characteristic : ModelElement, ISammSelfDescription, ISammStructure public string GetSelfName() => "samm-characteristic"; // public string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#Characteristic"; // FIX: seems to use bamm: instead of bamm-c: !! - public string GetSelfUrn() => "urn:bamm:io.openmanufacturing:meta-model:1.0.0#Characteristic"; + public string GetSelfUrn() => "bamm:Characteristic"; // structure model public bool IsTopElement() => false; @@ -630,7 +630,7 @@ public class Trait : Characteristic, ISammSelfDescription { // self description public new string GetSelfName() => "samm-trait"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#Trait"; + public new string GetSelfUrn() => "bamm-c:Trait"; /// /// The Characterstic that is being constrained. @@ -644,7 +644,7 @@ public class Trait : Characteristic, ISammSelfDescription /// to add multiple Constraints to the base Characteristic. /// [SammPropertyUri("bamm-c:constraint")] - public List? Constraint { get; set; } + public List? Constraint { get; set; } } /// @@ -657,7 +657,7 @@ public class Quantifiable : Characteristic, ISammSelfDescription { // self description public new string GetSelfName() => "samm-quantifiable"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#Quantifiable"; + public new string GetSelfUrn() => "bamm-c:Quantifiable"; /// /// Reference to a Unit as defined in the Unit catalog @@ -675,7 +675,7 @@ public class Measurement : Characteristic, ISammSelfDescription { // self description public new string GetSelfName() => "samm-measurement"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#Measurement"; + public new string GetSelfUrn() => "bamm-c:Measurement"; /// /// Reference to a Unit as defined in the Unit catalog @@ -698,7 +698,7 @@ public class Enumeration : Characteristic, ISammSelfDescription { // self description public new string GetSelfName() => "samm-enumeration"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#Enumeration"; + public new string GetSelfUrn() => "bamm-c:Enumeration"; /// /// List of possible values. The dataType of each of the values must match the @@ -722,7 +722,7 @@ public class State : Enumeration, ISammSelfDescription { // self description public new string GetSelfName() => "samm-state"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#State"; + public new string GetSelfUrn() => "bamm-c:State"; /// /// The default value for the state. @@ -745,7 +745,7 @@ public class Duration : Characteristic, ISammSelfDescription { // self description public new string GetSelfName() => "samm-duration"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#Duration"; + public new string GetSelfUrn() => "bamm-c:Duration"; /// /// Reference to a Unit as defined in the Unit catalog. The referenced unit or its referenceUnit @@ -776,7 +776,7 @@ public class Collection : Characteristic, ISammSelfDescription { // self description public new string GetSelfName() => "samm-collection"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#Collection"; + public new string GetSelfUrn() => "bamm-c:Collection"; /// /// Reference to a Characteristic which describes the individual elements contained in the Collection. @@ -799,7 +799,7 @@ public class List : Collection, ISammSelfDescription { // self description public new string GetSelfName() => "samm-list"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#List"; + public new string GetSelfUrn() => "bamm-c:List"; } /// @@ -811,7 +811,7 @@ public class Set : Collection, ISammSelfDescription { // self description public new string GetSelfName() => "samm-set"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#Set"; + public new string GetSelfUrn() => "bamm-c:Set"; } /// @@ -823,7 +823,7 @@ public class SortedSet : Collection, ISammSelfDescription { // self description public new string GetSelfName() => "samm-sorted-set"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#SortedSet"; + public new string GetSelfUrn() => "bamm-c:SortedSet"; } /// @@ -835,7 +835,7 @@ public class TimeSeries : SortedSet, ISammSelfDescription { // self description public new string GetSelfName() => "samm-time-series"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#TimeSeries"; + public new string GetSelfUrn() => "bamm-c:TimeSeries"; // For DataType // Set to samm-e:TimeSeriesEntity. This Entity consists of two Properties, namely samm-e:timestamp @@ -856,7 +856,7 @@ public class Code : Characteristic, ISammSelfDescription { // self description public new string GetSelfName() => "samm-code"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#Code"; + public new string GetSelfUrn() => "bamm-c:Code"; } /// @@ -870,7 +870,7 @@ public class Either : Characteristic, ISammSelfDescription { // self description public new string GetSelfName() => "samm-either"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#Either"; + public new string GetSelfUrn() => "bamm-c:Either"; /// /// The left side of the Either. The attribute references another Characteristic which describes the value. @@ -901,7 +901,7 @@ public class SingleEntity : Characteristic, ISammSelfDescription { // self description public new string GetSelfName() => "samm-single-entity"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#SingleEntity"; + public new string GetSelfUrn() => "bamm-c:SingleEntity"; } /// @@ -916,7 +916,7 @@ public class StructuredValue: Characteristic, ISammSelfDescription { // self description public new string GetSelfName() => "samm-structured-value"; - public new string GetSelfUrn() => "urn:bamm:io.openmanufacturing:characteristic:1.0.0#StructuredValue"; + public new string GetSelfUrn() => "bamm-c:StructuredValue"; /// /// The regular expression used to deconstruct the value into parts that are mapped to separate @@ -950,7 +950,7 @@ public class Property : ModelElement, ISammSelfDescription, ISammStructureModel { // self description public string GetSelfName() => "samm-property"; - public string GetSelfUrn() => "urn:bamm:io.openmanufacturing:meta-model:1.0.0#Property"; + public string GetSelfUrn() => "bamm:Property"; // structure model public bool IsTopElement() => false; @@ -988,7 +988,7 @@ public class Entity : ModelElement, ISammSelfDescription, ISammStructureModel { // self description public string GetSelfName() => "samm-entity"; - public string GetSelfUrn() => "urn:bamm:io.openmanufacturing:meta-model:1.0.0#Entity"; + public string GetSelfUrn() => "bamm:Entity"; // structure model public bool IsTopElement() => false; @@ -1018,7 +1018,7 @@ public class Aspect : ModelElement, ISammSelfDescription, ISammStructureModel { // self description public string GetSelfName() => "samm-aspect"; - public string GetSelfUrn() => "urn:bamm:io.openmanufacturing:meta-model:1.0.0#Aspect"; + public string GetSelfUrn() => "bamm:Aspect"; // structure model public bool IsTopElement() => true; @@ -1066,7 +1066,7 @@ public class Unit : ModelElement, ISammSelfDescription { // self description public string GetSelfName() => "samm-unit"; - public string GetSelfUrn() => "urn:bamm:io.openmanufacturing:meta-model:1.0.0#Unit"; + public string GetSelfUrn() => "bamm:Unit"; /// /// Normalized short code for unit; please refer to the original @@ -1435,8 +1435,13 @@ static Util() if (Activator.CreateInstance(st, new object[] { }) is ISammSelfDescription ssd) { // assumption: RDF matching is case sensitive?! - SammUrnToType.Add(ssd.GetSelfUrn(), st); - SammTypeToName.Add(st, "" + ssd.GetSelfName()); + var fullUri = Constants.SelfNamespaces.ExtendUri(ssd.GetSelfUrn()); + + if (fullUri != null) + { + SammUrnToType.Add(fullUri, st); + SammTypeToName.Add(st, "" + ssd.GetSelfName()); + } } } } diff --git a/src/AasxPackageExplorer/debug.MIHO.script b/src/AasxPackageExplorer/debug.MIHO.script index f7f53a96..1afc3eb2 100644 --- a/src/AasxPackageExplorer/debug.MIHO.script +++ b/src/AasxPackageExplorer/debug.MIHO.script @@ -6,4 +6,4 @@ // Select("Submodel", "Next"); // Tool("exportsmtasciidoc", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\new.zip", "ExportHtml", "true"); // Tool("Exit"); -Tool("sammaspectimport", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\BatteryPass-spiel.ttl"); \ No newline at end of file +Tool("sammaspectimport", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\BatteryPass-spiel-short.ttl"); \ No newline at end of file diff --git a/src/AasxPackageLogic/DispEditHelperModules.cs b/src/AasxPackageLogic/DispEditHelperModules.cs index f807aade..e57e80b7 100644 --- a/src/AasxPackageLogic/DispEditHelperModules.cs +++ b/src/AasxPackageLogic/DispEditHelperModules.cs @@ -2565,8 +2565,10 @@ public AnyUiLambdaActionBase SammExtensionHelperSammReferenceAction( var newSammExt = new Aas.Extension( name: "" + newSammSsd?.GetSelfName(), semanticId: new Aas.Reference(ReferenceTypes.ExternalReference, - (new[] { new Aas.Key(KeyTypes.GlobalReference, - newSammSsd.GetSelfUrn()) }) + (new[] { + new Aas.Key(KeyTypes.GlobalReference, + "" + Samm.Constants.SelfNamespaces.ExtendUri(newSammSsd.GetSelfUrn())) + }) .Cast().ToList()), value: ""); newCD.Extensions = new List { newSammExt }; @@ -2958,9 +2960,11 @@ public void DisplayOrEditEntitySammExtensions( new Aas.Extension( name: ssd.GetSelfName(), semanticId: new Aas.Reference(ReferenceTypes.ExternalReference, - (new[] { new Aas.Key(KeyTypes.GlobalReference, - ssd.GetSelfUrn()) }) - .Cast().ToList()), + (new[] { + new Aas.Key(KeyTypes.GlobalReference, + "" + Samm.Constants.SelfNamespaces.ExtendUri(ssd.GetSelfUrn())) + }) + .Cast().ToList()), value: "")); } @@ -3370,50 +3374,60 @@ public static List ImportSammModelParseRdfCollection( var lsr = new List(); INode collPtr = collectionStart; - while (collPtr != null && collPtr.NodeType == NodeType.Blank) - { - // the collection pointer needs to have a first relationship - var firstRel = g.GetTriplesWithSubjectPredicate( - subj: collPtr, - pred: new UriNode(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first"))) - .FirstOrDefault(); - if (firstRel?.Object == null) - break; - - // investigate, if first.object is a automatic/composite or an end node - if (firstRel.Object.NodeType == NodeType.Uri - || firstRel.Object.NodeType == NodeType.Literal) - { - // first.object is something tangible - lsr.Add(createInstance?.Invoke(firstRel.Object.ToSafeString(), false)); - } - else - { - // crawl firstRel.Object further to get individual end notes - string propElem = null; - bool? optional = null; - foreach (var x3 in g.GetTriplesWithSubject(firstRel.Object)) - { - if (x3.Predicate.Equals(new UriNode( - new Uri("urn:bamm:io.openmanufacturing:meta-model:1.0.0#property")))) - propElem = x3.Object.ToSafeString(); - if (x3.Predicate.Equals( - new UriNode(new Uri("urn:bamm:io.openmanufacturing:meta-model:1.0.0#optional")))) - optional = x3.Object.ToSafeString() == "true^^http://www.w3.org/2001/XMLSchema#boolean"; - } + 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)); + } + else + { + // a chain of instances is given + while (collPtr != null && collPtr.NodeType == NodeType.Blank) + { + // the collection pointer needs to have a first relationship + var firstRel = g.GetTriplesWithSubjectPredicate( + subj: collPtr, + pred: new UriNode(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first"))) + .FirstOrDefault(); + if (firstRel?.Object == null) + break; + + // investigate, if first.object is a automatic/composite or an end node + if (firstRel.Object.NodeType == NodeType.Uri + || firstRel.Object.NodeType == NodeType.Literal) + { + // first.object is something tangible + lsr.Add(createInstance?.Invoke(firstRel.Object.ToSafeString(), false)); + } + else + { + // crawl firstRel.Object further to get individual end notes + string propElem = null; + bool? optional = null; - if (propElem != null) - lsr.Add(createInstance?.Invoke(propElem, optional.Value)); - } + foreach (var x3 in g.GetTriplesWithSubject(firstRel.Object)) + { + if (x3.Predicate.Equals(new UriNode( + new Uri("urn:bamm:io.openmanufacturing:meta-model:1.0.0#property")))) + propElem = x3.Object.ToSafeString(); + if (x3.Predicate.Equals( + new UriNode(new Uri("urn:bamm:io.openmanufacturing:meta-model:1.0.0#optional")))) + optional = x3.Object.ToSafeString() == "true^^http://www.w3.org/2001/XMLSchema#boolean"; + } - // iterate further - var restRel = g.GetTriplesWithSubjectPredicate( - subj: collPtr, - pred: new UriNode(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"))) - .FirstOrDefault(); - collPtr = restRel?.Object; - } + if (propElem != null) + lsr.Add(createInstance?.Invoke(propElem, optional.Value)); + } + + // iterate further + var restRel = g.GetTriplesWithSubjectPredicate( + subj: collPtr, + pred: new UriNode(new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"))) + .FirstOrDefault(); + collPtr = restRel?.Object; + } + } return lsr; } @@ -3640,16 +3654,18 @@ public static void ImportSammModelToConceptDescriptions( var newCD = new Aas.ConceptDescription( id: newId, idShort: newIdShort, - description: cdDesc.Cast().ToList()); + description: cdDesc?.Cast().ToList()); // create new SAMM element var newSammSsd = sammInst as Samm.ISammSelfDescription; var newSammExt = new Aas.Extension( name: "" + newSammSsd?.GetSelfName(), semanticId: new Aas.Reference(ReferenceTypes.ExternalReference, - (new[] { new Aas.Key(KeyTypes.GlobalReference, - newSammSsd.GetSelfUrn()) }) - .Cast().ToList()), + (new[] { + new Aas.Key(KeyTypes.GlobalReference, + "" + Samm.Constants.SelfNamespaces.ExtendUri(newSammSsd.GetSelfUrn())) + }) + .Cast().ToList()), value: ""); newCD.Extensions = new List { newSammExt };