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

Commit

Permalink
* more SAMM details
Browse files Browse the repository at this point in the history
* editing
* import TTL
  • Loading branch information
festo-i40 committed Oct 31, 2023
1 parent 977c780 commit 9864ff0
Show file tree
Hide file tree
Showing 9 changed files with 1,109 additions and 297 deletions.
280 changes: 270 additions & 10 deletions src/AasxCore.Samm2_2_0/SammClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ This source code may use other Open Source software components (see LICENSE.txt)
using Newtonsoft.Json;
using Aas = AasCore.Aas3_0;

// Note: Nice regex for searching prefix in .ttl files:
// @prefix\s+([^:]*)\:\s+<([^>]+)>.

namespace AasCore.Samm2_2_0
{

Expand All @@ -35,6 +38,61 @@ public class LangString
/// Text in this language.
/// </summary>
public string? Text { get; set; }

public LangString() { }

public LangString(string language, string text)
{
Language = language;
Text = text;
}
}

/// <summary>
/// This attribute gives a list of given presets to an field or property.
/// in order to avoid cycles
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = true)]
public class SammPresetListAttribute : System.Attribute
{
public string PresetListName = "";

public SammPresetListAttribute(string presetListName)
{
if (presetListName != null)
PresetListName = presetListName;
}
}

/// <summary>
/// This attribute marks a string field/ property as multiline.
/// in order to avoid cycles
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property)]
public class SammMultiLineAttribute : System.Attribute
{
public int? MaxLines = null;

public SammMultiLineAttribute(int maxLines = -1)
{
if (maxLines > 0)
MaxLines = maxLines;
}
}

/// <summary>
/// This attribute gives a list of given presets to an field or property.
/// in order to avoid cycles
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = true)]
public class SammPropertyUriAttribute : System.Attribute
{
public string Uri = "";

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

/// <summary>
Expand Down Expand Up @@ -87,20 +145,24 @@ public class ModelElement
/// times for different languages but only once for a specific language. There should
/// be at least one preferredName defined with an "en" language tag.
/// </summary>
public List<LangString>? PreferredName = null;

/// <summary>
/// Human readable description in a specific language. This attribute may be defined multiple
/// times for different languages but only once for a specific language. There should be at
/// least one description defined with an "en" language tag.
/// </summary>
public List<LangString>? Description = null;
[SammPropertyUri("bamm:preferredName")]
public List<LangString>? PreferredName { get; set; } = null;

// Note: Description is already in the Referable
///// <summary>
///// Human readable description in a specific language. This attribute may be defined multiple
///// times for different languages but only once for a specific language. There should be at
///// least one description defined with an "en" language tag.
///// </summary>
//[SammPropertyUri("bamm:description")]
//public List<LangString>? Description { get; set; } = null;

/// <summary>
/// A reference to a related element in an external taxonomy, ontology or other standards document.
/// The datatype is xsd:anyURI. This attribute may be defined multiple times.
/// </summary>
public List<string>? See = null;
[SammPropertyUri("bamm:see")]
public List<string>? See { get; set; } = null;
}

/// <summary>
Expand Down Expand Up @@ -268,6 +330,89 @@ public SammReference(string val = "")
}
}

/// <summary>
/// Single item for <c>NamespaceMap</c>.
/// </summary>
public class NamespaceMapItem
{
/// <summary>
/// Prefix of a namespace.
/// Format: short sequence of chars. ALWAYS trailing colon (:).
/// </summary>
public string Prefix { get; set; } = "";

/// <summary>
/// Absolute URI to replace a prefix.
/// </summary>
public string Uri { get; set; } = "";

public NamespaceMapItem() { }
public NamespaceMapItem(string prefix, string uri)
{
Prefix = prefix;
Uri = uri;
}
}

/// <summary>
/// This (proprietary) map links prefixes and uris together.
/// Intended use case is to be embedded into the SAMM aspect
/// and help resolving complete URIs.
/// </summary>
public class NamespaceMap
{
/// <summary>
/// Container of map items.
/// </summary>
[JsonIgnore]
public Dictionary<string, NamespaceMapItem> Map { get; set; } =
new Dictionary<string, NamespaceMapItem>();

// For JSON
public NamespaceMapItem[] Items
{
get => Map.Keys.Select(k => Map[k]).ToArray();
set {
Map.Clear();
foreach (var v in value)
AddOrIgnore(v.Prefix, v.Uri);
}
}

public int Count() => Map.Count();

public NamespaceMapItem this[int index] => Map[Map.Keys.ElementAt(index)];

public void RemoveAt(int index) => Map.Remove(Map.Keys.ElementAt(index));

public bool AddOrIgnore(string prefix, string uri)
{
if (prefix == null || uri == null)
return false;
prefix = prefix.Trim();
if (!prefix.EndsWith(':'))
return false;
if (Map.ContainsKey(prefix))
return false;
Map[prefix] = new NamespaceMapItem(prefix, uri);
return true;
}

public string? ExtendUri(string input)
{
if (input == null)
return null;
var p = input.IndexOf(':');
if (p < 0)
return input;
var ask = input.Substring(0, p) + ':';
if (!Map.ContainsKey(ask) || (p+1) >= input.Length)
return input;
var res = Map[ask].Uri + input.Substring(p + 1);
return res;
}
}

/// <summary>
/// Base class for other constraints that constrain a Characteristic in some way, e.g., the Range Constraint
/// limits the value range for a Property.
Expand Down Expand Up @@ -433,6 +578,7 @@ public IEnumerable<SammReference> DescendOnce()
/// Reference to a scalar or complex (Entity) data type. See Section "Type System" in the Aspect Meta Model.
/// Also the scalar data types (e.g. xsd:decimal) are treated as references in the first degree.
/// </summary>
[SammPresetList("SammXsdDataTypes")]
public SammReference DataType { get; set; }

public Characteristic()
Expand Down Expand Up @@ -780,6 +926,7 @@ public IEnumerable<SammReference> DescendOnce()
/// <summary>
/// One Property has exactly one Characteristic.
/// </summary>
[SammPresetList("Characteristics")]
public SammReference Characteristic { get; set; }

public Property()
Expand All @@ -788,6 +935,33 @@ public Property()
}
}

/// <summary>
/// As defined in the Meta Model Elements, an Entity has a number of Properties.
/// </summary>
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";

// structure model
public bool IsTopElement() => false;
public IEnumerable<SammReference> DescendOnce()
{
if (Properties != null)
foreach (var x in Properties)
yield return x;
}

// own
public List<SammReference> Properties { get; set; }

public Entity()
{
Properties = new List<SammReference>();
}
}

/// <summary>
/// An Aspect is the root element of each Aspect Model and has a number of Properties, Events, and Operations.
/// This element is mandatory and must appear exactly once per model.
Expand All @@ -809,7 +983,21 @@ public IEnumerable<SammReference> DescendOnce()
}

// own

/// <summary>
/// The namespaces/ prefix definitions of the SAMM models are attached to the Aspect.
/// </summary>
public NamespaceMap Namespaces { get; set; } = new NamespaceMap();

/// <summary>
/// Multiline string with comments (for the whole SAMM file).
/// </summary>
[SammMultiLine(maxLines: 5)]
public string Comments { get; set; } = "";

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

public List<SammReference> Events { get; set; }
public List<SammReference> Operations { get; set; }

Expand Down Expand Up @@ -852,6 +1040,7 @@ public static class Constants
// Top level
typeof(Aspect),
typeof(Property),
typeof(Entity),
// Characteristic
typeof(Characteristic),
typeof(Trait),
Expand Down Expand Up @@ -892,6 +1081,8 @@ public class SammElementRenderInfo
return null;
}

public static NamespaceMap SelfNamespaces = new NamespaceMap();

static Constants()
{
_renderInfo.Add(typeof(Aspect), new SammElementRenderInfo() {
Expand All @@ -917,7 +1108,7 @@ static Constants()
Background = 0xFFD6E2A6
});

_renderInfo.Add(typeof(IEntity), new SammElementRenderInfo()
_renderInfo.Add(typeof(Entity), new SammElementRenderInfo()
{
DisplayName = "Entity",
Abbreviation = "E",
Expand Down Expand Up @@ -964,9 +1155,78 @@ static Constants()
Foreground = 0xFF000000,
Background = 0xFFB9D8FA
});

// init namespaces, as being used by self / reflection information
SelfNamespaces = new NamespaceMap();
SelfNamespaces.AddOrIgnore("bamm:", "urn:bamm:io.openmanufacturing:meta-model:1.0.0#");
SelfNamespaces.AddOrIgnore("bamm-c:", "urn:bamm:io.openmanufacturing:characteristic:1.0.0#");
SelfNamespaces.AddOrIgnore("bamm-e:", "urn:bamm:io.openmanufacturing:entity:1.0.0#");
SelfNamespaces.AddOrIgnore("unit:", "urn:bamm:io.openmanufacturing:unit:1.0.0#");
SelfNamespaces.AddOrIgnore("rdf:", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
SelfNamespaces.AddOrIgnore("rdfs:", "http://www.w3.org/2000/01/rdf-schema#");
SelfNamespaces.AddOrIgnore("xsd:", "http://www.w3.org/2001/XMLSchema#");
}

public static uint RenderBackground = 0xFFEFEFF0;

public static readonly string[] SammXsdDataTypes =
{
"xsd:anyURI",
"xsd:base64Binary",
"xsd:boolean",
"xsd:byte",
"xsd:date",
"xsd:dateTime",
"xsd:decimal",
"xsd:double",
"xsd:duration",
"xsd:float",
"xsd:gDay",
"xsd:gMonth",
"xsd:gMonthDay",
"xsd:gYear",
"xsd:gYearMonth",
"xsd:hexBinary",
"xsd:int",
"xsd:integer",
"xsd:long",
"xsd:negativeInteger",
"xsd:nonNegativeInteger",
"xsd:nonPositiveInteger",
"xsd:positiveInteger",
"xsd:short",
"xsd:string",
"xsd:time",
"xsd:unsignedByte",
"xsd:unsignedInt",
"xsd:unsignedLong",
"xsd:unsignedShort",
"langString"
};

public static readonly string[] CharacteristicsFixTypes =
{
"samm-c:Timestamp",
"samm-c:Text",
"samm-c:Boolean",
"samm-c:Locale",
"samm-c:Language",
"samm-c:UnitReference",
"samm-c:ResourcePath",
"samm-c:MimeType"
};

public static string[]? GetPresetsForListName(string listName)
{
if (listName == null)
return null;
listName = listName.Trim().ToLower();
if (listName == "SammXsdDataTypes".ToLower())
return SammXsdDataTypes;
if (listName == "Characteristics".ToLower())
return CharacteristicsFixTypes;
return null;
}
}

public static class Util
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This source code may use other Open Source software components (see LICENSE.txt)
using System;
using System.Collections.Generic;
using System.Linq;

namespace Extensions
{
public static class ExtendILangStringNameType
Expand Down
3 changes: 2 additions & 1 deletion src/AasxPackageExplorer/debug.MIHO.script
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
// Select("Submodel", "First");
// Select("Submodel", "Next");
// Tool("exportsmtasciidoc", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\new.zip", "ExportHtml", "true");
// Tool("Exit");
// Tool("Exit");
Tool("sammaspectimport", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\BatteryPass-spiel-short.ttl");
1 change: 1 addition & 0 deletions src/AasxPackageLogic/AasxPackageLogic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="dotNetRdf" Version="3.1.1" />
<PackageReference Include="IdentityModel" Version="6.0.0" />
<PackageReference Include="jose-jwt" Version="4.0.1" />
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
Expand Down
Loading

0 comments on commit 9864ff0

Please sign in to comment.