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

Commit

Permalink
* SAMM import extended
Browse files Browse the repository at this point in the history
* SAMM export to Turtle
   works initally
  • Loading branch information
festo-i40 committed Nov 5, 2023
1 parent d25e68f commit c9a7ad4
Show file tree
Hide file tree
Showing 12 changed files with 2,513 additions and 1,556 deletions.
126 changes: 123 additions & 3 deletions src/AasxCore.Samm2_2_0/SammClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public LangString(string language, string text)
Language = language;
Text = text;
}

public LangString(Aas.ILangStringTextType ls)
{
Language = ls.Language;
Text = ls.Text;
}
}

/// <summary>
Expand Down Expand Up @@ -81,8 +87,7 @@ public SammMultiLineAttribute(int maxLines = -1)
}

/// <summary>
/// This attribute gives a list of given presets to an field or property.
/// in order to avoid cycles
/// This attribute identifies the uri of a single property within a class.
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = true)]
public class SammPropertyUriAttribute : System.Attribute
Expand All @@ -95,6 +100,21 @@ public SammPropertyUriAttribute(string uri)
}
}

/// <summary>
/// If a RDF collection is parsed, this attribute identifies the uri of
/// the relationship pointing to the content node.
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = true)]
public class SammCollectionContentUriAttribute : System.Attribute
{
public string Uri = "";

public SammCollectionContentUriAttribute(string uri)
{
Uri = uri;
}
}

/// <summary>
/// Some string based flags to attach to the property
/// </summary>
Expand All @@ -109,6 +129,20 @@ public SammPropertyFlagsAttribute(string flags)
}
}

/// <summary>
/// Enum string representation need a namespace prefix to be serialized to Turtle
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = true)]
public class SammPropertyPrefixAttribute : System.Attribute
{
public string Prefix = "";

public SammPropertyPrefixAttribute(string prefix)
{
Prefix = prefix;
}
}

/// <summary>
/// Shall be implemented by all non-abstract model elements
/// </summary>
Expand Down Expand Up @@ -176,6 +210,7 @@ public class ModelElement
/// The datatype is xsd:anyURI. This attribute may be defined multiple times.
/// </summary>
[SammPropertyUri("bamm:see")]
[SammPropertyFlags("anyuri")]
public List<string>? See { get; set; } = null;
}

Expand Down Expand Up @@ -437,11 +472,31 @@ public bool AddOrIgnore(string prefix, string uri)
if (p < 0)
return input;
var ask = input.Substring(0, p) + ':';
if (!Map.ContainsKey(ask) || (p+1) >= input.Length)
if (!Map.ContainsKey(ask) || (p+1) > input.Length)
return input;
var res = Map[ask].Uri + input.Substring(p + 1);
return res;
}

public string? PrefixUri(string input)
{
// access
if (input == null)
return null;

// tedious searching
foreach (var mi in Map.Values)
if (input.StartsWith(mi.Uri))
{
var pf = mi.Prefix;
if (pf == ":")
pf = "this:";
return pf + input.Substring(mi.Uri.Length);
}

// not found .. give whole back
return input;
}
}

/// <summary>
Expand Down Expand Up @@ -521,13 +576,15 @@ public class RangeConstraint : Constraint, ISammSelfDescription
/// <c>AT_MOST</c> and <c>LESS_THAN</c>.
/// </summary>
[SammPropertyUri("bamm-c:upperBoundDefinition")]
[SammPropertyPrefix("bamm-c:")]
public SammUpperBoundDefinition? UpperBoundDefinition { get; set; }

/// <summary>
/// Defines whether the lower bound of a range is inclusive or exclusive. Possible values are
/// <c>AT_LEAST</c> and <c>GREATER_THAN</c>.
/// </summary>
[SammPropertyUri("bamm-c:lowerBoundDefinition")]
[SammPropertyPrefix("bamm-c:")]
public SammLowerBoundDefinition? LowerBoundDefinition { get; set; }
}

Expand All @@ -547,6 +604,7 @@ public class EncodingConstraint : Constraint, ISammSelfDescription
/// <c>US-ASCII</c>, <c>ISO-8859-1</c>, <c>UTF-8</c>, <c>UTF-16</c>, <c>UTF-16BE</c> or <c>UTF-16LE</c>.
/// </summary>
[SammPropertyUri("bamm-c:value")]
[SammPropertyPrefix("bamm-c:")]
public SammEncoding? Value { get; set; }
}

Expand Down Expand Up @@ -1056,6 +1114,7 @@ public IEnumerable<SammReference> DescendOnce()

// own
[SammPropertyUri("bamm:properties")]
[SammCollectionContentUri("bamm:property")]
public List<SammReference> Properties { get; set; }

public Entity()
Expand Down Expand Up @@ -1102,18 +1161,21 @@ public IEnumerable<SammReference> DescendOnce()
/// multiple times in a model ([0..n]).
/// </summary>
[SammPropertyUri("bamm:properties")]
[SammCollectionContentUri("bamm:property")]
public List<OptionalSammReference> Properties { get; set; } = new List<OptionalSammReference>();

/// <summary>
/// An Event is a model element that represents a single occurence where the timing is important.
/// </summary>
[SammPropertyUri("bamm:events")]
[SammCollectionContentUri("bamm:event")]
public List<SammReference> Events { get; set; } = new List<SammReference>();

/// <summary>
/// An Operation represents an action that can be triggered on the Aspect.
/// </summary>
[SammPropertyUri("bamm:operations")]
[SammCollectionContentUri("bamm:operation")]
public List<SammReference> Operations { get; set; } = new List<SammReference>();
}

Expand Down Expand Up @@ -1171,8 +1233,66 @@ public static class Constants
{
public static string NamespaceURN = "urn:samm:org.eclipse.esmf.samm:";

/// <summary>
/// XSD uri for "a"
/// </summary>
public static string PredicateA = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";

/// <summary>
/// XSD datatype of uint
/// </summary>
public static string XsdNonNegInt = "http://www.w3.org/2001/XMLSchema#nonNegativeInteger";

/// <summary>
/// XSD datatype of bool
/// </summary>
public static string XsdBoolean = "http://www.w3.org/2001/XMLSchema#boolean";

/// <summary>
/// XSD datatype of string
/// </summary>
public static string XsdString = "http://www.w3.org/2001/XMLSchema#string";

/// <summary>
/// Accordng to standard of RDF collection, the first element relationship
/// </summary>
public static string RdfCollFirst = "http://www.w3.org/1999/02/22-rdf-syntax-ns#first";

/// <summary>
/// Accordng to standard of RDF collection, the res element relationship
/// </summary>
public static string RdfCollRest = "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest";

/// <summary>
/// Accordng to standard of RDF collection, the end element
/// </summary>
public static string RdfCollNil = "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil";

/// <summary>
/// In RDF collections of SAMM references, the pointer to the content itself
/// </summary>
public static string RdfCollProperty = "urn:bamm:io.openmanufacturing:meta-model:1.0.0#property";

/// <summary>
/// In RDF collections of SAMM references, the optional flag
/// </summary>
public static string RdfCollOptional = "urn:bamm:io.openmanufacturing:meta-model:1.0.0#optional";

/// <summary>
/// The head to be used for auto generated instances
/// </summary>
public static string DefaultInstanceURN = "https://admin-shell.io/samm-import#";

/// <summary>
/// Holds attribute URI name with prefix for the description attribute of a SAMM element.
/// </summary>
public static string SammDescription = "bamm:description";

/// <summary>
/// Holds attribute URI name with prefix for the name attribute of a SAMM element.
/// </summary>
public static string SammName = "bamm:name";

public static Type[] AddableCharacteristic =
{
typeof(Trait),
Expand Down
Loading

0 comments on commit c9a7ad4

Please sign in to comment.