Skip to content
Snippets Groups Projects
Commit 180f463f authored by MaZiFAU's avatar MaZiFAU
Browse files

Fixed List/Tupel; Using new SOMDoc Types;

parent eebb35ae
No related branches found
No related tags found
No related merge requests found
Showing
with 3532 additions and 3436 deletions
...@@ -253,26 +253,23 @@ public static void GenerateCanonBallStage() ...@@ -253,26 +253,23 @@ public static void GenerateCanonBallStage()
// Set Solution // Set Solution
#region CannonBallScroll #region CannonBallScroll
StageStatic.stage.solution.Add( // for CannonBallScroll StageStatic.stage.solution.Add( // for CannonBallScroll
new ListFact(Walls.Select(w => w.Topology.Id).ToArray(), typeof(LineFact), StageStatic.stage.solution), new ListFact(Walls.Select(w => w.Topology.Id).ToArray(), null, new OMS(MMT_OMS_URI.TYPE_TO_OMS[typeof(LineFact)]), StageStatic.stage.solution),
out bool _, true, null, null out bool _, true, null, null
); );
// special case for Prototype // special case for Prototype
string[] RRRRTupel = new string[Walls.Count]; SOMDoc[] RRRRTupel = new SOMDoc[Walls.Count];
for (int i = 0; i < Walls.Count; i++) for (int i = 0; i < Walls.Count; i++)
{ {
RRRRTupel[i] = StageStatic.stage.solution.Add( RRRRTupel[i] =
new TupelFact(null, SOMDoc.MakeTupel(
new[] { new[] {
SOMDoc.MakeTupel(new OMF[] { new(Walls[i].Topology.Point1.Point[dim_A]), new(Walls[i].Topology.Point1.Point[dim_B]) }), SOMDoc.MakeTupel(new OMF[] { new(Walls[i].Topology.Point1.Point[dim_A]), new(Walls[i].Topology.Point1.Point[dim_B]) }),
SOMDoc.MakeTupel(new OMF[] { new(Walls[i].Topology.Point2.Point[dim_A]), new(Walls[i].Topology.Point2.Point[dim_B]) }), SOMDoc.MakeTupel(new OMF[] { new(Walls[i].Topology.Point2.Point[dim_A]), new(Walls[i].Topology.Point2.Point[dim_B]) }),
}, });
StageStatic.stage.solution),
out bool _, true, null, null
);
} }
StageStatic.stage.solution.Add( StageStatic.stage.solution.Add(
new ListFact(RRRRTupel, typeof(TupelFact), StageStatic.stage.solution), new ListFact(null, RRRRTupel, null, StageStatic.stage.solution),
out bool _, true, null, null out bool _, true, null, null
); );
#endregion CannonBallScroll #endregion CannonBallScroll
...@@ -282,6 +279,11 @@ public static void GenerateCanonBallStage() ...@@ -282,6 +279,11 @@ public static void GenerateCanonBallStage()
out _, false, null, null); out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(BallURI); StageStatic.stage.solution.ExposedSolutionFacts.Add(BallURI);
string VecURI = StageStatic.stage.solution.Add(
new PointFact(StartVec, StartVec.normalized, StageStatic.stage.solution),
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(VecURI);
CanonBallProblemCalculator calc = new(Walls, StartPos, StartVec, Gravity, dim_const, dim_A, dim_B, StageStatic.stage.solution); CanonBallProblemCalculator calc = new(Walls, StartPos, StartVec, Gravity, dim_const, dim_A, dim_B, StageStatic.stage.solution);
string attacheFactURI = StageStatic.stage.solution.Add( string attacheFactURI = StageStatic.stage.solution.Add(
......
...@@ -71,12 +71,13 @@ private void PostServerConnection() ...@@ -71,12 +71,13 @@ private void PostServerConnection()
IEnumerator getScrollsfromServer() IEnumerator getScrollsfromServer()
{ {
//Try /scroll/listAll endpoint when scroll/list is not working //Try /scroll/listall endpoint when scroll/list is not working
UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/list"); //UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/listAll");
//Postman-Echo-Mock //Postman-Echo-Mock
//UnityWebRequest request = UnityWebRequest.Get("https://019a8ea5-843a-498b-8d0c-778669aef987.mock.pstmn.io/get"); //UnityWebRequest request = UnityWebRequest.Get("https://019a8ea5-843a-498b-8d0c-778669aef987.mock.pstmn.io/get");
System.DateTime requestTime = System.DateTime.UtcNow; System.DateTime requestTime = System.DateTime.UtcNow;
UnityWebRequest request = null;
for (int i = 0; i < this.tryScrollListTimes; i++) for (int i = 0; i < this.tryScrollListTimes; i++)
{ {
request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/list"); request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/list");
......
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Collections.Generic; using System.Collections.Generic;
using TMPro;
using UnityEngine; using UnityEngine;
using static SOMDocManager; using static SOMDocManager;
......
...@@ -415,18 +415,20 @@ public static Fact parseFact(MMTDeclaration fact) ...@@ -415,18 +415,20 @@ public static Fact parseFact(MMTDeclaration fact)
} }
} }
protected void SendToMMT()
=> _URI = SendToMMT(MakeMMTDeclaration());
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <remarks>Asynchron version has proofen inefficent, since <see cref="Fact.Id"/> is usually called in close proximity.</remarks> /// <remarks>Asynchron version has proofen inefficent, since <see cref="Fact.Id"/> is usually called in close proximity.</remarks>
// Asynchron version in comments // Asynchron version in comments
public void SendToMMT() public static string SendToMMT(MMTDeclaration mmtDecl)
{ {
MMTDeclaration mmtDecl = MakeMMTDeclaration();
//GlobalBehaviour.Instance.StartCoroutine( //GlobalBehaviour.Instance.StartCoroutine(
// FetchURICoroutine = // FetchURICoroutine =
_URI = //_URI =
string uri =
_SendAdd( _SendAdd(
CommunicationEvents.ServerAdress + "/fact/add", CommunicationEvents.ServerAdress + "/fact/add",
mmtDecl.ToJson() mmtDecl.ToJson()
...@@ -440,11 +442,13 @@ public void SendToMMT() ...@@ -440,11 +442,13 @@ public void SendToMMT()
// _URI = uri; // _URI = uri;
if (mmtDecl is MMTSymbolDeclaration mMTSymbol && mMTSymbol.defines != null) if (mmtDecl is MMTSymbolDeclaration mMTSymbol && mMTSymbol.defines != null)
ParsingDictionary.parseTermsToId[mMTSymbol.defines.ToString()] = _URI; ParsingDictionary.parseTermsToId[mMTSymbol.defines.ToString()] = uri;// _URI;
//} //}
return uri;
/*IEnumerator*/ /*IEnumerator*/
string _SendAdd(string path, string body)//, Action<string> uriCallback) static string _SendAdd(string path, string body)//, Action<string> uriCallback)
{ {
if (!CommunicationEvents.ServerRunning) if (!CommunicationEvents.ServerRunning)
{ {
......
...@@ -15,59 +15,65 @@ public class ListFact : FactWrappedCRTP<ListFact> ...@@ -15,59 +15,65 @@ public class ListFact : FactWrappedCRTP<ListFact>
public SOMDoc[] payload = new SOMDoc[0]; public SOMDoc[] payload = new SOMDoc[0];
public string typeURI; public OMA ListType;
[JsonIgnore]
public Type ListType
{
get => MMT_OMS_URI.OMS_TO_TYPE[typeURI];
private set => typeURI = MMT_OMS_URI.TYPE_TO_OMS[value];
}
public ListFact() : base() { } public ListFact() : base() { }
public ListFact(string[] lids, SOMDoc[] payload, Type ListType, FactOrganizer organizer) : base(organizer) public ListFact(string[] lids, SOMDoc[] payload, SOMDoc ElementType, FactOrganizer organizer) : base(organizer)
{ {
this.ListType = ListType; Init(lids, payload, ElementType);
Init(lids, payload);
SendToMMT(); SendToMMT();
} }
public ListFact(string[] lids, SOMDoc[] payload, string typeURI, string backendURI, FactOrganizer organizer) : base(organizer) public ListFact(string[] lids, SOMDoc[] payload, SOMDoc ElementType, string backendURI, FactOrganizer organizer) : base(organizer)
{ {
this.typeURI = typeURI; Init(lids, payload, ElementType);
Init(lids, payload);
_URI = backendURI; _URI = backendURI;
} }
private void Init(string[] lids, SOMDoc[] payload) private void Init(string[] lids, SOMDoc[] payload, SOMDoc ElementType)
{ {
this.lids = lids ?? new string[0]; this.lids = lids ?? new string[0];
this.payload = new SOMDoc[Unity.Mathematics.math.max(this.lids.Length, payload == null ? 0 : payload.Length)];
payload?.CopyTo(this.payload, 0);
if (!HasDependentFacts) if (!HasDependentFacts)
{ {
if (payload.Any(p => p == null)) if (payload.Any(p => p == null))
throw new ArgumentException(nameof(payload) + "must not include null elements iff " + nameof(lids) + " is all nulls or empty!"); throw new ArgumentException(nameof(payload) + "must not include null elements iff " + nameof(lids) + " is all nulls or empty!");
this.payload = payload;
} }
else else
{ {
this.payload = new SOMDoc[Unity.Mathematics.math.max(lids.Length, payload.Length)]; for (int i = 0; i < this.lids.Length; i++)
if (this.lids[i] != null)
for (int i = 0; i < this.payload.Length; i++) this.payload[i] = new OMS(this.lids[i]);
if (lids[i] != null)
payload[i] = new OMS(lids[i]);
else else
if (lids[i] == null && payload[i] == null) if (this.payload[i] == null)
throw new ArgumentException(nameof(lids) + " and " + nameof(payload) + " have to be complementary not null!"); throw new ArgumentException(nameof(lids) + " and " + nameof(payload) + " have to be complementary not null!");
} }
if (ElementType == null)
{
if (this.payload.Length == 0)
throw new ArgumentException(nameof(ElementType) + " must not be null if ListFact is empty List!");
ElementType = payload[0].TypeOf();
}
this.ListType = new OMA(
new OMS(MMT_OMS_URI.ListType),
new[] { ElementType }
);
} }
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer) protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new ListFact( => new ListFact(
lids.Select(id => id == null ? null : old_to_new[id]).ToArray(), lids.Select(id => id == null ? null : old_to_new[id]).ToArray(),
payload, payload.Select(somdoc => somdoc == null ? null : somdoc.MapURIs(old_to_new)).ToArray(),
ListType, organizer); ListType.arguments[0],
organizer);
public static List<T> parseFactList<T>(MMTDeclaration decl) public static List<T> parseFactList<T>(MMTDeclaration decl)
{ {
...@@ -100,7 +106,7 @@ public static List<T> parseFactList<T>(MMTDeclaration decl) ...@@ -100,7 +106,7 @@ public static List<T> parseFactList<T>(MMTDeclaration decl)
{ {
if (fact is not MMTSymbolDeclaration MMTSymbol if (fact is not MMTSymbolDeclaration MMTSymbol
|| MMTSymbol.type is not OMA listOMA || MMTSymbol.type is not OMA listOMA
|| listOMA.arguments[0] is not OMS typeOMS) || listOMA.arguments[0] is not OMA typeOMA)
{ {
return null; return null;
} }
...@@ -130,14 +136,14 @@ public static List<T> parseFactList<T>(MMTDeclaration decl) ...@@ -130,14 +136,14 @@ public static List<T> parseFactList<T>(MMTDeclaration decl)
return new( return new(
payload.Select(p => (p as OMS)?.uri).ToArray(), payload.Select(p => (p as OMS)?.uri).ToArray(),
payload.ToArray(), payload.ToArray(),
typeOMS.uri, typeOMA.arguments[0],
fact.@ref.uri, StageStatic.stage.factState); fact.@ref.uri, StageStatic.stage.factState);
} }
public override MMTDeclaration MakeMMTDeclaration() public override MMTDeclaration MakeMMTDeclaration()
{ {
OMA List = SOMDoc.MakeList(payload, typeURI); OMA List = SOMDoc.MakeShallowList(payload);
return new MMTSymbolDeclaration(Label, List.applicant, List.arguments[0]); return new MMTSymbolDeclaration(Label, ListType, List);
} }
protected override string[] GetGetDependentFactIds() protected override string[] GetGetDependentFactIds()
...@@ -146,7 +152,7 @@ protected override string[] GetGetDependentFactIds() ...@@ -146,7 +152,7 @@ protected override string[] GetGetDependentFactIds()
protected override void RecalculateTransform() { } protected override void RecalculateTransform() { }
protected override bool EquivalentWrapped(ListFact f1, ListFact f2) protected override bool EquivalentWrapped(ListFact f1, ListFact f2)
=> f1.typeURI == f2.typeURI => f1.ListType.Equivalent(f2.ListType)
&& f1.payload.Length == f2.payload.Length && f1.payload.Length == f2.payload.Length
&& DependentFactsEquivalent(f1, f2) && DependentFactsEquivalent(f1, f2)
&& f1.payload && f1.payload
...@@ -206,7 +212,8 @@ private void Init(string[] lids, SOMDoc[] payload) ...@@ -206,7 +212,8 @@ private void Init(string[] lids, SOMDoc[] payload)
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer) protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new TupelFact( => new TupelFact(
lids.Select(id => id == null ? null : old_to_new[id]).ToArray(), lids.Select(id => id == null ? null : old_to_new[id]).ToArray(),
payload, organizer); payload.Select(somdoc => somdoc == null ? null : somdoc.MapURIs(old_to_new)).ToArray(),
organizer);
public static new TupelFact parseFact(MMTDeclaration fact) public static new TupelFact parseFact(MMTDeclaration fact)
{ {
...@@ -225,8 +232,8 @@ protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, F ...@@ -225,8 +232,8 @@ protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, F
public override MMTDeclaration MakeMMTDeclaration() public override MMTDeclaration MakeMMTDeclaration()
{ {
OMA List = SOMDoc.MakeTupel(payload); OMA Tupel = SOMDoc.MakeTupel(payload);
return new MMTSymbolDeclaration(Label, List.applicant, List); return new MMTSymbolDeclaration(Label, Tupel.TypeOf(), Tupel);
} }
protected override string[] GetGetDependentFactIds() protected override string[] GetGetDependentFactIds()
......
...@@ -144,7 +144,11 @@ private int[] PrePopulateActiveScroll() ...@@ -144,7 +144,11 @@ private int[] PrePopulateActiveScroll()
{ {
case MMT_OMS_URI.ScrollCannonBall: case MMT_OMS_URI.ScrollCannonBall:
string lid_override = StageStatic.stage.solution.MyFactSpace.Values string lid_override = StageStatic.stage.solution.MyFactSpace.Values
.FirstOrDefault(sol => sol is ListFact lf && lf.ListType == typeof(TupelFact)) .FirstOrDefault(sol => sol is ListFact lf
&& lf.ListType is OMA tpOMA
&& tpOMA.arguments[0] is OMA tupelOMA
&& tupelOMA.applicant is OMS tupelOMS
&& tupelOMS.uri == MMT_OMS_URI.Tuple)
?.Id; ?.Id;
if (lid_override == null) if (lid_override == null)
...@@ -264,13 +268,16 @@ private IEnumerator SendView(string endpoint) ...@@ -264,13 +268,16 @@ private IEnumerator SendView(string endpoint)
if (www.result == UnityWebRequest.Result.ConnectionError if (www.result == UnityWebRequest.Result.ConnectionError
|| www.result == UnityWebRequest.Result.ProtocolError) || www.result == UnityWebRequest.Result.ProtocolError)
{ {
Debug.Log(www.error); Debug.LogWarning(www.error);
currentMmtAnswer = null; currentMmtAnswer = null;
} }
else else
{ {
string answer = www.downloadHandler.text; while(!www.downloadHandler.isDone)
currentMmtAnswer = answer; yield return null;
currentMmtAnswer = www.downloadHandler.text
.Replace("\"float\":null", "\"float\":0.0"); // cannot convert null to value type
} }
string prepareScrollAssignments() string prepareScrollAssignments()
...@@ -285,6 +292,37 @@ string prepareScrollAssignments() ...@@ -285,6 +292,37 @@ string prepareScrollAssignments()
} }
return JsonConvert.SerializeObject(new ScrollApplication(ActiveScroll.ScrollReference, assignmentList)); return JsonConvert.SerializeObject(new ScrollApplication(ActiveScroll.ScrollReference, assignmentList));
string lid_override = StageStatic.stage.solution.MyFactSpace.Values
.FirstOrDefault(sol => sol is ListFact lf
&& lf.ListType is OMA tpOMA
&& tpOMA.arguments[0] is OMA tupelOMA
&& tupelOMA.applicant is OMS tupelOMS
&& tupelOMS.uri == MMT_OMS_URI.Product)
?.Id;
return JsonConvert.SerializeObject(new ScrollApplication(
MMT_OMS_URI.ScrollCannonBall,
new() {
new("http://mathhub.info/FrameIT/frameworld?BouncingScroll/Problem?xposition",
Fact.SendToMMT(new MMTSymbolDeclaration("PX", new OMS(MMT_OMS_URI.RealLit),
new OMF(18.639f)))),
new("http://mathhub.info/FrameIT/frameworld?BouncingScroll/Problem?yposition",
Fact.SendToMMT(new MMTSymbolDeclaration("PY", new OMS(MMT_OMS_URI.RealLit),
new OMF(14.715f)))),
new("http://mathhub.info/FrameIT/frameworld?BouncingScroll/Problem?xvelocity",
Fact.SendToMMT(new MMTSymbolDeclaration("VX", new OMS(MMT_OMS_URI.RealLit),
new OMF(-24.0345f)))),
new("http://mathhub.info/FrameIT/frameworld?BouncingScroll/Problem?yvelocity",
Fact.SendToMMT(new MMTSymbolDeclaration("VY", new OMS(MMT_OMS_URI.RealLit),
new OMF(7.3575f)))),
new("http://mathhub.info/FrameIT/frameworld?BouncingScroll/Problem?g_base",
Fact.SendToMMT(new MMTSymbolDeclaration("GG", new OMS(MMT_OMS_URI.RealLit),
new OMF(9.81f)))),
new("http://mathhub.info/FrameIT/frameworld?BouncingScroll/Problem?walls",
lid_override),
}
));
} }
} }
......
using System.IO; using System.IO;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Newtonsoft.Json; using Newtonsoft.Json;
using static CommunicationEvents;
using System; using System;
using UnityEditor.Timeline.Actions; using static CommunicationEvents;
public class Stage : IJSONsavable<Stage> public class Stage : IJSONsavable<Stage>
{ {
......
...@@ -13,7 +13,6 @@ public static class SOMDocManager ...@@ -13,7 +13,6 @@ public static class SOMDocManager
public static class MMT_OMS_URI public static class MMT_OMS_URI
{ {
public static readonly string Point = "http://mathhub.info/MitM/core/geometry?3DGeometry?point"; public static readonly string Point = "http://mathhub.info/MitM/core/geometry?3DGeometry?point";
public static readonly string Tuple = "http://gl.mathhub.info/MMT/LFX/Sigma?Symbols?Tuple";
public static readonly string LineType = "http://mathhub.info/MitM/core/geometry?Geometry/Common?line_type"; public static readonly string LineType = "http://mathhub.info/MitM/core/geometry?Geometry/Common?line_type";
public static readonly string LineOf = "http://mathhub.info/MitM/core/geometry?Geometry/Common?lineOf"; public static readonly string LineOf = "http://mathhub.info/MitM/core/geometry?Geometry/Common?lineOf";
...@@ -58,7 +57,11 @@ public static class MMT_OMS_URI ...@@ -58,7 +57,11 @@ public static class MMT_OMS_URI
public static readonly string TestType = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?xcircleType3D"; public static readonly string TestType = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?xcircleType3D";
public static readonly string Product = "http://gl.mathhub.info/MMT/LFX/Sigma?Symbols?Product";
public static readonly string Tuple = "http://gl.mathhub.info/MMT/LFX/Sigma?Symbols?Tuple";
public static readonly string ListType = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?ListType"; public static readonly string ListType = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?ListType";
public static readonly string ListApplicant = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?list";
public static readonly string ListLiteral = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?cons"; public static readonly string ListLiteral = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?cons";
public static readonly string ListEnd = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?nil_constant"; public static readonly string ListEnd = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?nil_constant";
...@@ -85,9 +88,8 @@ public static class MMT_OMS_URI ...@@ -85,9 +88,8 @@ public static class MMT_OMS_URI
public const string ScrollCircleAreaScroll = "http://mathhub.info/FrameIT/frameworld?CircleAreaScroll"; public const string ScrollCircleAreaScroll = "http://mathhub.info/FrameIT/frameworld?CircleAreaScroll";
public const string ScrollConeVolumeScroll = "http://mathhub.info/FrameIT/frameworld?ConeVolumeScroll"; public const string ScrollConeVolumeScroll = "http://mathhub.info/FrameIT/frameworld?ConeVolumeScroll";
public const string ScrollTruncatedConeVolumeScroll = "http://mathhub.info/FrameIT/frameworld?TruncatedConeVolumeScroll"; public const string ScrollTruncatedConeVolumeScroll = "http://mathhub.info/FrameIT/frameworld?TruncatedConeVolumeScroll";
public const string ScrollCannonBall = "CannonBall"; public const string ScrollCannonBall = "http://mathhub.info/FrameIT/frameworld?BouncingScroll";
public static readonly IReadOnlyDictionary<Type, string> TYPE_TO_OMS;
public static readonly IReadOnlyDictionary<string, Type> OMS_TO_TYPE = new Dictionary<string, Type>() public static readonly IReadOnlyDictionary<string, Type> OMS_TO_TYPE = new Dictionary<string, Type>()
{ {
{ Point, { Point,
...@@ -167,21 +169,29 @@ public static class MMT_OMS_URI ...@@ -167,21 +169,29 @@ public static class MMT_OMS_URI
{ typeof(Vector3).ToString(), { typeof(Vector3).ToString(),
typeof(Vector3) } typeof(Vector3) }
}; };
public static readonly IReadOnlyDictionary<Type, string> TYPE_TO_OMS = OMS_TO_TYPE.ReverseKeyValInto(new()
static MMT_OMS_URI() { // **Overrides**
{
Dictionary<Type, string> _TYPE_TO_OMS = new() {
// **Overrides**
//{ typeof(Vector3), //{ typeof(Vector3),
// Tuple }, // Tuple },
});
public static readonly IReadOnlyDictionary<string, string> URI_TO_TypeOF = new Dictionary<string, string> {
{ MkCircle3d,
CircleType3d },
}; };
public static readonly IReadOnlyDictionary<string, string> TypeOF_TO_URI = URI_TO_TypeOF.ReverseKeyVal();
foreach (KeyValuePair<string, Type> KeyVal in OMS_TO_TYPE) public static readonly IReadOnlyDictionary<string, string> HeterogenApplication_TO_TypeOF = new Dictionary<string, string> {
if (KeyVal.Value != null) { Tuple,
_TYPE_TO_OMS.TryAdd(KeyVal.Value, KeyVal.Key); Product },
};
public static readonly IReadOnlyDictionary<string, string> TypeOF_TO_HeterogenApplication = HeterogenApplication_TO_TypeOF.ReverseKeyVal();
TYPE_TO_OMS = _TYPE_TO_OMS; public static readonly IReadOnlyDictionary<string, string> HomogenApplication_TO_TypeOF = new Dictionary<string, string> {
} { ListApplicant,
ListType },
};
public static readonly IReadOnlyDictionary<string, string> TypeOF_TO_HomogenApplication = HomogenApplication_TO_TypeOF.ReverseKeyVal();
} }
...@@ -472,6 +482,11 @@ abstract public class SOMDoc ...@@ -472,6 +482,11 @@ abstract public class SOMDoc
protected SOMDoc() { kind = this.GetType().Name; } protected SOMDoc() { kind = this.GetType().Name; }
public SOMDoc TypeOf()
=> TypeOf(new SOMDoc[0]);
protected internal abstract SOMDoc TypeOf(SOMDoc[] args);
public static bool Equivalent(SOMDoc sd1, SOMDoc sd2) public static bool Equivalent(SOMDoc sd1, SOMDoc sd2)
=> sd1 == null && sd2 == null => sd1 == null && sd2 == null
|| sd1.Equivalent(sd2); || sd1.Equivalent(sd2);
...@@ -548,16 +563,19 @@ public static OMA MakeTupel(SOMDoc[] args) ...@@ -548,16 +563,19 @@ public static OMA MakeTupel(SOMDoc[] args)
args args
); );
public static OMA MakeList(SOMDoc[] args, Type type) public static OMA MakeShallowList(SOMDoc[] args)
=> MakeList(args, MMT_OMS_URI.TYPE_TO_OMS[type]); => new(
new OMS(MMT_OMS_URI.ListApplicant),
args
);
public static OMA MakeList(SOMDoc[] args, string typeURI) public static OMA MakeDeepList(SOMDoc[] args, SOMDoc typeURI)
{ {
SOMDoc[] end_of_list = new SOMDoc[] { SOMDoc[] end_of_list = new SOMDoc[] {
new OMA( new OMA(
new OMS(MMT_OMS_URI.ListEnd), new OMS(MMT_OMS_URI.ListEnd),
new[] { new[] {
new OMS(typeURI), typeURI,
} }
), ),
args.Length == 0 args.Length == 0
...@@ -584,8 +602,8 @@ public static OMA MakeList(SOMDoc[] args, string typeURI) ...@@ -584,8 +602,8 @@ public static OMA MakeList(SOMDoc[] args, string typeURI)
} }
SOMDoc type = new OMA( SOMDoc type = new OMA(
new OMS(MMT_OMS_URI.ListType), new OMS(MMT_OMS_URI.ListApplicant),
new[] { new OMS(typeURI), } new[] { typeURI }
); );
return new OMA(type, new[] { defines }); return new OMA(type, new[] { defines });
...@@ -605,7 +623,7 @@ public override bool Equivalent(SOMDoc sd2) ...@@ -605,7 +623,7 @@ public override bool Equivalent(SOMDoc sd2)
public override SOMDoc MapURIs(Dictionary<string, string> old_to_new) public override SOMDoc MapURIs(Dictionary<string, string> old_to_new)
=> MapURIsWrapped(old_to_new); => MapURIsWrapped(old_to_new);
public abstract T MapURIsWrapped(Dictionary<string, string> old_to_new); protected abstract T MapURIsWrapped(Dictionary<string, string> old_to_new);
} }
public class OMBINDC : SOMDocCRTP<OMBINDC> public class OMBINDC : SOMDocCRTP<OMBINDC>
...@@ -635,6 +653,9 @@ public OMBINDC(string name, string typeString, SOMDoc lambdabody) : base() ...@@ -635,6 +653,9 @@ public OMBINDC(string name, string typeString, SOMDoc lambdabody) : base()
this.lambdabody = lambdabody; this.lambdabody = lambdabody;
} }
protected internal override SOMDoc TypeOf(SOMDoc[] args)
=> throw new NotImplementedException();
public OMBINDC(string name, Type type, SOMDoc lambdabody) : base() public OMBINDC(string name, Type type, SOMDoc lambdabody) : base()
{ {
this.name = name; this.name = name;
...@@ -659,7 +680,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio ...@@ -659,7 +680,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio
public override string ToString() public override string ToString()
=> "OMBINDC(" + name + ", " + typeString + ")->"; => "OMBINDC(" + name + ", " + typeString + ")->";
public override OMBINDC MapURIsWrapped(Dictionary<string, string> old_to_new) protected override OMBINDC MapURIsWrapped(Dictionary<string, string> old_to_new)
=> new(name, type, lambdabody.MapURIs(old_to_new)); => new(name, type, lambdabody.MapURIs(old_to_new));
} }
...@@ -677,6 +698,9 @@ public OMA(SOMDoc applicant, SOMDoc[] arguments) : base() ...@@ -677,6 +698,9 @@ public OMA(SOMDoc applicant, SOMDoc[] arguments) : base()
this.arguments = arguments; this.arguments = arguments;
} }
protected internal override SOMDoc TypeOf(SOMDoc[] args)
=> applicant.TypeOf(arguments.Select(a => a.TypeOf()).ToArray());
protected override bool EquivalentWrapped(OMA sd2) protected override bool EquivalentWrapped(OMA sd2)
=> Equivalent(this.applicant, sd2.applicant) => Equivalent(this.applicant, sd2.applicant)
&& this.arguments && this.arguments
...@@ -693,7 +717,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio ...@@ -693,7 +717,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio
public override string ToString() public override string ToString()
=> applicant.ToString() + "(" + string.Join(", ", arguments.Select(a => a.ToString())) + ")"; => applicant.ToString() + "(" + string.Join(", ", arguments.Select(a => a.ToString())) + ")";
public override OMA MapURIsWrapped(Dictionary<string, string> old_to_new) protected override OMA MapURIsWrapped(Dictionary<string, string> old_to_new)
=> new OMA( => new OMA(
applicant.MapURIs(old_to_new), applicant.MapURIs(old_to_new),
arguments.Select(arg => arg.MapURIs(old_to_new)).ToArray() arguments.Select(arg => arg.MapURIs(old_to_new)).ToArray()
...@@ -712,6 +736,29 @@ public OMS(string uri) : base() ...@@ -712,6 +736,29 @@ public OMS(string uri) : base()
this.uri = uri; this.uri = uri;
} }
protected internal override SOMDoc TypeOf(SOMDoc[] args)
{
if (FactOrganizer.AllFacts.TryGetValue(uri, out Fact found))
return new OMS(MMT_OMS_URI.TYPE_TO_OMS[found.GetType()]);
if (MMT_OMS_URI.HeterogenApplication_TO_TypeOF.TryGetValue(uri, out string type))
return new OMA(
new OMS(type),
args
);
if (MMT_OMS_URI.HomogenApplication_TO_TypeOF.TryGetValue(uri, out type))
return new OMA(
new OMS(type),
new[] { args[0] }
);
if (MMT_OMS_URI.URI_TO_TypeOF.TryGetValue(uri, out type))
return new OMS(type);
throw new NotImplementedException();
}
protected override bool EquivalentWrapped(OMS sd2) protected override bool EquivalentWrapped(OMS sd2)
=> this.uri == sd2.uri; => this.uri == sd2.uri;
...@@ -721,7 +768,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio ...@@ -721,7 +768,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio
public override string ToString() public override string ToString()
=> uri; => uri;
public override OMS MapURIsWrapped(Dictionary<string, string> old_to_new) protected override OMS MapURIsWrapped(Dictionary<string, string> old_to_new)
{ {
if (!old_to_new.TryGetValue(uri, out string new_uri)) if (!old_to_new.TryGetValue(uri, out string new_uri))
new_uri = uri; new_uri = uri;
...@@ -743,6 +790,9 @@ public OMSTR(string s) : base() ...@@ -743,6 +790,9 @@ public OMSTR(string s) : base()
this.s = s; this.s = s;
} }
protected internal override SOMDoc TypeOf(SOMDoc[] args)
=> throw new NotImplementedException();
protected override bool EquivalentWrapped(OMSTR sd2) protected override bool EquivalentWrapped(OMSTR sd2)
=> this.s == sd2.s; => this.s == sd2.s;
...@@ -752,7 +802,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio ...@@ -752,7 +802,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio
public override string ToString() public override string ToString()
=> s; => s;
public override OMSTR MapURIsWrapped(Dictionary<string, string> old_to_new) protected override OMSTR MapURIsWrapped(Dictionary<string, string> old_to_new)
=> (OMSTR)this.MemberwiseClone(); => (OMSTR)this.MemberwiseClone();
} }
...@@ -769,6 +819,9 @@ public OMF(float f) : base() ...@@ -769,6 +819,9 @@ public OMF(float f) : base()
this.@float = f; this.@float = f;
} }
protected internal override SOMDoc TypeOf(SOMDoc[] args)
=> new OMS(MMT_OMS_URI.RealLit);
protected override bool EquivalentWrapped(OMF sd2) protected override bool EquivalentWrapped(OMF sd2)
=> Mathf.Approximately(@float, sd2.@float); => Mathf.Approximately(@float, sd2.@float);
...@@ -778,7 +831,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio ...@@ -778,7 +831,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio
public override string ToString() public override string ToString()
=> @float.ToString(); => @float.ToString();
public override OMF MapURIsWrapped(Dictionary<string, string> old_to_new) protected override OMF MapURIsWrapped(Dictionary<string, string> old_to_new)
=> (OMF)this.MemberwiseClone(); => (OMF)this.MemberwiseClone();
} }
...@@ -794,6 +847,9 @@ public OMC(T value) : base() ...@@ -794,6 +847,9 @@ public OMC(T value) : base()
this.value = value; this.value = value;
} }
protected internal override SOMDoc TypeOf(SOMDoc[] args)
=> new OMS(MMT_OMS_URI.TYPE_TO_OMS[typeof(T)]);
protected override bool EquivalentWrapped(OMC<T> sd2) protected override bool EquivalentWrapped(OMC<T> sd2)
{ {
Debug.LogWarning("Cannot check Equivalency for " + this.GetType() + "; only whether it's exact!"); Debug.LogWarning("Cannot check Equivalency for " + this.GetType() + "; only whether it's exact!");
...@@ -806,7 +862,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio ...@@ -806,7 +862,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio
public override string ToString() public override string ToString()
=> "C_" + typeof(T) + "(" + value.ToString() + ")"; => "C_" + typeof(T) + "(" + value.ToString() + ")";
public override OMC<T> MapURIsWrapped(Dictionary<string, string> old_to_new) protected override OMC<T> MapURIsWrapped(Dictionary<string, string> old_to_new)
=> (OMC<T>)this.MemberwiseClone(); => (OMC<T>)this.MemberwiseClone();
} }
...@@ -822,6 +878,9 @@ public OMV(string name) : base() ...@@ -822,6 +878,9 @@ public OMV(string name) : base()
this.name = name; this.name = name;
} }
protected internal override SOMDoc TypeOf(SOMDoc[] args)
=> throw new NotImplementedException();
protected override bool EquivalentWrapped(OMV sd2) protected override bool EquivalentWrapped(OMV sd2)
=> this.name == sd2.name; => this.name == sd2.name;
...@@ -840,7 +899,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio ...@@ -840,7 +899,7 @@ protected internal override LambdaExpression GetLambdaExpression(LambdaExpressio
public override string ToString() public override string ToString()
=> "Variable_" + "(" + name + ")"; => "Variable_" + "(" + name + ")";
public override OMV MapURIsWrapped(Dictionary<string, string> old_to_new) protected override OMV MapURIsWrapped(Dictionary<string, string> old_to_new)
=> (OMV)this.MemberwiseClone(); => (OMV)this.MemberwiseClone();
} }
...@@ -856,7 +915,10 @@ public RAW(string xml) : base() ...@@ -856,7 +915,10 @@ public RAW(string xml) : base()
this.xml = xml; this.xml = xml;
} }
public override RAW MapURIsWrapped(Dictionary<string, string> old_to_new) protected internal override SOMDoc TypeOf(SOMDoc[] args)
=> throw new NotImplementedException();
protected override RAW MapURIsWrapped(Dictionary<string, string> old_to_new)
{ {
string copy = xml; string copy = xml;
foreach (KeyValuePair<string, string> KeyVal in old_to_new) foreach (KeyValuePair<string, string> KeyVal in old_to_new)
......
...@@ -11,7 +11,7 @@ public class CollapsableStage : MonoBehaviour ...@@ -11,7 +11,7 @@ public class CollapsableStage : MonoBehaviour
public EditLoader editLoader; public EditLoader editLoader;
public string stage_name; public string stage_name;
public bool local; public bool local;
public Stage stage { get { return StageStatic.GetStage(stage_name, local); } } public Stage stage => StageStatic.GetStage(stage_name, local);
public void Init() public void Init()
{ {
...@@ -51,8 +51,7 @@ public void DrawChildren() ...@@ -51,8 +51,7 @@ public void DrawChildren()
{ {
var index = record_list[i].name; var index = record_list[i].name;
GameObject time_entry = Instantiate(TimeEntry); GameObject time_entry = Instantiate(TimeEntry, body.transform);
time_entry.transform.SetParent(body.transform, false);
PopulateLocalEntryList(time_entry, new List<string> { PopulateLocalEntryList(time_entry, new List<string> {
stage.player_record_list[index].solved ? (++k).ToString() : "--", stage.player_record_list[index].solved ? (++k).ToString() : "--",
......
using System.Collections.Generic;
public static class DictionaryExtensions
{
public static Dictionary<V, K> ReverseKeyVal<K, V>(this IReadOnlyDictionary<K, V> source)
=> source.ReverseKeyValInto(new());
public static Dictionary<V, K> ReverseKeyValInto<K, V>(this IReadOnlyDictionary<K, V> source, Dictionary<V, K> target)
{
foreach (KeyValuePair<K, V> KeyVal in source)
if (KeyVal.Value != null)
target.TryAdd(KeyVal.Value, KeyVal.Key);
return target;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 0e5c609270dbe874588c6e9dc0e3c4f2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment