Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
* temporary stage
Browse files Browse the repository at this point in the history
  • Loading branch information
festo-i40 committed Nov 2, 2023
1 parent e8081a0 commit d25e68f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/AasxCore.Samm2_2_0/SammClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
63 changes: 55 additions & 8 deletions src/AasxPackageLogic/DispEditHelperModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3533,7 +3533,7 @@ public static List<T> ImportSammModelParseRdfCollection<T>(
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
{
Expand Down Expand Up @@ -3589,16 +3589,37 @@ public static List<T> ImportSammModelParseRdfCollection<T>(

public static class RdfHelper
{
public static string GetLiteralStrValue(INode node)
/// <summary>
/// Dirty. Used for the generation of names of nodes for anonymouse node instances
/// of the parsed graph.
/// </summary>
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 "";
if (node is LiteralNode ln)
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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<Samm.LangString>)))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d25e68f

Please sign in to comment.