diff --git a/Assets/Scripts/GenerateDemoFiles.cs b/Assets/Scripts/GenerateDemoFiles.cs index 1ce3523886d9e077ef572bfbfb641dfe0c46d12f..33813d6c1ee266418464d2bf6aadda0bc0d712e0 100644 --- a/Assets/Scripts/GenerateDemoFiles.cs +++ b/Assets/Scripts/GenerateDemoFiles.cs @@ -1,12 +1,10 @@ using System.Linq; using System.Collections.Generic; using UnityEngine; -using static CommunicationEvents; -using static UnityEditor.PlayerSettings; using static CanonBallProblemCalculator; using Unity.Mathematics; using System; -using static SOMDocManager; +using REST_JSON_API; public class GenerateDemoFiles { @@ -253,7 +251,7 @@ public static void GenerateCanonBallStage() // Set Solution #region CannonBallScroll StageStatic.stage.solution.Add( // for CannonBallScroll - new ListFact(Walls.Select(w => w.Topology.Id).ToArray(), null, new OMS(MMT_OMS_URI.TYPE_TO_OMS[typeof(LineFact)]), StageStatic.stage.solution), + new ListFact(Walls.Select(w => w.Topology.Id).ToArray(), null, new OMS(MMTConstants.TYPE_TO_OMS[typeof(LineFact)]), StageStatic.stage.solution), out bool _, true, null, null ); diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractAngleFact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractAngleFact.cs index 5ef39d1704835ef3672d1d3d45e8733566787bbe..347f69e5fb25a47ddd33531d0f9432e3e35211e6 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractAngleFact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractAngleFact.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; +using REST_JSON_API; using System; using System.Collections.Generic; -using static SOMDocManager; using TMPro; using UnityEngine; using UnityEngine.UIElements; @@ -149,11 +149,11 @@ public AngleFact(string pid1, string pid2, string pid3, FactOrganizer organizer) public AngleFact(string Pid1, string Pid2, string Pid3, float angle, string backendURI, FactOrganizer organizer) : base(Pid1, Pid2, Pid3, angle, backendURI, organizer) { } - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc lhs = new OMA( - new OMS(MMT_OMS_URI.Angle), + new OMS(MMTConstants.Angle), new[] { new OMS(Pid1), new OMS(Pid2), @@ -161,16 +161,16 @@ public override MMTDeclaration MakeMMTDeclaration() } ); - SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit); + SOMDoc valueTp = new OMS(MMTConstants.RealLit); SOMDoc value = new OMF(angle); - return new MMTValueDeclaration(this.Label, lhs, valueTp, value); + return new MMTValueFact(this.Label, lhs, valueTp, value); } /// \copydoc Fact.parseFact(ScrollFact) - public new static AngleFact parseFact(MMTDeclaration fact) + public new static AngleFact parseFact(MMTFact fact) { - if (fact is not MMTValueDeclaration value_fact) //If angle is a 90Degree-Angle + if (fact is not MMTValueFact value_fact) //If angle is a 90Degree-Angle throw new ArgumentException("Angle 90 degrees parsed. This shouldn't happen anymore"); if (value_fact.lhs is not OMA lhs) @@ -241,14 +241,14 @@ public RightAngleFact(string pid1, string pid2, string pid3, FactOrganizer organ public RightAngleFact(string Pid1, string Pid2, string Pid3, string backendURI, FactOrganizer organizer) : base(Pid1, Pid2, Pid3, 90f, backendURI, organizer) { } - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc tp = new OMA( - new OMS(MMT_OMS_URI.Ded), + new OMS(MMTConstants.Ded), new[] { new OMA( - new OMS(MMT_OMS_URI.RightAngle), + new OMS(MMTConstants.RightAngle), new[] { new OMS(Pid1), new OMS(Pid2), @@ -257,13 +257,13 @@ public override MMTDeclaration MakeMMTDeclaration() SOMDoc df = null; - return new MMTSymbolDeclaration(Label, tp, df); + return new MMTGeneralFact(Label, tp, df); } /// \copydoc Fact.parseFact(ScrollFact) - public new static RightAngleFact parseFact(MMTDeclaration fact) + public new static RightAngleFact parseFact(MMTFact fact) { - if (((MMTSymbolDeclaration)fact).type + if (((MMTGeneralFact)fact).type is not OMA proof_OMA // proof DED || proof_OMA.arguments[0] is not OMA rightAngleOMA // rightAngle OMA diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractLineFact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractLineFact.cs index 6d0161d58b91729158c8d8887558efe6854a4125..889b1c723a881504416411a228a9b3253e68bdf3 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractLineFact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/AbstractLineFact.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; +using REST_JSON_API; using System.Collections.Generic; using UnityEngine; -using static SOMDocManager; /// <summary> /// Base-class for 1D-Facts @@ -136,28 +136,28 @@ public LineFact(string pid1, string pid2, FactOrganizer organizer) : base(pid1, SendToMMT(); } - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc lhs = new OMA( - new OMS(MMT_OMS_URI.Metric), + new OMS(MMTConstants.Metric), new[] { new OMS(Pid1), new OMS(Pid2) } ); - SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit); + SOMDoc valueTp = new OMS(MMTConstants.RealLit); OMF value = new OMF(Distance); - return new MMTValueDeclaration(this.Label, lhs, valueTp, value); + return new MMTValueFact(this.Label, lhs, valueTp, value); } /// \copydoc Fact.parseFact(ScrollFact) - public new static LineFact parseFact(MMTDeclaration fact) + public new static LineFact parseFact(MMTFact fact) { - string pointAUri = ((OMS)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).uri; - string pointBUri = ((OMS)((OMA)((MMTValueDeclaration)fact).lhs).arguments[1]).uri; + string pointAUri = ((OMS)((OMA)((MMTValueFact)fact).lhs).arguments[0]).uri; + string pointBUri = ((OMS)((OMA)((MMTValueFact)fact).lhs).arguments[1]).uri; if (!FactOrganizer.AllFacts.ContainsKey(pointAUri) || !FactOrganizer.AllFacts.ContainsKey(pointBUri)) @@ -200,24 +200,24 @@ public RayFact(string pid1, string pid2, FactOrganizer organizer) : base(pid1, p SendToMMT(); } - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { - SOMDoc type = new OMS(MMT_OMS_URI.LineType); + SOMDoc type = new OMS(MMTConstants.LineType); SOMDoc defines = new OMA( - new OMS(MMT_OMS_URI.LineOf), + new OMS(MMTConstants.LineOf), new[] { new OMS(Pid1), new OMS(Pid2) }); - return new MMTSymbolDeclaration(this.Label, type, defines); + return new MMTGeneralFact(this.Label, type, defines); } /// \copydoc Fact.parseFact(ScrollFact) - public new static RayFact parseFact(MMTDeclaration fact) + public new static RayFact parseFact(MMTFact fact) { - if (((MMTSymbolDeclaration)fact).defines is not OMA defines) + if (((MMTGeneralFact)fact).defines is not OMA defines) return null; string pointAUri = ((OMS)defines.arguments[0]).uri; diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs index 492f931f79d80c901e184c6e9039d4aa897e5d7b..51d069cba56e2bd4504e218b33d8c31f90dc3bad 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/Fact.cs @@ -6,60 +6,56 @@ using JsonSubTypes; using System.Linq; using REST_JSON_API; -using static SOMDocManager; -using UnityEngine.ProBuilder; -using Unity.Mathematics; -using System.Runtime.ExceptionServices; public static class ParsingDictionary { //TODO? get rid of this, use reflection? instead, if possible //TODO: docu - public static Dictionary<string, Func<MMTDeclaration, Fact>> parseFactDictionary = new() { - { MMT_OMS_URI.Point, + public static Dictionary<string, Func<MMTFact, Fact>> parseFactDictionary = new() { + { MMTConstants.Point, PointFact.parseFact }, - { MMT_OMS_URI.Metric, + { MMTConstants.Metric, LineFact.parseFact }, - { MMT_OMS_URI.Angle, + { MMTConstants.Angle, AngleFact.parseFact }, - { MMT_OMS_URI.Eq, + { MMTConstants.Eq, AngleFact.parseFact }, - { MMT_OMS_URI.RightAngle, + { MMTConstants.RightAngle, RightAngleFact.parseFact }, - { MMT_OMS_URI.LineType, + { MMTConstants.LineType, RayFact.parseFact }, - { MMT_OMS_URI.LineOf, + { MMTConstants.LineOf, RayFact.parseFact }, - { MMT_OMS_URI.OnLine, + { MMTConstants.OnLine, OnLineFact.parseFact }, - { MMT_OMS_URI.ParallelLine, + { MMTConstants.ParallelLine, ParallelLineFact.parseFact }, - { MMT_OMS_URI.CircleType3d, + { MMTConstants.CircleType3d, CircleFact.parseFact }, - { MMT_OMS_URI.OnCircle, + { MMTConstants.OnCircle, OnCircleFact.parseFact }, - { MMT_OMS_URI.AnglePlaneLine, + { MMTConstants.AnglePlaneLine, AngleCircleLineFact.parseFact }, - { MMT_OMS_URI.RadiusCircleMetric, + { MMTConstants.RadiusCircleMetric, RadiusFact.parseFact }, - { MMT_OMS_URI.AreaCircle, + { MMTConstants.AreaCircle, AreaCircleFact.parseFact }, - { MMT_OMS_URI.OrthoCircleLine, + { MMTConstants.OrthoCircleLine, OrthogonalCircleLineFact.parseFact }, - { MMT_OMS_URI.VolumeCone, + { MMTConstants.VolumeCone, ConeVolumeFact.parseFact }, - { MMT_OMS_URI.TruncatedVolumeCone, + { MMTConstants.TruncatedVolumeCone, TruncatedConeVolumeFact.parseFact }, - { MMT_OMS_URI.CylinderVolume, + { MMTConstants.CylinderVolume, CylinderVolumeFact.parseFact }, - { MMT_OMS_URI.TestType, + { MMTConstants.TestType, TestFact.parseFact }, - { MMT_OMS_URI.EqualityCircles, + { MMTConstants.EqualityCircles, EqualCirclesFact.parseFact }, - { MMT_OMS_URI.UnEqualityCircles, + { MMTConstants.UnEqualityCircles, UnEqualCirclesFact.parseFact }, - { MMT_OMS_URI.ListLiteral, + { MMTConstants.ListLiteral, ListFact.parseFact }, }; @@ -330,7 +326,7 @@ public bool rename(string newLabel) protected abstract void RecalculateTransform(); - public abstract MMTDeclaration MakeMMTDeclaration(); + public abstract MMTFact MakeMMTDeclaration(); /// <summary> /// Frees ressources e.g. <see cref="Label"/> and will eventually delete %Fact Server-Side in far-near future when feature is supported. @@ -393,11 +389,11 @@ protected virtual string generateLabel() } /// <summary> - /// Parses <see cref="MMTDeclaration"/> to actual Fact + /// Parses <see cref="MMTFact"/> to actual Fact /// </summary> /// <param name="fact">instance to be parsed</param> /// <returns>parsed Fact</returns> - public static Fact parseFact(MMTDeclaration fact) + public static Fact parseFact(MMTFact fact) => null; /// <summary> @@ -423,7 +419,7 @@ protected void SendToMMT() /// </summary> /// <remarks>Asynchron version has proofen inefficent, since <see cref="Fact.Id"/> is usually called in close proximity.</remarks> // Asynchron version in comments - public static string SendToMMT(MMTDeclaration mmtDecl) + public static string SendToMMT(MMTFact mmtDecl) { //GlobalBehaviour.Instance.StartCoroutine( // FetchURICoroutine = @@ -441,7 +437,7 @@ public static string SendToMMT(MMTDeclaration mmtDecl) //{ // _URI = uri; - if (mmtDecl is MMTSymbolDeclaration mMTSymbol && mMTSymbol.defines != null) + if (mmtDecl is MMTGeneralFact mMTSymbol && mMTSymbol.defines != null) ParsingDictionary.parseTermsToId[mMTSymbol.defines.ToString()] = uri;// _URI; //} @@ -591,9 +587,9 @@ public PointFact(Vector3 point, string uri, FactOrganizer organizer) : base(orga } /// \copydoc Fact.parseFact(ScrollFact) - public new static PointFact parseFact(MMTDeclaration fact) + public new static PointFact parseFact(MMTFact fact) { - if (((MMTSymbolDeclaration)fact).defines is not OMA defines) + if (((MMTGeneralFact)fact).defines is not OMA defines) return null; ParsingDictionary.parseTermsToId.TryAdd(defines.ToString(), fact.@ref.uri); @@ -619,11 +615,11 @@ protected override bool EquivalentWrapped(PointFact f1, PointFact f2) protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer) => new PointFact(this.Point, this.Normal, organizer); - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { - SOMDoc tp = new OMS(MMT_OMS_URI.Point); + SOMDoc tp = new OMS(MMTConstants.Point); SOMDoc df = new OMA( - new OMS(MMT_OMS_URI.Tuple), + new OMS(MMTConstants.Tuple), new[] { new OMF(Point.x), new OMF(Point.y), @@ -631,7 +627,7 @@ public override MMTDeclaration MakeMMTDeclaration() } ); - return new MMTSymbolDeclaration(Label, tp, df); + return new MMTGeneralFact(Label, tp, df); } } @@ -708,14 +704,14 @@ public OnLineFact(string pid, string rid, string uri, FactOrganizer organizer) : } /// \copydoc Fact.parseFact(ScrollFact) - public new static OnLineFact parseFact(MMTDeclaration fact) + public new static OnLineFact parseFact(MMTFact fact) { - string pointUri = ((OMS)((OMA)((OMA)((MMTSymbolDeclaration)fact).type).arguments[0]).arguments[1]).uri; - string lineUri = ((OMA)((OMA)((MMTSymbolDeclaration)fact).type).arguments[0]).arguments[0] is OMS + string pointUri = ((OMS)((OMA)((OMA)((MMTGeneralFact)fact).type).arguments[0]).arguments[1]).uri; + string lineUri = ((OMA)((OMA)((MMTGeneralFact)fact).type).arguments[0]).arguments[0] is OMS // standard case - ? ((OMS)((OMA)((OMA)((MMTSymbolDeclaration)fact).type).arguments[0]).arguments[0]).uri + ? ((OMS)((OMA)((OMA)((MMTGeneralFact)fact).type).arguments[0]).arguments[0]).uri // case when line Uri has a projl on the line Argument - : ((OMS)((OMA)((OMA)((OMA)((MMTSymbolDeclaration)fact).type).arguments[0]).arguments[0]).arguments[0]).uri; + : ((OMS)((OMA)((OMA)((OMA)((MMTGeneralFact)fact).type).arguments[0]).arguments[0]).arguments[0]).uri; if (!FactOrganizer.AllFacts.ContainsKey(pointUri) || !FactOrganizer.AllFacts.ContainsKey(lineUri)) @@ -741,13 +737,13 @@ protected override bool EquivalentWrapped(OnLineFact f1, OnLineFact f2) protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer) => new OnLineFact(old_to_new[this.Pid], old_to_new[this.Rid], organizer); - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc tp = new OMA( - new OMS(MMT_OMS_URI.Ded), + new OMS(MMTConstants.Ded), new[] { new OMA( - new OMS(MMT_OMS_URI.OnLine), + new OMS(MMTConstants.OnLine), new[] { new OMS(Rid), new OMS(Pid) @@ -755,7 +751,7 @@ public override MMTDeclaration MakeMMTDeclaration() SOMDoc df = null; - return new MMTSymbolDeclaration(this.Label, tp, df); + return new MMTGeneralFact(this.Label, tp, df); } } @@ -815,9 +811,9 @@ public ParallelLineFact(string Lid1, string Lid2, string backendURI, FactOrganiz } /// \copydoc Fact.parseFact(ScrollFact) - public new static ParallelLineFact parseFact(MMTDeclaration fact) + public new static ParallelLineFact parseFact(MMTFact fact) { - if (((MMTSymbolDeclaration)fact).type is not OMA type) // proof DED + if (((MMTGeneralFact)fact).type is not OMA type) // proof DED return null; OMA parallel_lines_OMA = (OMA)type.arguments[0]; // parallel @@ -836,13 +832,13 @@ public ParallelLineFact(string Lid1, string Lid2, string backendURI, FactOrganiz protected override string generateLabel() => Ray1.Label + "||" + Ray2.Label; - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc tp = new OMA( - new OMS(MMT_OMS_URI.Ded), + new OMS(MMTConstants.Ded), new[] { new OMA( - new OMS(MMT_OMS_URI.ParallelLine), + new OMS(MMTConstants.ParallelLine), new[] { new OMS(Lid1), new OMS(Lid2), @@ -853,7 +849,7 @@ public override MMTDeclaration MakeMMTDeclaration() SOMDoc df = null; - return new MMTSymbolDeclaration(this.Label, tp, df); + return new MMTGeneralFact(this.Label, tp, df); } /// \copydoc Fact.hasDependentFacts @@ -957,9 +953,9 @@ public CircleFact(string Pid1, string Pid2, float radius, Vector3 normal, string /// parses the Circlefact response of the MMT-Server /// </summary> /// \copydoc Fact.parseFact(ScrollFact) - public new static CircleFact parseFact(MMTDeclaration fact) + public new static CircleFact parseFact(MMTFact fact) { - if (((MMTSymbolDeclaration)fact).defines is not OMA df) + if (((MMTGeneralFact)fact).defines is not OMA df) return null; OMA planeOMA = (OMA)df.arguments[0]; @@ -968,13 +964,13 @@ public CircleFact(string Pid1, string Pid2, float radius, Vector3 normal, string Vector3 normal; // Getting the plane // IN case of a normale plane - if (planeApplicant.Equals(MMT_OMS_URI.pointNormalPlane)) + if (planeApplicant.Equals(MMTConstants.pointNormalPlane)) { //OMA pointAOMA = (OMA)planeOMA.arguments[0]; normal = (planeOMA.arguments[1].GetLambdaExpression().Compile() as Func<Vector3>)(); } // In case of parametrized plane - else if (planeApplicant.Equals(MMT_OMS_URI.ParametrizedPlane)) + else if (planeApplicant.Equals(MMTConstants.ParametrizedPlane)) { Vector3 v = (planeOMA.arguments[1].GetLambdaExpression().Compile() as Func<Vector3>)(); Vector3 w = (planeOMA.arguments[2].GetLambdaExpression().Compile() as Func<Vector3>)(); @@ -1008,14 +1004,14 @@ protected override string generateLabel() /// <param name="p2URI"> <see cref="Pid2"/></param> /// <param name="radius"> <see cref="radius"/></param> /// <returns>struct for <see cref="AddFactResponse"/></returns> - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc[] outerArguments = new SOMDoc[] { //CirclePlane, new OMA( //PointNormalPlane, - new OMS(MMT_OMS_URI.pointNormalPlane), + new OMS(MMTConstants.pointNormalPlane), //planeArgs, new SOMDoc[] { //base point of the circle plane?, @@ -1023,7 +1019,7 @@ public override MMTDeclaration MakeMMTDeclaration() //NormalVector, new OMA( //"Vector" - new OMS(MMT_OMS_URI.Tuple), + new OMS(MMTConstants.Tuple), //normalArgs, new[] { new OMF(normal.x), @@ -1040,10 +1036,10 @@ public override MMTDeclaration MakeMMTDeclaration() }; // Do i need this here? doubt - SOMDoc tp = new OMS(MMT_OMS_URI.CircleType3d); - SOMDoc df = new OMA(new OMS(MMT_OMS_URI.MkCircle3d), outerArguments); + SOMDoc tp = new OMS(MMTConstants.CircleType3d); + SOMDoc df = new OMA(new OMS(MMTConstants.MkCircle3d), outerArguments); - return new MMTSymbolDeclaration(Label, tp, df); + return new MMTGeneralFact(Label, tp, df); } /// \copydoc Fact.hasDependentFacts @@ -1122,9 +1118,9 @@ public OnCircleFact(string pid, string cid, string uri, FactOrganizer organizer) } /// \copydoc Fact.parseFact(ScrollFact) - public new static OnCircleFact parseFact(MMTDeclaration fact) + public new static OnCircleFact parseFact(MMTFact fact) { - if (((MMTSymbolDeclaration)fact).type is not OMA type) + if (((MMTGeneralFact)fact).type is not OMA type) return null; string circleUri = ((OMS)((OMA)type.arguments[0]).arguments[0]).uri; @@ -1155,14 +1151,14 @@ protected override bool EquivalentWrapped(OnCircleFact c1, OnCircleFact c2) protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer) => new OnCircleFact(old_to_new[this.Pid], old_to_new[this.Cid], organizer); - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc tp = new OMA( - new OMS(MMT_OMS_URI.Ded), + new OMS(MMTConstants.Ded), new[] { new OMA( - new OMS(MMT_OMS_URI.OnCircle), + new OMS(MMTConstants.OnCircle), new[] { new OMS(Cid), new OMS(Pid), @@ -1170,7 +1166,7 @@ public override MMTDeclaration MakeMMTDeclaration() SOMDoc df = null; - return new MMTSymbolDeclaration(Label, tp, df); + return new MMTGeneralFact(Label, tp, df); } } @@ -1267,16 +1263,16 @@ public AngleCircleLineFact(string Cid1, string Rid2, float angle, string backend } /// \copydoc Fact.parseFact(ScrollFact) - public new static AngleCircleLineFact parseFact(MMTDeclaration fact) + public new static AngleCircleLineFact parseFact(MMTFact fact) { - if (((MMTValueDeclaration)fact).lhs is not OMA lhs) + if (((MMTValueFact)fact).lhs is not OMA lhs) return null; // init it with 0 degrees, so we don't accidentally generate orthogonalfacts // and the parsing works correctly if smb ever adds a scroll for this float angle = 0.0f; - if (((MMTValueDeclaration)fact).value is OMF oMFangle) + if (((MMTValueFact)fact).value is OMF oMFangle) angle = oMFangle.@float; string CircleUri = ((OMS)lhs.arguments[0]).uri; @@ -1293,21 +1289,21 @@ public AngleCircleLineFact(string Cid1, string Rid2, float angle, string backend protected override string generateLabel() => "∠" + Circle.Label + Ray.Label; - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc lhs = new OMA( - new OMS(MMT_OMS_URI.AnglePlaneLine), + new OMS(MMTConstants.AnglePlaneLine), new[] { new OMS(Cid1), new OMS(Rid2), } ); - SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit); + SOMDoc valueTp = new OMS(MMTConstants.RealLit); SOMDoc value = new OMF(angle); - return new MMTValueDeclaration(this.Label, lhs, valueTp, value); + return new MMTValueFact(this.Label, lhs, valueTp, value); } /// \copydoc Fact.hasDependentFacts @@ -1381,9 +1377,9 @@ public RadiusFact(string Cid1, string backendURI, FactOrganizer organizer) : bas } /// \copydoc Fact.parseFact(ScrollFact) - public new static RadiusFact parseFact(MMTDeclaration fact) + public new static RadiusFact parseFact(MMTFact fact) { - string CircleUri = ((OMS)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).uri; + string CircleUri = ((OMS)((OMA)((MMTValueFact)fact).lhs).arguments[0]).uri; if (!FactOrganizer.AllFacts.ContainsKey(CircleUri)) return null; @@ -1401,20 +1397,20 @@ protected override string generateLabel() /// <param name="rad"> see <see cref="rad"/></param> /// <param name="c1URI"> see <see cref="Cid1"/></param> - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc lhs = new OMA( - new OMS(MMT_OMS_URI.RadiusCircleMetric), + new OMS(MMTConstants.RadiusCircleMetric), new[] { new OMS(Cid1), } ); - SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit); + SOMDoc valueTp = new OMS(MMTConstants.RealLit); SOMDoc value = new OMF(rad); - return new MMTValueDeclaration(this.Label, lhs, valueTp, value); + return new MMTValueFact(this.Label, lhs, valueTp, value); } /// \copydoc Fact.hasDependentFacts @@ -1490,9 +1486,9 @@ public AreaCircleFact(string Cid1, string backendURI, FactOrganizer organizer) : } /// \copydoc Fact.parseFact(ScrollFact) - public new static AreaCircleFact parseFact(MMTDeclaration fact) + public new static AreaCircleFact parseFact(MMTFact fact) { - string CircleUri = ((OMS)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).uri; + string CircleUri = ((OMS)((OMA)((MMTValueFact)fact).lhs).arguments[0]).uri; if (!FactOrganizer.AllFacts.ContainsKey(CircleUri)) return null; @@ -1504,20 +1500,20 @@ public AreaCircleFact(string Cid1, string backendURI, FactOrganizer organizer) : protected override string generateLabel() => "A(" + Circle.Label + ")"; - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc lhs = new OMA( - new OMS(MMT_OMS_URI.AreaCircle), + new OMS(MMTConstants.AreaCircle), new[] { new OMS(Cid1), } ); - SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit); + SOMDoc valueTp = new OMS(MMTConstants.RealLit); SOMDoc value = new OMF(A); - return new MMTValueDeclaration(this.Label, lhs, valueTp, value); + return new MMTValueFact(this.Label, lhs, valueTp, value); } /// \copydoc Fact.hasDependentFacts @@ -1607,16 +1603,16 @@ public ConeVolumeFact(string Cid1, string Pid1, float volume, string backendURI, } /// \copydoc Fact.parseFact(ScrollFact) - public new static ConeVolumeFact parseFact(MMTDeclaration fact) + public new static ConeVolumeFact parseFact(MMTFact fact) { - if (((MMTValueDeclaration)fact).lhs is not OMA lhs) + if (((MMTValueFact)fact).lhs is not OMA lhs) return null; string CircleUri = ((OMS)((OMA)lhs.arguments[0]).arguments[0]).uri; string PointUri = ((OMS)((OMA)lhs.arguments[0]).arguments[1]).uri; float volume = 0.0f; - if (((MMTValueDeclaration)fact).value is OMF oMFvolume) + if (((MMTValueFact)fact).value is OMF oMFvolume) volume = oMFvolume.@float; if (!FactOrganizer.AllFacts.ContainsKey(CircleUri) @@ -1630,14 +1626,14 @@ public ConeVolumeFact(string Cid1, string Pid1, float volume, string backendURI, protected override string generateLabel() => "V(" + Circle.Label + "," + Point.Label + ")"; - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc lhs = new OMA( - new OMS(MMT_OMS_URI.VolumeCone), + new OMS(MMTConstants.VolumeCone), new[] { - new OMA(new OMS(MMT_OMS_URI.ConeOfCircleApex), + new OMA(new OMS(MMTConstants.ConeOfCircleApex), new[] { new OMS(Cid1), new OMS(Pid1), @@ -1646,10 +1642,10 @@ public override MMTDeclaration MakeMMTDeclaration() } ); - SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit); + SOMDoc valueTp = new OMS(MMTConstants.RealLit); SOMDoc value = new OMF(vol); - return new MMTValueDeclaration(this.Label, lhs, valueTp, value); + return new MMTValueFact(this.Label, lhs, valueTp, value); } /// \copydoc Fact.hasDependentFacts @@ -1747,9 +1743,9 @@ public OrthogonalCircleLineFact(string Cid1, string Lid1, string backendURI, Fac } /// \copydoc Fact.parseFact(ScrollFact) - public new static OrthogonalCircleLineFact parseFact(MMTDeclaration fact) + public new static OrthogonalCircleLineFact parseFact(MMTFact fact) { - if (((MMTSymbolDeclaration)fact).type is not OMA type) + if (((MMTGeneralFact)fact).type is not OMA type) return null; string CircleUri = ((OMS)((OMA)type.arguments[0]).arguments[0]).uri; @@ -1766,13 +1762,13 @@ public OrthogonalCircleLineFact(string Cid1, string Lid1, string backendURI, Fac protected override string generateLabel() => Circle.Label + "⊥" + Ray.Label; - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc tp = new OMA( - new OMS(MMT_OMS_URI.Ded), + new OMS(MMTConstants.Ded), new[]{ new OMA( - new OMS(MMT_OMS_URI.OrthoCircleLine), + new OMS(MMTConstants.OrthoCircleLine), new[] { new OMS(Cid1), new OMS(Lid1), @@ -1783,7 +1779,7 @@ public override MMTDeclaration MakeMMTDeclaration() SOMDoc df = null; - return new MMTSymbolDeclaration(this.Label, tp, df); + return new MMTGeneralFact(this.Label, tp, df); } /// \copydoc Fact.hasDependentFacts @@ -1882,14 +1878,14 @@ public TruncatedConeVolumeFact(string Cid1, string Cid2, float volume, string un } /// \copydoc Fact.parseFact(ScrollFact) - public new static TruncatedConeVolumeFact parseFact(MMTDeclaration fact) + public new static TruncatedConeVolumeFact parseFact(MMTFact fact) { - string Circle1Uri = ((OMS)((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[0]).uri; - string Circle2Uri = ((OMS)((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[1]).uri; - float volume = ((OMF)((MMTValueDeclaration)fact).value).@float; + string Circle1Uri = ((OMS)((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[0]).uri; + string Circle2Uri = ((OMS)((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[1]).uri; + float volume = ((OMF)((MMTValueFact)fact).value).@float; - string UnEqualCirclesProof = ((OMS)(((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[2])).uri; - OMA proof = (OMA)(((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[3]); + string UnEqualCirclesProof = ((OMS)(((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[2])).uri; + OMA proof = (OMA)(((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[3]); if (!FactOrganizer.AllFacts.ContainsKey(Circle1Uri) || !FactOrganizer.AllFacts.ContainsKey(Circle2Uri)) @@ -1902,11 +1898,11 @@ public TruncatedConeVolumeFact(string Cid1, string Cid2, float volume, string un protected override string generateLabel() => "V(" + Circle1.Label + "," + Circle2.Label + ")"; - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc lhs = new OMA( - new OMS(MMT_OMS_URI.TruncatedVolumeCone), + new OMS(MMTConstants.TruncatedVolumeCone), new SOMDoc[] { new OMS(Cid1), new OMS(Cid2), @@ -1915,10 +1911,10 @@ public override MMTDeclaration MakeMMTDeclaration() } ); - SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit); + SOMDoc valueTp = new OMS(MMTConstants.RealLit); SOMDoc value = new OMF(vol); - return new MMTValueDeclaration(this.Label, lhs, valueTp, value); + return new MMTValueFact(this.Label, lhs, valueTp, value); } /// \copydoc Fact.hasDependentFacts @@ -2016,14 +2012,14 @@ public CylinderVolumeFact(string Cid1, string Cid2, float volume, string eqProof } /// \copydoc Fact.parseFact(ScrollFact) - public new static CylinderVolumeFact parseFact(MMTDeclaration fact) + public new static CylinderVolumeFact parseFact(MMTFact fact) { - string Circle1Uri = ((OMS)((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[0]).uri; - string Circle2Uri = ((OMS)((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[1]).uri; - float volume = ((OMF)((MMTValueDeclaration)fact).value).@float; - string EqualCirclesProof = ((OMS)(((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[2])).uri; + string Circle1Uri = ((OMS)((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[0]).uri; + string Circle2Uri = ((OMS)((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[1]).uri; + float volume = ((OMF)((MMTValueFact)fact).value).@float; + string EqualCirclesProof = ((OMS)(((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[2])).uri; - OMA proof = (OMA)(((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[3]); + OMA proof = (OMA)(((OMA)((OMA)((MMTValueFact)fact).lhs).arguments[0]).arguments[3]); if (!FactOrganizer.AllFacts.ContainsKey(Circle1Uri) || !FactOrganizer.AllFacts.ContainsKey(Circle2Uri)) @@ -2036,11 +2032,11 @@ public CylinderVolumeFact(string Cid1, string Cid2, float volume, string eqProof protected override string generateLabel() => "V(" + Circle1.Label + "," + Circle2.Label + ")"; - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc lhs = new OMA( - new OMS(MMT_OMS_URI.CylinderVolume), + new OMS(MMTConstants.CylinderVolume), new SOMDoc[] { new OMS(Cid1), @@ -2050,10 +2046,10 @@ public override MMTDeclaration MakeMMTDeclaration() } ); - SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit); + SOMDoc valueTp = new OMS(MMTConstants.RealLit); SOMDoc value = new OMF(vol); - return new MMTValueDeclaration(this.Label, lhs, valueTp, value); + return new MMTValueFact(this.Label, lhs, valueTp, value); } /// \copydoc Fact.hasDependentFacts @@ -2132,9 +2128,9 @@ public EqualCirclesFact(string Cid1, string Cid2, string backendURI, FactOrganiz } /// \copydoc Fact.parseFact(ScrollFact) - public new static EqualCirclesFact parseFact(MMTDeclaration fact) + public new static EqualCirclesFact parseFact(MMTFact fact) { - if (((MMTSymbolDeclaration)fact).type is not OMA proof_OMA) // proof DED + if (((MMTGeneralFact)fact).type is not OMA proof_OMA) // proof DED return null; OMA parallel_circles_OMA = (OMA)proof_OMA.arguments[0]; // parallel @@ -2153,13 +2149,13 @@ public EqualCirclesFact(string Cid1, string Cid2, string backendURI, FactOrganiz protected override string generateLabel() => Circle1.Label + " ≠ " + Circle2.Label; - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc tp = new OMA( - new OMS(MMT_OMS_URI.Ded), + new OMS(MMTConstants.Ded), new[] { new OMA( - new OMS(MMT_OMS_URI.EqualityCircles), + new OMS(MMTConstants.EqualityCircles), new[] { new OMS(Cid1), new OMS(Cid2), @@ -2170,7 +2166,7 @@ public override MMTDeclaration MakeMMTDeclaration() SOMDoc df = null; - return new MMTSymbolDeclaration(this.Label, tp, df); + return new MMTGeneralFact(this.Label, tp, df); } /// \copydoc Fact.hasDependentFacts @@ -2249,9 +2245,9 @@ public UnEqualCirclesFact(string Cid1, string Cid2, string backendURI, FactOrgan } /// \copydoc Fact.parseFact(ScrollFact) - public new static UnEqualCirclesFact parseFact(MMTDeclaration fact) + public new static UnEqualCirclesFact parseFact(MMTFact fact) { - if (((MMTSymbolDeclaration)fact).type is not OMA proof_OMA) // proof DED + if (((MMTGeneralFact)fact).type is not OMA proof_OMA) // proof DED return null; OMA unequal_circles_OMA = (OMA)proof_OMA.arguments[0]; // unequal @@ -2270,12 +2266,12 @@ public UnEqualCirclesFact(string Cid1, string Cid2, string backendURI, FactOrgan protected override string generateLabel() => Circle1.Label + " = " + Circle2.Label; - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { SOMDoc tp = new OMA( - new OMS(MMT_OMS_URI.Ded), + new OMS(MMTConstants.Ded), new[] { - new OMA(new OMS(MMT_OMS_URI.UnEqualityCircles), + new OMA(new OMS(MMTConstants.UnEqualityCircles), new[] { new OMS(Cid1), new OMS(Cid2), @@ -2283,7 +2279,7 @@ public override MMTDeclaration MakeMMTDeclaration() SOMDoc df = null; - return new MMTSymbolDeclaration(this.Label, tp, df); + return new MMTGeneralFact(this.Label, tp, df); } /// \copydoc Fact.hasDependentFacts @@ -2353,7 +2349,7 @@ public TestFact(string backendURI, FactOrganizer organizer) : base(organizer) /// parses the Circlefact response of the MMT-Server /// </summary> /// \copydoc Fact.parseFact(ScrollFact) - public new static TestFact parseFact(MMTDeclaration fact) + public new static TestFact parseFact(MMTFact fact) { string uri = fact.@ref.uri; Debug.Log("TestFact Uri:" + uri); @@ -2384,7 +2380,7 @@ protected override bool EquivalentWrapped(TestFact f1, TestFact f2) protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer) => new TestFact(organizer); - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { throw new NotImplementedException(); } diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/FunctionFact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/FunctionFact.cs index b395c82b9e5d8ea3f0bd565560b52401548063a8..2db3bcca86ce586e5c1118719ee11cc10fb79e73 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/FunctionFact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/FunctionFact.cs @@ -4,7 +4,7 @@ using Newtonsoft.Json; using System.Linq.Expressions; using System.Linq; -using static SOMDocManager; +using REST_JSON_API; public class FunctionCallFact : FactWrappedCRTP<FunctionCallFact> { @@ -57,7 +57,7 @@ protected override bool EquivalentWrapped(FunctionCallFact f1, FunctionCallFact && f1.Function_args.Equivalent(f2.Function_args) )); - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { throw new NotImplementedException(); } @@ -144,9 +144,9 @@ public FunctionFact(SOMDoc Function_SOMDoc, string uri, FactOrganizer organizer) protected override void RecalculateTransform() { } /// \copydoc Fact.parseFact(ScrollFact) - public new static FunctionFact parseFact(MMTDeclaration fact) + public new static FunctionFact parseFact(MMTFact fact) {// TODO Correctness - if (((MMTSymbolDeclaration)fact).defines is not OMA defines) + if (((MMTGeneralFact)fact).defines is not OMA defines) return null; ParsingDictionary.parseTermsToId.TryAdd(defines.ToString(), fact.@ref.uri); @@ -173,7 +173,7 @@ protected override bool EquivalentWrapped(FunctionFact f1, FunctionFact f2) protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer) => new FunctionFact(this.Function_SOMDoc.MapURIs(old_to_new), organizer); - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { throw new NotImplementedException(); } @@ -253,9 +253,9 @@ protected AttachedPositionFunction(string fid, string[] funcids, string uri, Fac // _URI = uri; //} - public new static AttachedPositionFunction parseFact(MMTDeclaration fact) + public new static AttachedPositionFunction parseFact(MMTFact fact) {// TODO Correctness - if (((MMTSymbolDeclaration)fact).defines is not OMA defines) + if (((MMTGeneralFact)fact).defines is not OMA defines) return null; ParsingDictionary.parseTermsToId.TryAdd(defines.ToString(), fact.@ref.uri); @@ -263,7 +263,7 @@ protected AttachedPositionFunction(string fid, string[] funcids, string uri, Fac return new AttachedPositionFunction(default, default(string[]), fact.@ref.uri, StageStatic.stage.factState); } - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { //SOMDoc[] defines ?? //SOMDoc type = new OMS(MMT_OMS_URI.Tuple); diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/MMTTypes.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/MMTTypes.cs index ef35cea8a1aa7e35e980b8c9256afb1c3ad5758d..45200adddf0439ec45aea8ac88b6c4da6e417b01 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/MMTTypes.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/MMTTypes.cs @@ -1,8 +1,7 @@ -using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; using System; -using static SOMDocManager; +using REST_JSON_API; /// <summary> /// @@ -63,7 +62,7 @@ private void Init(string[] lids, SOMDoc[] payload, SOMDoc ElementType) } this.ListType = new OMA( - new OMS(MMT_OMS_URI.ListType), + new OMS(MMTConstants.ListType), new[] { ElementType } ); } @@ -75,9 +74,9 @@ protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, F ListType.arguments[0], organizer); - public static List<T> parseFactList<T>(MMTDeclaration decl) + public static List<T> parseFactList<T>(MMTFact decl) { - if (decl is not MMTSymbolDeclaration mMTSymbol) + if (decl is not MMTGeneralFact mMTSymbol) return null; List<T> ret = new(); @@ -102,9 +101,9 @@ public static List<T> parseFactList<T>(MMTDeclaration decl) } } - public static new ListFact parseFact(MMTDeclaration fact) + public static new ListFact parseFact(MMTFact fact) { - if (fact is not MMTSymbolDeclaration MMTSymbol + if (fact is not MMTGeneralFact MMTSymbol || MMTSymbol.type is not OMA listOMA || listOMA.arguments[0] is not OMA typeOMA) { @@ -140,10 +139,10 @@ public static List<T> parseFactList<T>(MMTDeclaration decl) fact.@ref.uri, StageStatic.stage.factState); } - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { OMA List = SOMDoc.MakeShallowList(payload); - return new MMTSymbolDeclaration(Label, ListType, List); + return new MMTGeneralFact(Label, ListType, List); } protected override string[] GetGetDependentFactIds() @@ -215,9 +214,9 @@ protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, F 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(MMTFact fact) { - if (fact is not MMTSymbolDeclaration MMTSymbol + if (fact is not MMTGeneralFact MMTSymbol || MMTSymbol.defines is not OMA defineOMA) { return null; @@ -230,10 +229,10 @@ protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, F return new(lids, defineOMA.arguments, fact.@ref.uri, StageStatic.stage.factState); } - public override MMTDeclaration MakeMMTDeclaration() + public override MMTFact MakeMMTDeclaration() { OMA Tupel = SOMDoc.MakeTupel(payload); - return new MMTSymbolDeclaration(Label, Tupel.TypeOf(), Tupel); + return new MMTGeneralFact(Label, Tupel.TypeOf(), Tupel); } protected override string[] GetGetDependentFactIds() diff --git a/Assets/Scripts/InteractionEngine/TBD/CanonBallCalculator.cs b/Assets/Scripts/InteractionEngine/TBD/CanonBallCalculator.cs index 4cac425954e921a4adcb5be19c084f560251788b..dd1e64977b6f1430de04fbe731a1e3c7011c6862 100644 --- a/Assets/Scripts/InteractionEngine/TBD/CanonBallCalculator.cs +++ b/Assets/Scripts/InteractionEngine/TBD/CanonBallCalculator.cs @@ -1,8 +1,8 @@ +using REST_JSON_API; using System; using System.Collections.Generic; using System.Linq; using UnityEngine; -using static SOMDocManager; public class CanonBallProblemCalculator { @@ -57,29 +57,29 @@ SOMDoc BuildOMA_XVA() new OMBINDC("Acc", typeof(Vector3), new OMBINDC("t", "R", new OMA( - new OMS(MMT_OMS_URI.Add), + new OMS(MMTConstants.Add), new SOMDoc[] { new OMV("Pos"), new OMA( - new OMS(MMT_OMS_URI.Add), + new OMS(MMTConstants.Add), new[] { new OMA( - new OMS(MMT_OMS_URI.Multiply), + new OMS(MMTConstants.Multiply), new[] { new OMV("Vel"), new OMV("t"), } ), new OMA( - new OMS(MMT_OMS_URI.Multiply), + new OMS(MMTConstants.Multiply), new SOMDoc[] { new OMF(0.5f), new OMA( - new OMS(MMT_OMS_URI.Multiply), + new OMS(MMTConstants.Multiply), new SOMDoc[] { new OMV("Acc"), new OMA( - new OMS(MMT_OMS_URI.Multiply), + new OMS(MMTConstants.Multiply), new[] { new OMV("t"), new OMV("t"), @@ -90,7 +90,7 @@ SOMDoc BuildOMAPath(Vector3 Pos, Vector3 Vel) { //t -> [Pos, Vel, g, t] return new OMBINDC("t", "R", new OMA( - new OMS(MMT_OMS_URI.MakeObjectArray), + new OMS(MMTConstants.MakeObjectArray), new SOMDoc[] { SOMDoc.MakeTupel(Pos), SOMDoc.MakeTupel(Vel), diff --git a/Assets/Scripts/InventoryStuff/ScrollDetails.cs b/Assets/Scripts/InventoryStuff/ScrollDetails.cs index b4430cc55ff230c4ee6f2f437565bfde4f058c61..61bb062c845b97a4e1dc4e0a2beb14e1a6c82ac5 100644 --- a/Assets/Scripts/InventoryStuff/ScrollDetails.cs +++ b/Assets/Scripts/InventoryStuff/ScrollDetails.cs @@ -7,7 +7,6 @@ using System.Linq; using REST_JSON_API; using static CommunicationEvents; -using static SOMDocManager; public class ScrollDetails : MonoBehaviour { @@ -142,13 +141,13 @@ private int[] PrePopulateActiveScroll() { switch (ActiveScroll.ScrollReference) { - case MMT_OMS_URI.ScrollCannonBall: + case MMTConstants.ScrollCannonBall: 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.Tuple) + && tupelOMS.uri == MMTConstants.Tuple) ?.Id; if (lid_override == null) @@ -298,26 +297,26 @@ string prepareScrollAssignments() && lf.ListType is OMA tpOMA && tpOMA.arguments[0] is OMA tupelOMA && tupelOMA.applicant is OMS tupelOMS - && tupelOMS.uri == MMT_OMS_URI.Product) + && tupelOMS.uri == MMTConstants.Product) ?.Id; return JsonConvert.SerializeObject(new ScrollApplication( - MMT_OMS_URI.ScrollCannonBall, + MMTConstants.ScrollCannonBall, new() { new("http://mathhub.info/FrameIT/frameworld?BouncingScroll/Problem?xposition", - Fact.SendToMMT(new MMTSymbolDeclaration("PX", new OMS(MMT_OMS_URI.RealLit), + Fact.SendToMMT(new MMTGeneralFact("PX", new OMS(MMTConstants.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), + Fact.SendToMMT(new MMTGeneralFact("PY", new OMS(MMTConstants.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), + Fact.SendToMMT(new MMTGeneralFact("VX", new OMS(MMTConstants.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), + Fact.SendToMMT(new MMTGeneralFact("VY", new OMS(MMTConstants.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), + Fact.SendToMMT(new MMTGeneralFact("GG", new OMS(MMTConstants.RealLit), new OMF(9.81f)))), new("http://mathhub.info/FrameIT/frameworld?BouncingScroll/Problem?walls", lid_override), @@ -326,7 +325,7 @@ string prepareScrollAssignments() } } - private void ReadPushout(List<MMTDeclaration> pushoutFacts) + private void ReadPushout(List<MMTFact> pushoutFacts) { Popup.HidePopUp(); //close error Window diff --git a/Assets/Scripts/InventoryStuff/Scroll.cs b/Assets/Scripts/MMTServer/CommunicationProtocoll/Endpoints.cs similarity index 57% rename from Assets/Scripts/InventoryStuff/Scroll.cs rename to Assets/Scripts/MMTServer/CommunicationProtocoll/Endpoints.cs index b5ff5a9dbf512ea926594e7fae8e04a503c6d400..eaa50cf37a6fb3fd677c904f653fd785aab8c0da 100644 --- a/Assets/Scripts/InventoryStuff/Scroll.cs +++ b/Assets/Scripts/MMTServer/CommunicationProtocoll/Endpoints.cs @@ -1,6 +1,6 @@ -using Newtonsoft.Json; +using JsonSubTypes; +using Newtonsoft.Json; using System.Collections.Generic; -using static SOMDocManager; /// <summary> /// Implements REST/JSON API @@ -18,7 +18,7 @@ public class ScrollApplicationInfo public ScrollApplicationCheckingError[] errors; [JsonProperty("acquiredFacts")] - public List<MMTDeclaration> acquiredFacts; + public List<MMTFact> acquiredFacts; } /// <summary>Response to "POST /scroll/dynamic" using <see cref="ScrollApplication"/></summary> @@ -63,6 +63,129 @@ public FactReference(string uri) } } + [JsonConverter(typeof(JsonSubtypes), "kind")] + [JsonSubtypes.KnownSubType(typeof(MMTGeneralFact), "general")] + [JsonSubtypes.KnownSubType(typeof(MMTValueFact), "veq")] + public abstract class MMTFact + { + [JsonProperty("kind")] + public abstract string kind { get; } + + [JsonProperty("label")] + public string label; + + [JsonProperty("ref")] + public FactReference @ref; + + public static MMTFact FromJson(string json) + { + MMTFact mmtDecl = JsonConvert.DeserializeObject<MMTFact>(json); + mmtDecl.label ??= string.Empty; + + return mmtDecl; + } + + public string ToJson() + { + label ??= string.Empty; + return JsonConvert.SerializeObject(this); + } + + public abstract string getType(); + + public abstract string getApplicant(); + } + + /// <summary>Class for facts without values, e.g. Points</summary> + public class MMTGeneralFact : MMTFact + { + public override string kind => "general"; + + [JsonProperty("tp")] + public SOMDoc type; + [JsonProperty("df")] + public SOMDoc defines; + + [JsonConstructor] + private MMTGeneralFact() { } + + /// <summary>Constructor used for sending new declarations to mmt</summary> + public MMTGeneralFact(string label, SOMDoc type, SOMDoc defines) + { + this.label = label; + this.type = type; + this.defines = defines; + } + + public override string getType() + { + return type switch + { + OMS oMS => oMS.uri, + OMA oMA => ((oMA.arguments[0] as OMA).applicant as OMS).uri, + _ => null + }; + } + + public override string getApplicant() + { + return defines switch + { + OMA oMA when oMA.applicant is OMS oMS => oMS.uri, + _ => null + }; + } + } + + /// <summary>Class for facts with values, e.g. Distances or Angles</summary> + public class MMTValueFact : MMTFact + { + public override string kind => "veq"; + + [JsonProperty("lhs")] + public SOMDoc lhs; + + [JsonProperty("valueTp")] + public SOMDoc valueType; + + [JsonProperty("value")] + public SOMDoc value; + + [JsonProperty("proof")] + public SOMDoc proof; + + [JsonConstructor] + private MMTValueFact() { } + + /// <summary>Constructor used for sending new declarations to mmt</summary> + public MMTValueFact(string label, SOMDoc lhs, SOMDoc valueType, SOMDoc value, SOMDoc proof = null) + { + this.label = label; + this.lhs = lhs; + this.valueType = valueType; + this.value = value; + this.proof = proof; + } + + public override string getType() + { + return lhs switch + { + OMA oMA when oMA.applicant is OMS oMS => oMS.uri, + _ => null + }; + } + + public override string getApplicant() + { + return lhs switch + { + OMA oMA when oMA.applicant is OMS oMS => oMS.uri, + _ => null + }; + } + } + public class Scroll { /// <summary>MMT URI to theory declaring the scroll</summary> @@ -79,11 +202,11 @@ public class Scroll /// <summary>array of facts; facts that the scroll required you to give for scroll application</summary> [JsonProperty("requiredFacts")] - public List<MMTDeclaration> requiredFacts; + public List<MMTFact> requiredFacts; /// <summary>array of facts; facts that the scroll gives you upon successful scroll application</summary> [JsonProperty("acquiredFacts")] - public List<MMTDeclaration> acquiredFacts; + public List<MMTFact> acquiredFacts; } public class ScrollAssignment @@ -141,11 +264,4 @@ public class ScrollApplicationCheckingError [JsonProperty("fact")] public FactReference fact; } - - //TODO: Ist das Kunst oder kann das weg? - public class ScrollTheoryReference - { - public string problemTheory; - public string solutionTheory; - } } \ No newline at end of file diff --git a/Assets/Scripts/InventoryStuff/Scroll.cs.meta b/Assets/Scripts/MMTServer/CommunicationProtocoll/Endpoints.cs.meta similarity index 100% rename from Assets/Scripts/InventoryStuff/Scroll.cs.meta rename to Assets/Scripts/MMTServer/CommunicationProtocoll/Endpoints.cs.meta diff --git a/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs b/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs new file mode 100644 index 0000000000000000000000000000000000000000..609c662cc11f6a3d5a26d40e310f47e3e46c57c9 --- /dev/null +++ b/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs @@ -0,0 +1,190 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace REST_JSON_API +{ + public static class MMTConstants + { + public static readonly string Point = "http://mathhub.info/MitM/core/geometry?3DGeometry?point"; + 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 OnLine = "http://mathhub.info/MitM/core/geometry?Geometry/Common?onLine"; + public static readonly string Ded = "http://mathhub.info/MitM/Foundation?Logic?ded"; + public static readonly string Eq = "http://mathhub.info/MitM/Foundation?Logic?eq"; + public static readonly string Metric = "http://mathhub.info/MitM/core/geometry?Geometry/Common?metric"; + public static readonly string Angle = "http://mathhub.info/MitM/core/geometry?Geometry/Common?angle_between"; + public static readonly string Sketch = "http://mathhub.info/MitM/Foundation?InformalProofs?proofsketch"; + public static readonly string RealLit = "http://mathhub.info/MitM/Foundation?RealLiterals?real_lit"; + + public static readonly string ParallelLine = "http://mathhub.info/MitM/core/geometry?Geometry/Common?parallelLine"; + //public static readonly string RectangleFact = "http://mathhub.info/FrameIT/frameworld?FrameITRectangles?rectangleType"; + //public static readonly string RectangleFactmk = "http://mathhub.info/FrameIT/frameworld?FrameITRectangles?mkRectangle"; + + public static readonly string CircleType3d = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?circleType3D"; + public static readonly string MkCircle3d = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?circle3D"; + public static readonly string TriangleMiddlePoint = "http://mathhub.info/FrameIT/frameworld?FrameITTriangles?triangleMidPointWrapper"; + public static readonly string RadiusCircleMetric = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?circleRadius"; + + public static readonly string AreaCircle = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?areaCircle"; + public static readonly string VolumeCone = "http://mathhub.info/FrameIT/frameworld?FrameITCone?volumeCone"; + public static readonly string ConeOfCircleApex = "http://mathhub.info/FrameIT/frameworld?FrameITCone?circleConeOf"; + + public static readonly string ParametrizedPlane = "http://mathhub.info/MitM/core/geometry?Planes?ParametrizedPlane"; + public static readonly string pointNormalPlane = "http://mathhub.info/MitM/core/geometry?Planes?pointNormalPlane"; + public static readonly string OnCircle = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?pointOnCircle"; + public static readonly string AnglePlaneLine = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?angleCircleLine"; + public static readonly string OrthoCircleLine = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?orthogonalCircleLine"; + + public static readonly string TruncatedVolumeCone = "http://mathhub.info/FrameIT/frameworld?FrameITCone?truncatedConeVolume"; + public static readonly string CylinderVolume = "http://mathhub.info/FrameIT/frameworld?FrameITCylinder?cylinderVolume"; + public static readonly string EqualityCircles = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?equalityCircles"; + public static readonly string UnEqualityCircles = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?unequalityCircles"; + + public static readonly string ParallelCircles = "http://mathhub.info/FrameIT/frameworld?FrameITCone?parallelCircles"; + public static readonly string RightAngle = "http://mathhub.info/FrameIT/frameworld?FrameITBasics?rightAngle"; + + public static readonly string AttachedPositionFunction = "0SET_IN_MMTConstants!"; + public static readonly string FunctionCallFact = "1SET_IN_MMTConstants!"; + public static readonly string FunctionFact = "2SET_IN_MMTConstants!"; + + 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 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 ListEnd = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?nil_constant"; + + public static readonly string Sin = "Sin"; + public static readonly string Cos = "Cos"; + public static readonly string Add = "Add"; + public static readonly string Divide = "Divide"; + public static readonly string Multiply = "Multiply"; + public static readonly string Subtract = "Subtract"; + public static readonly string SquareRoot = "SquareRoot"; + //public static readonly string MakeUnityEngineVector3 = "UnityEngine.Vector3"; + public static readonly string MakeObjectArray = "MakeObjectArray"; + + + public const string ScrollOppositeLen = "http://mathhub.info/FrameIT/frameworld?OppositeLen"; + public const string ScrollSupplementaryAngles = "http://mathhub.info/FrameIT/frameworld?SupplementaryAngles"; + public const string ScrollAngleSum = "http://mathhub.info/FrameIT/frameworld?AngleSum"; + public const string ScrollPythagoras = "http://mathhub.info/FrameIT/frameworld?Pythagoras"; + public const string ScrollCylinderVolumeScroll = "http://mathhub.info/FrameIT/frameworld?CylinderVolumeScroll"; + public const string ScrollCircleLineAngleToAngleScroll = "http://mathhub.info/FrameIT/frameworld?CircleLineAngleToAngleScroll"; + public const string ScrollMidpoint = "http://mathhub.info/FrameIT/frameworld?Midpoint"; + public const string ScrollCircleScroll = "http://mathhub.info/FrameIT/frameworld?CircleScroll"; + public const string ScrollCircleLineAngleScroll = "http://mathhub.info/FrameIT/frameworld?CircleLineAngleScroll"; + public const string ScrollCircleAreaScroll = "http://mathhub.info/FrameIT/frameworld?CircleAreaScroll"; + public const string ScrollConeVolumeScroll = "http://mathhub.info/FrameIT/frameworld?ConeVolumeScroll"; + public const string ScrollTruncatedConeVolumeScroll = "http://mathhub.info/FrameIT/frameworld?TruncatedConeVolumeScroll"; + public const string ScrollCannonBall = "http://mathhub.info/FrameIT/frameworld?BouncingScroll"; + + public static readonly IReadOnlyDictionary<string, Type> OMS_TO_TYPE = new Dictionary<string, Type>() + { + { Point, + typeof(PointFact) }, + { Metric, + typeof(LineFact) }, + { Angle, + typeof(AngleFact) }, + { Eq, + typeof(AngleFact) }, + { RightAngle, + typeof(RightAngleFact) }, + { LineType, + typeof(RayFact) }, + { LineOf, + typeof(RayFact) }, + { OnLine, + typeof(OnLineFact) }, + { ParallelLine, + typeof(ParallelLineFact) }, + { CircleType3d, + typeof(CircleFact) }, + { OnCircle, + typeof(OnCircleFact) }, + { AnglePlaneLine, + typeof(AngleCircleLineFact) }, + { RadiusCircleMetric, + typeof(RadiusFact) }, + { AreaCircle, + typeof(AreaCircleFact) }, + { OrthoCircleLine, + typeof(OrthogonalCircleLineFact) }, + { VolumeCone, + typeof(ConeVolumeFact) }, + { TruncatedVolumeCone, + typeof(TruncatedConeVolumeFact) }, + { CylinderVolume, + typeof(CylinderVolumeFact) }, + { TestType, + typeof(TestFact) }, + { EqualityCircles, + typeof(EqualCirclesFact) }, + { UnEqualityCircles, + typeof(UnEqualCirclesFact) }, + { FunctionFact, + typeof(FunctionFact) }, + { FunctionCallFact, + typeof(FunctionCallFact) }, + { AttachedPositionFunction, + typeof(AttachedPositionFunction) }, + + { RealLit, + typeof(float) }, + { Tuple, + typeof(TupelFact) }, + { ListType, + typeof(List<>) }, + + { MkCircle3d, null }, //typeof(CircleFact) }, + { ConeOfCircleApex, null }, //typeof(ConeVolumeFact) }, + + { Ded, null }, + { Sketch, null }, + { TriangleMiddlePoint, null }, + { ParametrizedPlane, null }, + { pointNormalPlane, null }, + { ParallelCircles, null }, + + { "R", + typeof(float) }, + { typeof(float).ToString(), + typeof(float) }, + { typeof(double).ToString(), + typeof(double) }, + { typeof(string).ToString(), + typeof(string) }, + { typeof(Vector3).ToString(), + typeof(Vector3) } + }; + public static readonly IReadOnlyDictionary<Type, string> TYPE_TO_OMS = OMS_TO_TYPE.ReverseKeyValInto(new() + { // **Overrides** + //{ typeof(Vector3), + // 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(); + + public static readonly IReadOnlyDictionary<string, string> HeterogenApplication_TO_TypeOF = new Dictionary<string, string> { + { Tuple, + Product }, + }; + public static readonly IReadOnlyDictionary<string, string> TypeOF_TO_HeterogenApplication = HeterogenApplication_TO_TypeOF.ReverseKeyVal(); + + 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(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs b/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs new file mode 100644 index 0000000000000000000000000000000000000000..ccf4ea2e9472ec977191b1f23648aefe49eeac4d --- /dev/null +++ b/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs @@ -0,0 +1,279 @@ +using System.Collections.Generic; +using System.Linq.Expressions; +using System; +using System.Linq; +using UnityEngine; + +namespace REST_JSON_API +{ + abstract public partial class SOMDoc + { + protected static class SOMDocToLambdaExpression<T> + { + // TODO: Populate Dictionaries + #region ExpressionDictionaries + + delegate LambdaExpression CustomFunction(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params); + private static readonly Dictionary<string, CustomFunction> MMTtoLambdaMaker = new() + { + { MMTConstants.Sin, + MakeSin }, + { MMTConstants.Cos, + MakeCos }, + { MMTConstants.SquareRoot, + MakeCos }, + { MMTConstants.Tuple, + MakeTupel }, + { MMTConstants.MakeObjectArray, + MakeObjArray }, + { "InstantList", + MakeInstantList }, + { MMTConstants.ListEnd, + MakeListEnd }, + { MMTConstants.ListLiteral, + InsertFrontListLiteral }, + { MMTConstants.ListType, + Identity0 }, + }; + + private static readonly Dictionary<string, ExpressionType> MMTtoBinaryExpressionType = new() + { + { MMTConstants.Add, + ExpressionType.Add}, + { "AddAssign", + ExpressionType.AddAssign}, + { "AddAssignChecked", + ExpressionType.AddAssignChecked}, + { "AddChecked", + ExpressionType.AddChecked}, + { "And", + ExpressionType.And}, + { "AndAlso", + ExpressionType.AndAlso}, + { "AndAssign", + ExpressionType.AndAssign}, + { "Assign", + ExpressionType.Assign}, + { MMTConstants.Divide, + ExpressionType.Divide}, + { "DivideAssign", + ExpressionType.DivideAssign}, + { "Equal", + ExpressionType.Equal}, + { "ExclusiveOr", + ExpressionType.ExclusiveOr}, + { "ExclusiveOrAssign", + ExpressionType.ExclusiveOrAssign}, + { "GreaterThan", + ExpressionType.GreaterThan}, + { "GreaterThanOrEqual", + ExpressionType.GreaterThanOrEqual}, + { "LeftShift", + ExpressionType.LeftShift}, + { "LeftShiftAssign", + ExpressionType.LeftShiftAssign}, + { "LessThan", + ExpressionType.LessThan}, + { "LessThanOrEqual", + ExpressionType.LessThanOrEqual}, + { "Modulo", + ExpressionType.Modulo}, + { "ModuloAssign", + ExpressionType.ModuloAssign}, + { MMTConstants.Multiply, + ExpressionType.Multiply}, + { "MultiplyAssign", + ExpressionType.MultiplyAssign}, + { "MultiplyAssignChecked", + ExpressionType.MultiplyAssignChecked}, + { "MultiplyChecked", + ExpressionType.MultiplyChecked}, + { "NotEqual", + ExpressionType.NotEqual}, + { "Or", + ExpressionType.Or}, + { "OrAssign", + ExpressionType.OrAssign}, + { "OrElse", + ExpressionType.OrElse}, + { "Power", + ExpressionType.Power}, + { "PowerAssign", + ExpressionType.PowerAssign}, + { "RightShift", + ExpressionType.RightShift}, + { "RightShiftAssign", + ExpressionType.RightShiftAssign}, + { MMTConstants.Subtract, + ExpressionType.Subtract}, + { "SubtractAssign", + ExpressionType.SubtractAssign}, + { "SubtractAssignChecked", + ExpressionType.SubtractAssignChecked}, + { "SubtractChecked", + ExpressionType.SubtractChecked}, + }; + + private static readonly Dictionary<string, ExpressionType> MMTtoUnaryExpressionType = new() + { + //{ "Constant", // Not Unary + // ExpressionType.Constant}, + { "Convert", + ExpressionType.Convert}, + { "ConvertChecked", + ExpressionType.ConvertChecked}, + { "Decrement", + ExpressionType.Decrement}, + { "Increment", + ExpressionType.Increment}, + { "Negate", + ExpressionType.Negate}, + { "NegateChecked", + ExpressionType.NegateChecked}, + { "Not", + ExpressionType.Not}, + { "OnesComplement", + ExpressionType.OnesComplement}, + { "PostDecrementAssign", + ExpressionType.PostDecrementAssign}, + { "PostIncrementAssign", + ExpressionType.PostIncrementAssign}, + { "PreDecrementAssign", + ExpressionType.PreDecrementAssign}, + { "PreIncrementAssign", + ExpressionType.PreIncrementAssign}, + { "UnaryPlus", + ExpressionType.UnaryPlus}, + }; + + #endregion ExpressionDictionaries + + //TODO: case ((f->x)->y) instead of assumed (f->(x->y)) + public static LambdaExpression MakeLambdaExpression(string URI, LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + { + void ThrowArgumentException(ExpressionType expression_cast, int expected) + { + throw new ArgumentException(string.Format( + "\"Wrong number of Arguments. Required: {2}. Supplied: {3}.\\n\\tFor URI:\\\"{0}\\\"\\n\\tmapped to:\\\"{1}\\\"\"", + URI, expression_cast, expected, lambda_applicant.Count() + )); + } + + ParameterExpression[] lambda_params = + lambda_applicant + .SelectMany(l => l.Parameters) + .ToArray(); //PERF: .ToList().Sort() => .BinarySearch; //Too much overhead? + ParameterExpression[] found_bound_params = + bound_params + .Where(p => lambda_params.Contains(p)) + .ToArray(); + + if (MMTtoUnaryExpressionType.TryGetValue(URI, out var unnary_type)) + { + if (found_bound_params.Count() < 1) + ThrowArgumentException(unnary_type, 1); + + Type UnarySecondArgument = found_bound_params.Count() < 2 ? null : found_bound_params[1].Type; + + return Expression.Lambda(Expression.MakeUnary(unnary_type, lambda_applicant[0].Body, UnarySecondArgument), found_bound_params); + } + else + if (MMTtoBinaryExpressionType.TryGetValue(URI, out var binary_type)) + { + if (lambda_applicant.Count() != 2) + ThrowArgumentException(binary_type, 2); + + return Expression.Lambda(Expression.MakeBinary(binary_type, lambda_applicant[0].Body, lambda_applicant[1].Body), found_bound_params); + } + else + if (MMTtoLambdaMaker.TryGetValue(URI, out var lamda_maker)) + { + return lamda_maker(lambda_applicant, lambda_arguments, found_bound_params); + } + else + if (MMTConstants.OMS_TO_TYPE.TryGetValue(URI, out Type type)) + { + return Expression.Lambda(Expression.Default(type), null); + } + + throw new NotImplementedException("Could not map URI: \"" + URI + "\""); + } + + private static LambdaExpression ExpresionFuncToLambda(LambdaExpression func, string name, LambdaExpression[] args_lamda, ParameterExpression[] bound_params, uint nTargs_fallback) + => Expression.Lambda(Expression.Invoke(func, args_lamda.Select(l => l.Body)), name, bound_params); + + private static LambdaExpression ParseFuncUUToExpression<U>(Func<U, U> func) + => (Expression<Func<U, U>>)((U x) => func(x)); + + private static LambdaExpression MakeSin(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + => ExpresionFuncToLambda( + lambda_applicant[0].ReturnType == typeof(float) ? ParseFuncUUToExpression<float>(MathF.Sin) + : lambda_applicant[0].ReturnType == typeof(double) ? ParseFuncUUToExpression<double>(Math.Sin) + : throw new NotImplementedException("Sinus for " + lambda_applicant[0].ReturnType), + + "Sin", lambda_arguments.Length > 0 ? lambda_arguments : lambda_applicant, bound_params, 1 + ); + + private static LambdaExpression MakeCos(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + => ExpresionFuncToLambda( + lambda_applicant[0].ReturnType == typeof(float) ? ParseFuncUUToExpression<float>(MathF.Cos) + : lambda_applicant[0].ReturnType == typeof(double) ? ParseFuncUUToExpression<double>(Math.Cos) + : throw new NotImplementedException("Cosinus for " + lambda_applicant[0].ReturnType), + + "Cos", lambda_arguments.Length > 0 ? lambda_arguments : lambda_applicant, bound_params, 1 + ); + + private static LambdaExpression MakeTupel(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + { + if (lambda_applicant.Length == 3 + && lambda_applicant.All(l => l.ReturnType == typeof(float))) + + return ExpresionFuncToLambda( + (Expression<Func<float, float, float, Vector3>>)((x, y, z) => new Vector3(x, y, z)), + "UnityEngineVector3", lambda_applicant, bound_params, 3 + ); + + return MakeObjArray(lambda_applicant, lambda_arguments, bound_params); + } + + private static LambdaExpression MakeObjArray(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + => Expression.Lambda( + Expression.NewArrayInit( + typeof(object), + lambda_applicant.Select(l => Expression.Convert(l.Body, typeof(object))) + ), + bound_params + ); + + private static LambdaExpression MakeInstantList(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + => Expression.Lambda( + Expression.ListInit( + Expression.New(typeof(List<>).MakeGenericType(lambda_applicant[0].ReturnType)), + lambda_arguments.Select(l => l.Body) // Expression.Convert(l.Body, lambda_applicant[0].ReturnType)) + ), + bound_params + ); + + private static LambdaExpression InsertFrontListLiteral(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + => Expression.Lambda( + Expression.Call( + lambda_applicant[0].Body, + lambda_applicant[0].ReturnType.GetMethod("Insert"), + Expression.Constant(0, typeof(int)), + lambda_applicant[1].Body + ), + bound_params + ); + + private static LambdaExpression MakeListEnd(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + => Expression.Lambda( + Expression.New(typeof(List<>).MakeGenericType(lambda_applicant[0].ReturnType)), + null + ); + + private static LambdaExpression Identity0(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + => lambda_applicant[0]; + + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/SOMDocManager.cs.meta b/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs.meta similarity index 100% rename from Assets/Scripts/SOMDocManager.cs.meta rename to Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs.meta diff --git a/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocs.cs b/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocs.cs new file mode 100644 index 0000000000000000000000000000000000000000..c90ab80734a8c3e47d4d6896666ae36673128efa --- /dev/null +++ b/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocs.cs @@ -0,0 +1,486 @@ +using JsonSubTypes; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Linq; +using System; +using UnityEngine; +using MoreLinq; + +namespace REST_JSON_API +{ + [JsonConverter(typeof(JsonSubtypes), "kind")] + [JsonSubtypes.KnownSubType(typeof(OMA), "OMA")] + [JsonSubtypes.KnownSubType(typeof(OMBINDC), "OMBINDC")] + [JsonSubtypes.KnownSubType(typeof(OMS), "OMS")] + [JsonSubtypes.KnownSubType(typeof(OMSTR), "OMSTR")] + [JsonSubtypes.KnownSubType(typeof(OMF), "OMF")] + [JsonSubtypes.KnownSubType(typeof(OMV), "OMV")] + [JsonSubtypes.KnownSubType(typeof(RAW), "RAW")] + //[JsonSubtypes.KnownSubType(typeof(OMC<T>), "OMC<" + typeof(T) + ">")] + [JsonSubtypes.KnownSubType(typeof(OMC<Vector3>), "OMC<UnityEngine.Vector3>")] + [JsonSubtypes.KnownSubType(typeof(OMC<float>), "OMC<System.Single>")] + [JsonSubtypes.KnownSubType(typeof(OMC<double>), "OMC<System.Double>")] + abstract public partial class SOMDoc + { + public string kind; + + 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) + => sd1 != null && sd2 != null + && sd1.Equivalent(sd2); + + public abstract bool Equivalent(SOMDoc sd2); + + public LambdaExpression PartialInvokeCastingLambdaExpression(out Type[] signature_args, object[] callArgs = null, bool[] useArgs = null) + { + LambdaExpression lambda_orig = GetLambdaExpression(); + + signature_args = new Type[lambda_orig.Parameters.Count + 1]; + + ParameterExpression object_arr = Expression.Parameter(typeof(object[]), "PARAMS_Arr"); + Expression[] cast_new_to_signature = new Expression[lambda_orig.Parameters.Count]; + + int n_params = 0; + for (int i = 0; i < lambda_orig.Parameters.Count; i++) + { + if (callArgs != null && callArgs.Length < i + && (useArgs == null || (useArgs.Length < i && useArgs[i]))) + { + cast_new_to_signature[i] = + Expression.Constant(callArgs[i], lambda_orig.Parameters[i].Type); + continue; + } + + signature_args[n_params++] = lambda_orig.Parameters[i].Type; + + cast_new_to_signature[i] = + Expression.Convert( + Expression.ArrayIndex( + object_arr, + Expression.Constant(i) + ), + lambda_orig.Parameters[i].Type + ); + } + signature_args[n_params] = lambda_orig.ReturnType; + signature_args = signature_args.Slice(0, n_params + 1).ToArray(); + + return Expression.Lambda( + typeof(Array).IsAssignableFrom(lambda_orig.ReturnType) + ? Expression.Convert( + Expression.Invoke(lambda_orig, cast_new_to_signature), + typeof(object[])) + : Expression.NewArrayInit( + typeof(object), + new Expression[] { Expression.Convert(Expression.Invoke(lambda_orig, cast_new_to_signature), typeof(object)) }), + + object_arr + ); + } + + public LambdaExpression GetLambdaExpression() + => GetLambdaExpression(new LambdaExpression[0], new LambdaExpression[0], new ParameterExpression[0]); + + protected internal abstract LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params); + + public abstract override string ToString(); + + public abstract SOMDoc MapURIs(Dictionary<string, string> old_to_new); + + #region MakeMMT_OMS_URItoSOMDoc + public static OMA MakeTupel(Vector3 vec) + => MakeTupel(new[] { + new OMF(vec.x), + new OMF(vec.y), + new OMF(vec.z), + }); + + public static OMA MakeTupel(SOMDoc[] args) + => new( + new OMS(MMTConstants.Tuple), + args + ); + + public static OMA MakeShallowList(SOMDoc[] args) + => new( + new OMS(MMTConstants.ListApplicant), + args + ); + + public static OMA MakeDeepList(SOMDoc[] args, SOMDoc typeURI) + { + SOMDoc[] end_of_list = new SOMDoc[] { + new OMA( + new OMS(MMTConstants.ListEnd), + new[] { + typeURI, + } + ), + args.Length == 0 + ? null + : args[^1] + }; + + if (args.Length == 0) + end_of_list = end_of_list[..^0]; + + SOMDoc defines = new OMA( + new OMS(MMTConstants.ListLiteral), + end_of_list + ); + + for (int i = args.Length - 2; i >= 0; i--) + { + defines = new OMA( + new OMS(MMTConstants.ListLiteral), + new[] { + defines, + args[i], + }); + } + + SOMDoc type = new OMA( + new OMS(MMTConstants.ListApplicant), + new[] { typeURI } + ); + + return new OMA(type, new[] { defines }); + } + #endregion MakeMMT_OMS_URItoSOMDoc + } + + public abstract class SOMDocCRTP<T> : SOMDoc where T : SOMDocCRTP<T> + { + protected SOMDocCRTP() : base() { } + + public override bool Equivalent(SOMDoc sd2) + => this.GetType() == sd2.GetType() && (this as T).EquivalentWrapped(sd2 as T); + + protected abstract bool EquivalentWrapped(T sd2); + + public override SOMDoc MapURIs(Dictionary<string, string> old_to_new) + => MapURIsWrapped(old_to_new); + + protected abstract T MapURIsWrapped(Dictionary<string, string> old_to_new); + } + + public class OMBINDC : SOMDocCRTP<OMBINDC> + { + public new string kind = "OMBINDC"; + + public string name; + + public SOMDoc lambdabody; + + /// <summary>@Type of this variable</summary> + [JsonIgnore] + public Type type; + + /// <summary>Enables (especially <see cref="JsonConverter"/>) to read and set <see cref="type"/> by its <c>string</c> representation.</summary> + public string typeString + { + get => MMTConstants.TYPE_TO_OMS[type]; + set => type = MMTConstants.OMS_TO_TYPE[value]; + } + + [JsonConstructor] + public OMBINDC(string name, string typeString, SOMDoc lambdabody) : base() + { + this.name = name; + this.typeString = typeString; + this.lambdabody = lambdabody; + } + + protected internal override SOMDoc TypeOf(SOMDoc[] args) + => throw new NotImplementedException(); + + public OMBINDC(string name, Type type, SOMDoc lambdabody) : base() + { + this.name = name; + this.type = type; + this.lambdabody = lambdabody; + } + + protected override bool EquivalentWrapped(OMBINDC sd2) + => this.type == sd2.type + && this.name.Equals(sd2.name) + && this.lambdabody.Equivalent(sd2.lambdabody); + + protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + { + ParameterExpression[] bind_me = bound_params.ShallowCloneAppend( + new[] { Expression.Parameter(type, name) } + ); + + return lambdabody.GetLambdaExpression(lambda_applicant, lambda_arguments, bind_me); + } + + public override string ToString() + => "OMBINDC(" + name + ", " + typeString + ")->"; + + protected override OMBINDC MapURIsWrapped(Dictionary<string, string> old_to_new) + => new(name, type, lambdabody.MapURIs(old_to_new)); + } + + public class OMA : SOMDocCRTP<OMA> + { + public new string kind = "OMA"; + + public SOMDoc applicant; + public SOMDoc[] arguments; + + [JsonConstructor] + public OMA(SOMDoc applicant, SOMDoc[] arguments) : base() + { + this.applicant = applicant; + this.arguments = arguments; + } + + protected internal override SOMDoc TypeOf(SOMDoc[] args) + => applicant.TypeOf(arguments.Select(a => a.TypeOf()).ToArray()); + + protected override bool EquivalentWrapped(OMA sd2) + => Equivalent(this.applicant, sd2.applicant) + && this.arguments + .Zip(sd2.arguments, (arg1, arg2) => Equivalent(arg1, arg2)) + .All(b => b); + + protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant_paps, LambdaExpression[] lambda_applicant_grands, ParameterExpression[] bound_params) + => applicant.GetLambdaExpression( + arguments.Select(arg => arg.GetLambdaExpression(new LambdaExpression[0], new LambdaExpression[0], bound_params)).ToArray(), + lambda_applicant_paps, + bound_params + ); + + public override string ToString() + => applicant.ToString() + "(" + string.Join(", ", arguments.Select(a => a.ToString())) + ")"; + + protected override OMA MapURIsWrapped(Dictionary<string, string> old_to_new) + => new OMA( + applicant.MapURIs(old_to_new), + arguments.Select(arg => arg.MapURIs(old_to_new)).ToArray() + ); + } + + public class OMS : SOMDocCRTP<OMS> + { + public new string kind = "OMS"; + + public string uri; + + [JsonConstructor] + public OMS(string uri) : base() + { + this.uri = uri; + } + + protected internal override SOMDoc TypeOf(SOMDoc[] args) + { + if (FactOrganizer.AllFacts.TryGetValue(uri, out Fact found)) + return new OMS(MMTConstants.TYPE_TO_OMS[found.GetType()]); + + if (MMTConstants.HeterogenApplication_TO_TypeOF.TryGetValue(uri, out string type)) + return new OMA( + new OMS(type), + args + ); + + if (MMTConstants.HomogenApplication_TO_TypeOF.TryGetValue(uri, out type)) + return new OMA( + new OMS(type), + new[] { args[0] } + ); + + if (MMTConstants.URI_TO_TypeOF.TryGetValue(uri, out type)) + return new OMS(type); + + throw new NotImplementedException(); + } + + protected override bool EquivalentWrapped(OMS sd2) + => this.uri == sd2.uri; + + protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + => SOMDocToLambdaExpression<float>.MakeLambdaExpression(uri, lambda_applicant, lambda_arguments, bound_params); + + public override string ToString() + => uri; + + protected override OMS MapURIsWrapped(Dictionary<string, string> old_to_new) + { + if (!old_to_new.TryGetValue(uri, out string new_uri)) + new_uri = uri; + + return new OMS(new_uri); + } + } + + public class OMSTR : SOMDocCRTP<OMSTR> + { + public new string kind = "OMSTR"; + + [JsonProperty("float")] + public string s; + + [JsonConstructor] + public OMSTR(string s) : base() + { + this.s = s; + } + + protected internal override SOMDoc TypeOf(SOMDoc[] args) + => throw new NotImplementedException(); + + protected override bool EquivalentWrapped(OMSTR sd2) + => this.s == sd2.s; + + protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + => Expression.Lambda(Expression.Constant(s, typeof(string)), null); + + public override string ToString() + => s; + + protected override OMSTR MapURIsWrapped(Dictionary<string, string> old_to_new) + => (OMSTR)this.MemberwiseClone(); + } + + public class OMF : SOMDocCRTP<OMF> + { + public new string kind = "OMF"; + + [JsonProperty("float")] + public float @float; + + [JsonConstructor] + public OMF(float f) : base() + { + this.@float = f; + } + + protected internal override SOMDoc TypeOf(SOMDoc[] args) + => new OMS(MMTConstants.RealLit); + + protected override bool EquivalentWrapped(OMF sd2) + => Mathf.Approximately(@float, sd2.@float); + + protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + => Expression.Lambda(Expression.Constant(@float, typeof(float)), null); + + public override string ToString() + => @float.ToString(); + + protected override OMF MapURIsWrapped(Dictionary<string, string> old_to_new) + => (OMF)this.MemberwiseClone(); + } + + public class OMC<T> : SOMDocCRTP<OMC<T>> + { + public new string kind = "OMC<" + typeof(T) + ">"; + + public T value; + + [JsonConstructor] + public OMC(T value) : base() + { + this.value = value; + } + + protected internal override SOMDoc TypeOf(SOMDoc[] args) + => new OMS(MMTConstants.TYPE_TO_OMS[typeof(T)]); + + protected override bool EquivalentWrapped(OMC<T> sd2) + { + Debug.LogWarning("Cannot check Equivalency for " + this.GetType() + "; only whether it's exact!"); + return this.value.Equals(value); + } + + protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + => Expression.Lambda(Expression.Constant(value, typeof(T)), null); + + public override string ToString() + => "C_" + typeof(T) + "(" + value.ToString() + ")"; + + protected override OMC<T> MapURIsWrapped(Dictionary<string, string> old_to_new) + => (OMC<T>)this.MemberwiseClone(); + } + + public class OMV : SOMDocCRTP<OMV> + { + public new string kind = "OMV"; + + public string name; + + [JsonConstructor] + public OMV(string name) : base() + { + this.name = name; + } + + protected internal override SOMDoc TypeOf(SOMDoc[] args) + => throw new NotImplementedException(); + + protected override bool EquivalentWrapped(OMV sd2) + => this.name == sd2.name; + + protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + { + ParameterExpression v = bound_params.FirstOrDefault(param => param.Name.Equals(name)); + if (v == null) + { + Debug.LogErrorFormat("Unable to find {0} for {1} with name: {2}", nameof(OMBINDC), nameof(OMV), name); + return Expression.Lambda(Expression.Empty(), null); + } + else + return Expression.Lambda(v, new[] { v }); + } + + public override string ToString() + => "Variable_" + "(" + name + ")"; + + protected override OMV MapURIsWrapped(Dictionary<string, string> old_to_new) + => (OMV)this.MemberwiseClone(); + } + + public class RAW : SOMDocCRTP<RAW> + { + public new string kind = "RAW"; + + public string xml; + + [JsonConstructor] + public RAW(string xml) : base() + { + this.xml = xml; + } + + protected internal override SOMDoc TypeOf(SOMDoc[] args) + => throw new NotImplementedException(); + + protected override RAW MapURIsWrapped(Dictionary<string, string> old_to_new) + { + string copy = xml; + foreach (KeyValuePair<string, string> KeyVal in old_to_new) + copy = copy.Replace(KeyVal.Key, KeyVal.Value); + + return new RAW(copy); + } + + public override string ToString() + => xml; + + protected override bool EquivalentWrapped(RAW sd2) + => throw new NotImplementedException(); //xml == sd2.xml; // only exact + + protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/SOMDocManager.cs b/Assets/Scripts/SOMDocManager.cs deleted file mode 100644 index 8718b87ff91c4d47661166a30aaecd4d1efa83af..0000000000000000000000000000000000000000 --- a/Assets/Scripts/SOMDocManager.cs +++ /dev/null @@ -1,1053 +0,0 @@ -using System.Collections.Generic; -using Newtonsoft.Json; -using JsonSubTypes; -using System.Linq.Expressions; -using System; -using System.Linq; -using MoreLinq; -using UnityEngine; -using REST_JSON_API; - -public static class SOMDocManager -{ - public static class MMT_OMS_URI - { - public static readonly string Point = "http://mathhub.info/MitM/core/geometry?3DGeometry?point"; - 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 OnLine = "http://mathhub.info/MitM/core/geometry?Geometry/Common?onLine"; - public static readonly string Ded = "http://mathhub.info/MitM/Foundation?Logic?ded"; - public static readonly string Eq = "http://mathhub.info/MitM/Foundation?Logic?eq"; - public static readonly string Metric = "http://mathhub.info/MitM/core/geometry?Geometry/Common?metric"; - public static readonly string Angle = "http://mathhub.info/MitM/core/geometry?Geometry/Common?angle_between"; - public static readonly string Sketch = "http://mathhub.info/MitM/Foundation?InformalProofs?proofsketch"; - public static readonly string RealLit = "http://mathhub.info/MitM/Foundation?RealLiterals?real_lit"; - - public static readonly string ParallelLine = "http://mathhub.info/MitM/core/geometry?Geometry/Common?parallelLine"; - //public static readonly string RectangleFact = "http://mathhub.info/FrameIT/frameworld?FrameITRectangles?rectangleType"; - //public static readonly string RectangleFactmk = "http://mathhub.info/FrameIT/frameworld?FrameITRectangles?mkRectangle"; - - public static readonly string CircleType3d = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?circleType3D"; - public static readonly string MkCircle3d = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?circle3D"; - public static readonly string TriangleMiddlePoint = "http://mathhub.info/FrameIT/frameworld?FrameITTriangles?triangleMidPointWrapper"; - public static readonly string RadiusCircleMetric = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?circleRadius"; - - public static readonly string AreaCircle = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?areaCircle"; - public static readonly string VolumeCone = "http://mathhub.info/FrameIT/frameworld?FrameITCone?volumeCone"; - public static readonly string ConeOfCircleApex = "http://mathhub.info/FrameIT/frameworld?FrameITCone?circleConeOf"; - - public static readonly string ParametrizedPlane = "http://mathhub.info/MitM/core/geometry?Planes?ParametrizedPlane"; - public static readonly string pointNormalPlane = "http://mathhub.info/MitM/core/geometry?Planes?pointNormalPlane"; - public static readonly string OnCircle = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?pointOnCircle"; - public static readonly string AnglePlaneLine = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?angleCircleLine"; - public static readonly string OrthoCircleLine = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?orthogonalCircleLine"; - - public static readonly string TruncatedVolumeCone = "http://mathhub.info/FrameIT/frameworld?FrameITCone?truncatedConeVolume"; - public static readonly string CylinderVolume = "http://mathhub.info/FrameIT/frameworld?FrameITCylinder?cylinderVolume"; - public static readonly string EqualityCircles = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?equalityCircles"; - public static readonly string UnEqualityCircles = "http://mathhub.info/FrameIT/frameworld?FrameITCircle?unequalityCircles"; - - public static readonly string ParallelCircles = "http://mathhub.info/FrameIT/frameworld?FrameITCone?parallelCircles"; - public static readonly string RightAngle = "http://mathhub.info/FrameIT/frameworld?FrameITBasics?rightAngle"; - - public static readonly string AttachedPositionFunction = "0SET_IN_SOMDocManager!"; - public static readonly string FunctionCallFact = "1SET_IN_SOMDocManager!"; - public static readonly string FunctionFact = "2SET_IN_SOMDocManager!"; - - 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 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 ListEnd = "http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?nil_constant"; - - public static readonly string Sin = "Sin"; - public static readonly string Cos = "Cos"; - public static readonly string Add = "Add"; - public static readonly string Divide = "Divide"; - public static readonly string Multiply = "Multiply"; - public static readonly string Subtract = "Subtract"; - public static readonly string SquareRoot = "SquareRoot"; - //public static readonly string MakeUnityEngineVector3 = "UnityEngine.Vector3"; - public static readonly string MakeObjectArray = "MakeObjectArray"; - - - public const string ScrollOppositeLen = "http://mathhub.info/FrameIT/frameworld?OppositeLen"; - public const string ScrollSupplementaryAngles = "http://mathhub.info/FrameIT/frameworld?SupplementaryAngles"; - public const string ScrollAngleSum = "http://mathhub.info/FrameIT/frameworld?AngleSum"; - public const string ScrollPythagoras = "http://mathhub.info/FrameIT/frameworld?Pythagoras"; - public const string ScrollCylinderVolumeScroll = "http://mathhub.info/FrameIT/frameworld?CylinderVolumeScroll"; - public const string ScrollCircleLineAngleToAngleScroll = "http://mathhub.info/FrameIT/frameworld?CircleLineAngleToAngleScroll"; - public const string ScrollMidpoint = "http://mathhub.info/FrameIT/frameworld?Midpoint"; - public const string ScrollCircleScroll = "http://mathhub.info/FrameIT/frameworld?CircleScroll"; - public const string ScrollCircleLineAngleScroll = "http://mathhub.info/FrameIT/frameworld?CircleLineAngleScroll"; - public const string ScrollCircleAreaScroll = "http://mathhub.info/FrameIT/frameworld?CircleAreaScroll"; - public const string ScrollConeVolumeScroll = "http://mathhub.info/FrameIT/frameworld?ConeVolumeScroll"; - public const string ScrollTruncatedConeVolumeScroll = "http://mathhub.info/FrameIT/frameworld?TruncatedConeVolumeScroll"; - public const string ScrollCannonBall = "http://mathhub.info/FrameIT/frameworld?BouncingScroll"; - - public static readonly IReadOnlyDictionary<string, Type> OMS_TO_TYPE = new Dictionary<string, Type>() - { - { Point, - typeof(PointFact) }, - { Metric, - typeof(LineFact) }, - { Angle, - typeof(AngleFact) }, - { Eq, - typeof(AngleFact) }, - { RightAngle, - typeof(RightAngleFact) }, - { LineType, - typeof(RayFact) }, - { LineOf, - typeof(RayFact) }, - { OnLine, - typeof(OnLineFact) }, - { ParallelLine, - typeof(ParallelLineFact) }, - { CircleType3d, - typeof(CircleFact) }, - { OnCircle, - typeof(OnCircleFact) }, - { AnglePlaneLine, - typeof(AngleCircleLineFact) }, - { RadiusCircleMetric, - typeof(RadiusFact) }, - { AreaCircle, - typeof(AreaCircleFact) }, - { OrthoCircleLine, - typeof(OrthogonalCircleLineFact) }, - { VolumeCone, - typeof(ConeVolumeFact) }, - { TruncatedVolumeCone, - typeof(TruncatedConeVolumeFact) }, - { CylinderVolume, - typeof(CylinderVolumeFact) }, - { TestType, - typeof(TestFact) }, - { EqualityCircles, - typeof(EqualCirclesFact) }, - { UnEqualityCircles, - typeof(UnEqualCirclesFact) }, - { FunctionFact, - typeof(FunctionFact) }, - { FunctionCallFact, - typeof(FunctionCallFact) }, - { AttachedPositionFunction, - typeof(AttachedPositionFunction) }, - - { RealLit, - typeof(float) }, - { Tuple, - typeof(TupelFact) }, - { ListType, - typeof(List<>) }, - - { MkCircle3d, null }, //typeof(CircleFact) }, - { ConeOfCircleApex, null }, //typeof(ConeVolumeFact) }, - - { Ded, null }, - { Sketch, null }, - { TriangleMiddlePoint, null }, - { ParametrizedPlane, null }, - { pointNormalPlane, null }, - { ParallelCircles, null }, - - { "R", - typeof(float) }, - { typeof(float).ToString(), - typeof(float) }, - { typeof(double).ToString(), - typeof(double) }, - { typeof(string).ToString(), - typeof(string) }, - { typeof(Vector3).ToString(), - typeof(Vector3) } - }; - public static readonly IReadOnlyDictionary<Type, string> TYPE_TO_OMS = OMS_TO_TYPE.ReverseKeyValInto(new() - { // **Overrides** - //{ typeof(Vector3), - // 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(); - - public static readonly IReadOnlyDictionary<string, string> HeterogenApplication_TO_TypeOF = new Dictionary<string, string> { - { Tuple, - Product }, - }; - public static readonly IReadOnlyDictionary<string, string> TypeOF_TO_HeterogenApplication = HeterogenApplication_TO_TypeOF.ReverseKeyVal(); - - 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(); - } - - - public static class SOMDoctoLambdaExpression<T> - { - // TODO: Populate Dictionaries - #region ExpressionDictionaries - - delegate LambdaExpression CustomFunction(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params); - private static readonly Dictionary<string, CustomFunction> MMTtoLambdaMaker = new() - { - { MMT_OMS_URI.Sin, - MakeSin }, - { MMT_OMS_URI.Cos, - MakeCos }, - { MMT_OMS_URI.SquareRoot, - MakeCos }, - { MMT_OMS_URI.Tuple, - MakeTupel }, - { MMT_OMS_URI.MakeObjectArray, - MakeObjArray }, - { "InstantList", - MakeInstantList }, - { MMT_OMS_URI.ListEnd, - MakeListEnd }, - { MMT_OMS_URI.ListLiteral, - InsertFrontListLiteral }, - { MMT_OMS_URI.ListType, - Identity0 }, - }; - - private static readonly Dictionary<string, ExpressionType> MMTtoBinaryExpressionType = new() - { - { MMT_OMS_URI.Add, - ExpressionType.Add}, - { "AddAssign", - ExpressionType.AddAssign}, - { "AddAssignChecked", - ExpressionType.AddAssignChecked}, - { "AddChecked", - ExpressionType.AddChecked}, - { "And", - ExpressionType.And}, - { "AndAlso", - ExpressionType.AndAlso}, - { "AndAssign", - ExpressionType.AndAssign}, - { "Assign", - ExpressionType.Assign}, - { MMT_OMS_URI.Divide, - ExpressionType.Divide}, - { "DivideAssign", - ExpressionType.DivideAssign}, - { "Equal", - ExpressionType.Equal}, - { "ExclusiveOr", - ExpressionType.ExclusiveOr}, - { "ExclusiveOrAssign", - ExpressionType.ExclusiveOrAssign}, - { "GreaterThan", - ExpressionType.GreaterThan}, - { "GreaterThanOrEqual", - ExpressionType.GreaterThanOrEqual}, - { "LeftShift", - ExpressionType.LeftShift}, - { "LeftShiftAssign", - ExpressionType.LeftShiftAssign}, - { "LessThan", - ExpressionType.LessThan}, - { "LessThanOrEqual", - ExpressionType.LessThanOrEqual}, - { "Modulo", - ExpressionType.Modulo}, - { "ModuloAssign", - ExpressionType.ModuloAssign}, - { MMT_OMS_URI.Multiply, - ExpressionType.Multiply}, - { "MultiplyAssign", - ExpressionType.MultiplyAssign}, - { "MultiplyAssignChecked", - ExpressionType.MultiplyAssignChecked}, - { "MultiplyChecked", - ExpressionType.MultiplyChecked}, - { "NotEqual", - ExpressionType.NotEqual}, - { "Or", - ExpressionType.Or}, - { "OrAssign", - ExpressionType.OrAssign}, - { "OrElse", - ExpressionType.OrElse}, - { "Power", - ExpressionType.Power}, - { "PowerAssign", - ExpressionType.PowerAssign}, - { "RightShift", - ExpressionType.RightShift}, - { "RightShiftAssign", - ExpressionType.RightShiftAssign}, - { MMT_OMS_URI.Subtract, - ExpressionType.Subtract}, - { "SubtractAssign", - ExpressionType.SubtractAssign}, - { "SubtractAssignChecked", - ExpressionType.SubtractAssignChecked}, - { "SubtractChecked", - ExpressionType.SubtractChecked}, - }; - - private static readonly Dictionary<string, ExpressionType> MMTtoUnaryExpressionType = new() - { - //{ "Constant", // Not Unary - // ExpressionType.Constant}, - { "Convert", - ExpressionType.Convert}, - { "ConvertChecked", - ExpressionType.ConvertChecked}, - { "Decrement", - ExpressionType.Decrement}, - { "Increment", - ExpressionType.Increment}, - { "Negate", - ExpressionType.Negate}, - { "NegateChecked", - ExpressionType.NegateChecked}, - { "Not", - ExpressionType.Not}, - { "OnesComplement", - ExpressionType.OnesComplement}, - { "PostDecrementAssign", - ExpressionType.PostDecrementAssign}, - { "PostIncrementAssign", - ExpressionType.PostIncrementAssign}, - { "PreDecrementAssign", - ExpressionType.PreDecrementAssign}, - { "PreIncrementAssign", - ExpressionType.PreIncrementAssign}, - { "UnaryPlus", - ExpressionType.UnaryPlus}, - }; - - #endregion ExpressionDictionaries - - //TODO: case ((f->x)->y) instead of assumed (f->(x->y)) - public static LambdaExpression MakeLambdaExpression(string URI, LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - { - void ThrowArgumentException(ExpressionType expression_cast, int expected) - { - throw new ArgumentException(string.Format( - "\"Wrong number of Arguments. Required: {2}. Supplied: {3}.\\n\\tFor URI:\\\"{0}\\\"\\n\\tmapped to:\\\"{1}\\\"\"", - URI, expression_cast, expected, lambda_applicant.Count() - )); - } - - ParameterExpression[] lambda_params = - lambda_applicant - .SelectMany(l => l.Parameters) - .ToArray(); //PERF: .ToList().Sort() => .BinarySearch; //Too much overhead? - ParameterExpression[] found_bound_params = - bound_params - .Where(p => lambda_params.Contains(p)) - .ToArray(); - - if (MMTtoUnaryExpressionType.TryGetValue(URI, out var unnary_type)) - { - if (found_bound_params.Count() < 1) - ThrowArgumentException(unnary_type, 1); - - Type UnarySecondArgument = found_bound_params.Count() < 2 ? null : found_bound_params[1].Type; - - return Expression.Lambda(Expression.MakeUnary(unnary_type, lambda_applicant[0].Body, UnarySecondArgument), found_bound_params); - } - else - if (MMTtoBinaryExpressionType.TryGetValue(URI, out var binary_type)) - { - if (lambda_applicant.Count() != 2) - ThrowArgumentException(binary_type, 2); - - return Expression.Lambda(Expression.MakeBinary(binary_type, lambda_applicant[0].Body, lambda_applicant[1].Body), found_bound_params); - } - else - if (MMTtoLambdaMaker.TryGetValue(URI, out var lamda_maker)) - { - return lamda_maker(lambda_applicant, lambda_arguments, found_bound_params); - } - else - if (MMT_OMS_URI.OMS_TO_TYPE.TryGetValue(URI, out Type type)) - { - return Expression.Lambda(Expression.Default(type), null); - } - - throw new NotImplementedException("Could not map URI: \"" + URI + "\""); - } - - private static LambdaExpression ExpresionFuncToLambda(LambdaExpression func, string name, LambdaExpression[] args_lamda, ParameterExpression[] bound_params, uint nTargs_fallback) - => Expression.Lambda(Expression.Invoke(func, args_lamda.Select(l => l.Body)), name, bound_params); - - private static LambdaExpression ParseFuncUUToExpression<U>(Func<U, U> func) - => (Expression<Func<U, U>>)((U x) => func(x)); - - private static LambdaExpression MakeSin(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - => ExpresionFuncToLambda( - lambda_applicant[0].ReturnType == typeof(float) ? ParseFuncUUToExpression<float>(MathF.Sin) - : lambda_applicant[0].ReturnType == typeof(double) ? ParseFuncUUToExpression<double>(Math.Sin) - : throw new NotImplementedException("Sinus for " + lambda_applicant[0].ReturnType), - - "Sin", lambda_arguments.Length > 0 ? lambda_arguments : lambda_applicant, bound_params, 1 - ); - - private static LambdaExpression MakeCos(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - => ExpresionFuncToLambda( - lambda_applicant[0].ReturnType == typeof(float) ? ParseFuncUUToExpression<float>(MathF.Cos) - : lambda_applicant[0].ReturnType == typeof(double) ? ParseFuncUUToExpression<double>(Math.Cos) - : throw new NotImplementedException("Cosinus for " + lambda_applicant[0].ReturnType), - - "Cos", lambda_arguments.Length > 0 ? lambda_arguments : lambda_applicant, bound_params, 1 - ); - - private static LambdaExpression MakeTupel(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - { - if (lambda_applicant.Length == 3 - && lambda_applicant.All(l => l.ReturnType == typeof(float))) - - return ExpresionFuncToLambda( - (Expression<Func<float, float, float, Vector3>>)((x, y, z) => new Vector3(x, y, z)), - "UnityEngineVector3", lambda_applicant, bound_params, 3 - ); - - return MakeObjArray(lambda_applicant, lambda_arguments, bound_params); - } - - private static LambdaExpression MakeObjArray(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - => Expression.Lambda( - Expression.NewArrayInit( - typeof(object), - lambda_applicant.Select(l => Expression.Convert(l.Body, typeof(object))) - ), - bound_params - ); - - private static LambdaExpression MakeInstantList(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - => Expression.Lambda( - Expression.ListInit( - Expression.New(typeof(List<>).MakeGenericType(lambda_applicant[0].ReturnType)), - lambda_arguments.Select(l => l.Body) // Expression.Convert(l.Body, lambda_applicant[0].ReturnType)) - ), - bound_params - ); - - private static LambdaExpression InsertFrontListLiteral(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - => Expression.Lambda( - Expression.Call( - lambda_applicant[0].Body, - lambda_applicant[0].ReturnType.GetMethod("Insert"), - Expression.Constant(0, typeof(int)), - lambda_applicant[1].Body - ), - bound_params - ); - - private static LambdaExpression MakeListEnd(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - => Expression.Lambda( - Expression.New(typeof(List<>).MakeGenericType(lambda_applicant[0].ReturnType)), - null - ); - - private static LambdaExpression Identity0(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - => lambda_applicant[0]; - - } - - - [JsonConverter(typeof(JsonSubtypes), "kind")] - [JsonSubtypes.KnownSubType(typeof(OMA), "OMA")] - [JsonSubtypes.KnownSubType(typeof(OMBINDC), "OMBINDC")] - [JsonSubtypes.KnownSubType(typeof(OMS), "OMS")] - [JsonSubtypes.KnownSubType(typeof(OMSTR), "OMSTR")] - [JsonSubtypes.KnownSubType(typeof(OMF), "OMF")] - [JsonSubtypes.KnownSubType(typeof(OMV), "OMV")] - [JsonSubtypes.KnownSubType(typeof(RAW), "RAW")] - //[JsonSubtypes.KnownSubType(typeof(OMC<T>), "OMC<" + typeof(T) + ">")] - [JsonSubtypes.KnownSubType(typeof(OMC<Vector3>), "OMC<UnityEngine.Vector3>")] - [JsonSubtypes.KnownSubType(typeof(OMC<float>), "OMC<System.Single>")] - [JsonSubtypes.KnownSubType(typeof(OMC<double>), "OMC<System.Double>")] - abstract public class SOMDoc - { - public string kind; - - 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) - => sd1 == null && sd2 == null - || sd1.Equivalent(sd2); - - public abstract bool Equivalent(SOMDoc sd2); - - public LambdaExpression PartialInvokeCastingLambdaExpression(out Type[] signature_args, object[] callArgs = null, bool[] useArgs = null) - { - LambdaExpression lambda_orig = GetLambdaExpression(); - - signature_args = new Type[lambda_orig.Parameters.Count + 1]; - - ParameterExpression object_arr = Expression.Parameter(typeof(object[]), "PARAMS_Arr"); - Expression[] cast_new_to_signature = new Expression[lambda_orig.Parameters.Count]; - - int n_params = 0; - for (int i = 0; i < lambda_orig.Parameters.Count; i++) - { - if (callArgs != null && callArgs.Length < i - && (useArgs == null || (useArgs.Length < i && useArgs[i]))) - { - cast_new_to_signature[i] = - Expression.Constant(callArgs[i], lambda_orig.Parameters[i].Type); - continue; - } - - signature_args[n_params++] = lambda_orig.Parameters[i].Type; - - cast_new_to_signature[i] = - Expression.Convert( - Expression.ArrayIndex( - object_arr, - Expression.Constant(i) - ), - lambda_orig.Parameters[i].Type - ); - } - signature_args[n_params] = lambda_orig.ReturnType; - signature_args = signature_args.Slice(0, n_params + 1).ToArray(); - - return Expression.Lambda( - typeof(Array).IsAssignableFrom(lambda_orig.ReturnType) - ? Expression.Convert( - Expression.Invoke(lambda_orig, cast_new_to_signature), - typeof(object[])) - : Expression.NewArrayInit( - typeof(object), - new Expression[] { Expression.Convert(Expression.Invoke(lambda_orig, cast_new_to_signature), typeof(object)) }), - - object_arr - ); - } - - public LambdaExpression GetLambdaExpression() - => GetLambdaExpression(new LambdaExpression[0], new LambdaExpression[0], new ParameterExpression[0]); - - protected internal abstract LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params); - - public abstract override string ToString(); - - public abstract SOMDoc MapURIs(Dictionary<string, string> old_to_new); - - #region MakeMMT_OMS_URItoSOMDoc - public static OMA MakeTupel(Vector3 vec) - => MakeTupel(new[] { - new OMF(vec.x), - new OMF(vec.y), - new OMF(vec.z), - }); - - public static OMA MakeTupel(SOMDoc[] args) - => new( - new OMS(MMT_OMS_URI.Tuple), - args - ); - - public static OMA MakeShallowList(SOMDoc[] args) - => new( - new OMS(MMT_OMS_URI.ListApplicant), - args - ); - - public static OMA MakeDeepList(SOMDoc[] args, SOMDoc typeURI) - { - SOMDoc[] end_of_list = new SOMDoc[] { - new OMA( - new OMS(MMT_OMS_URI.ListEnd), - new[] { - typeURI, - } - ), - args.Length == 0 - ? null - : args[^1] - }; - - if (args.Length == 0) - end_of_list = end_of_list[..^0]; - - SOMDoc defines = new OMA( - new OMS(MMT_OMS_URI.ListLiteral), - end_of_list - ); - - for (int i = args.Length - 2; i >= 0; i--) - { - defines = new OMA( - new OMS(MMT_OMS_URI.ListLiteral), - new[] { - defines, - args[i], - }); - } - - SOMDoc type = new OMA( - new OMS(MMT_OMS_URI.ListApplicant), - new[] { typeURI } - ); - - return new OMA(type, new[] { defines }); - } - #endregion MakeMMT_OMS_URItoSOMDoc - } - - public abstract class SOMDocCRTP<T> : SOMDoc where T : SOMDocCRTP<T> - { - protected SOMDocCRTP() : base() { } - - public override bool Equivalent(SOMDoc sd2) - => this.GetType() == sd2.GetType() && (this as T).EquivalentWrapped(sd2 as T); - - protected abstract bool EquivalentWrapped(T sd2); - - public override SOMDoc MapURIs(Dictionary<string, string> old_to_new) - => MapURIsWrapped(old_to_new); - - protected abstract T MapURIsWrapped(Dictionary<string, string> old_to_new); - } - - public class OMBINDC : SOMDocCRTP<OMBINDC> - { - public new string kind = "OMBINDC"; - - public string name; - - public SOMDoc lambdabody; - - /// <summary>@Type of this variable</summary> - [JsonIgnore] - public Type type; - - /// <summary>Enables (especially <see cref="JsonConverter"/>) to read and set <see cref="type"/> by its <c>string</c> representation.</summary> - public string typeString - { - get => MMT_OMS_URI.TYPE_TO_OMS[type]; - set => type = MMT_OMS_URI.OMS_TO_TYPE[value]; - } - - [JsonConstructor] - public OMBINDC(string name, string typeString, SOMDoc lambdabody) : base() - { - this.name = name; - this.typeString = typeString; - this.lambdabody = lambdabody; - } - - protected internal override SOMDoc TypeOf(SOMDoc[] args) - => throw new NotImplementedException(); - - public OMBINDC(string name, Type type, SOMDoc lambdabody) : base() - { - this.name = name; - this.type = type; - this.lambdabody = lambdabody; - } - - protected override bool EquivalentWrapped(OMBINDC sd2) - => this.type == sd2.type - && this.name.Equals(sd2.name) - && this.lambdabody.Equivalent(sd2.lambdabody); - - protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - { - ParameterExpression[] bind_me = bound_params.ShallowCloneAppend( - new[] { Expression.Parameter(type, name) } - ); - - return lambdabody.GetLambdaExpression(lambda_applicant, lambda_arguments, bind_me); - } - - public override string ToString() - => "OMBINDC(" + name + ", " + typeString + ")->"; - - protected override OMBINDC MapURIsWrapped(Dictionary<string, string> old_to_new) - => new(name, type, lambdabody.MapURIs(old_to_new)); - } - - public class OMA : SOMDocCRTP<OMA> - { - public new string kind = "OMA"; - - public SOMDoc applicant; - public SOMDoc[] arguments; - - [JsonConstructor] - public OMA(SOMDoc applicant, SOMDoc[] arguments) : base() - { - this.applicant = applicant; - this.arguments = arguments; - } - - protected internal override SOMDoc TypeOf(SOMDoc[] args) - => applicant.TypeOf(arguments.Select(a => a.TypeOf()).ToArray()); - - protected override bool EquivalentWrapped(OMA sd2) - => Equivalent(this.applicant, sd2.applicant) - && this.arguments - .Zip(sd2.arguments, (arg1, arg2) => Equivalent(arg1, arg2)) - .All(b => b); - - protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant_paps, LambdaExpression[] lambda_applicant_grands, ParameterExpression[] bound_params) - => applicant.GetLambdaExpression( - arguments.Select(arg => arg.GetLambdaExpression(new LambdaExpression[0], new LambdaExpression[0], bound_params)).ToArray(), - lambda_applicant_paps, - bound_params - ); - - public override string ToString() - => applicant.ToString() + "(" + string.Join(", ", arguments.Select(a => a.ToString())) + ")"; - - protected override OMA MapURIsWrapped(Dictionary<string, string> old_to_new) - => new OMA( - applicant.MapURIs(old_to_new), - arguments.Select(arg => arg.MapURIs(old_to_new)).ToArray() - ); - } - - public class OMS : SOMDocCRTP<OMS> - { - public new string kind = "OMS"; - - public string uri; - - [JsonConstructor] - public OMS(string uri) : base() - { - 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) - => this.uri == sd2.uri; - - protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - => SOMDoctoLambdaExpression<float>.MakeLambdaExpression(uri, lambda_applicant, lambda_arguments, bound_params); - - public override string ToString() - => uri; - - protected override OMS MapURIsWrapped(Dictionary<string, string> old_to_new) - { - if (!old_to_new.TryGetValue(uri, out string new_uri)) - new_uri = uri; - - return new OMS(new_uri); - } - } - - public class OMSTR : SOMDocCRTP<OMSTR> - { - public new string kind = "OMSTR"; - - [JsonProperty("float")] - public string s; - - [JsonConstructor] - public OMSTR(string s) : base() - { - this.s = s; - } - - protected internal override SOMDoc TypeOf(SOMDoc[] args) - => throw new NotImplementedException(); - - protected override bool EquivalentWrapped(OMSTR sd2) - => this.s == sd2.s; - - protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - => Expression.Lambda(Expression.Constant(s, typeof(string)), null); - - public override string ToString() - => s; - - protected override OMSTR MapURIsWrapped(Dictionary<string, string> old_to_new) - => (OMSTR)this.MemberwiseClone(); - } - - public class OMF : SOMDocCRTP<OMF> - { - public new string kind = "OMF"; - - [JsonProperty("float")] - public float @float; - - [JsonConstructor] - public OMF(float f) : base() - { - this.@float = f; - } - - protected internal override SOMDoc TypeOf(SOMDoc[] args) - => new OMS(MMT_OMS_URI.RealLit); - - protected override bool EquivalentWrapped(OMF sd2) - => Mathf.Approximately(@float, sd2.@float); - - protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - => Expression.Lambda(Expression.Constant(@float, typeof(float)), null); - - public override string ToString() - => @float.ToString(); - - protected override OMF MapURIsWrapped(Dictionary<string, string> old_to_new) - => (OMF)this.MemberwiseClone(); - } - - public class OMC<T> : SOMDocCRTP<OMC<T>> - { - public new string kind = "OMC<" + typeof(T) + ">"; - - public T value; - - [JsonConstructor] - public OMC(T value) : base() - { - 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) - { - Debug.LogWarning("Cannot check Equivalency for " + this.GetType() + "; only whether it's exact!"); - return this.value.Equals(value); - } - - protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - => Expression.Lambda(Expression.Constant(value, typeof(T)), null); - - public override string ToString() - => "C_" + typeof(T) + "(" + value.ToString() + ")"; - - protected override OMC<T> MapURIsWrapped(Dictionary<string, string> old_to_new) - => (OMC<T>)this.MemberwiseClone(); - } - - public class OMV : SOMDocCRTP<OMV> - { - public new string kind = "OMV"; - - public string name; - - [JsonConstructor] - public OMV(string name) : base() - { - this.name = name; - } - - protected internal override SOMDoc TypeOf(SOMDoc[] args) - => throw new NotImplementedException(); - - protected override bool EquivalentWrapped(OMV sd2) - => this.name == sd2.name; - - protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - { - ParameterExpression v = bound_params.FirstOrDefault(param => param.Name.Equals(name)); - if (v == null) - { - Debug.LogErrorFormat("Unable to find {0} for {1} with name: {2}", nameof(OMBINDC), nameof(OMV), name); - return Expression.Lambda(Expression.Empty(), null); - } - else - return Expression.Lambda(v, new[] { v }); - } - - public override string ToString() - => "Variable_" + "(" + name + ")"; - - protected override OMV MapURIsWrapped(Dictionary<string, string> old_to_new) - => (OMV)this.MemberwiseClone(); - } - - public class RAW : SOMDocCRTP<RAW> - { - public new string kind = "RAW"; - - public string xml; - - [JsonConstructor] - public RAW(string xml) : base() - { - this.xml = xml; - } - - protected internal override SOMDoc TypeOf(SOMDoc[] args) - => throw new NotImplementedException(); - - protected override RAW MapURIsWrapped(Dictionary<string, string> old_to_new) - { - string copy = xml; - foreach (KeyValuePair<string, string> KeyVal in old_to_new) - copy = copy.Replace(KeyVal.Key, KeyVal.Value); - - return new RAW(copy); - } - - public override string ToString() - => xml; - - protected override bool EquivalentWrapped(RAW sd2) - => throw new NotImplementedException(); //xml == sd2.xml; // only exact - - protected internal override LambdaExpression GetLambdaExpression(LambdaExpression[] lambda_applicant, LambdaExpression[] lambda_arguments, ParameterExpression[] bound_params) - { - throw new NotImplementedException(); - } - } - - [JsonConverter(typeof(JsonSubtypes), "kind")] - [JsonSubtypes.KnownSubType(typeof(MMTSymbolDeclaration), "general")] - [JsonSubtypes.KnownSubType(typeof(MMTValueDeclaration), "veq")] - public abstract class MMTDeclaration - { - public string kind; - public string label; - public FactReference @ref; - - public static MMTDeclaration FromJson(string json) - { - MMTDeclaration mmtDecl = JsonConvert.DeserializeObject<MMTDeclaration>(json); - mmtDecl.label ??= string.Empty; - - return mmtDecl; - } - - public string ToJson() - { - label ??= string.Empty; - return JsonConvert.SerializeObject(this); - } - - public abstract string getType(); - - public abstract string getApplicant(); - } - - /// <summary>MMTSymbolDeclaration: Class for facts without values, e.g. Points</summary> - public class MMTSymbolDeclaration : MMTDeclaration - { - public new string kind = "general"; - - [JsonProperty("tp")] - public SOMDoc type; - [JsonProperty("df")] - public SOMDoc defines; - - [JsonConstructor] - private MMTSymbolDeclaration() { } - - /// <summary>Constructor used for sending new declarations to mmt</summary> - public MMTSymbolDeclaration(string label, SOMDoc type, SOMDoc defines) - { - this.label = label; - this.type = type; - this.defines = defines; - } - - public override string getType() - { - return type switch - { - OMS oMS => oMS.uri, - OMA oMA => ((oMA.arguments[0] as OMA).applicant as OMS).uri, - _ => null - }; - } - - public override string getApplicant() - { - return defines switch - { - OMA oMA when oMA.applicant is OMS oMS => oMS.uri, - _ => null - }; - } - } - - /// <summary>MMTValueDeclaration: Class for facts with values, e.g. Distances or Angles</summary> - public class MMTValueDeclaration : MMTDeclaration - { - public new string kind = "veq"; - - public SOMDoc lhs; - [JsonProperty("valueTp")] - public SOMDoc valueType; - public SOMDoc value; - public SOMDoc proof; - - [JsonConstructor] - private MMTValueDeclaration() { } - - /// <summary>Constructor used for sending new declarations to mmt</summary> - public MMTValueDeclaration(string label, SOMDoc lhs, SOMDoc valueType, SOMDoc value, SOMDoc proof = null) - { - this.label = label; - this.lhs = lhs; - this.valueType = valueType; - this.value = value; - this.proof = proof; - } - - public override string getType() - { - return lhs switch - { - OMA oMA when oMA.applicant is OMS oMS => oMS.uri, - _ => null - }; - } - - public override string getApplicant() - { - return lhs switch - { - OMA oMA when oMA.applicant is OMS oMS => oMS.uri, - _ => null - }; - } - } -} diff --git a/Assets/Scripts/UI/InGame/PopupBehavior.cs b/Assets/Scripts/UI/InGame/PopupBehavior.cs index 1b0f699a3cfae1e42ba3142b29d4e00ba0f1661b..667846e9e2bb81f82e4c89942ed8902d8fbb7a3f 100644 --- a/Assets/Scripts/UI/InGame/PopupBehavior.cs +++ b/Assets/Scripts/UI/InGame/PopupBehavior.cs @@ -4,7 +4,6 @@ using TMPro; using UnityEngine.UI; using REST_JSON_API; -using static SOMDocManager; public class PopupBehavior : MonoBehaviour { @@ -86,7 +85,7 @@ private string generateHelpfulMessageAndAnimateScrollParam(ScrollApplicationChec else if (error.kind == "invalidAssignment") { invAssCount++; - MMTDeclaration fact = parseFactFromError(error); + MMTFact fact = parseFactFromError(error); //animate all invalidly assigned facts if (ParameterDisplays != null && fact != null) @@ -122,7 +121,7 @@ private string generateHelpfulMessageAndAnimateScrollParam(ScrollApplicationChec } //this should be changed, the Fact Object should be parsed by JSON. This is a workaround because the MMT servers JSON serialization contains a bug - private MMTDeclaration parseFactFromError(ScrollApplicationCheckingError error) + private MMTFact parseFactFromError(ScrollApplicationCheckingError error) { if (error == null || error.msg == null) return null; diff --git a/Assets/Scripts/UI/InGame/TimeStop.cs b/Assets/Scripts/UI/InGame/TimeStop.cs index d4d3242a97c3ac6f6bd9c2a41417df681fb75a32..1dc0226a4656937230d3bc517bb602faf353bbce 100644 --- a/Assets/Scripts/UI/InGame/TimeStop.cs +++ b/Assets/Scripts/UI/InGame/TimeStop.cs @@ -1,20 +1,4 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; -using UnityEngine.UI; //andr -using UnityEngine.SceneManagement; -using System.IO; // -using UnityEngine.Video;//streaming -using UnityEngine.Networking; -//using static StreamingAssetLoader; -//using static CheckServer; -//using static CommunicationEvents; -using static UIconfig; -using UnityEngine.EventSystems; -using static Restart; -using static SceneSwitcher; - - /* https://gamedevbeginner.com/the-right-way-to-pause-the-game-in-unity/#:~:text=The%20most%20convenient%20method%20for%20pausing%20the%20game,will%20return%20the%20game%20to%20its%20normal%20speed. @@ -22,15 +6,9 @@ public class TimeStop: MonoBehaviour { - - - public bool checkTimeToStop; - - - void Start() { PauseGame(); @@ -38,27 +16,13 @@ void Start() private void Update() { - if (checkTimeToStop == true) { + if (checkTimeToStop == true) PauseGame(); - //disableGameUI(); - } } - - - - private void PauseGame() { - UIconfig.GamePaused = true; Time.timeScale = 0; } - - - - - - - } \ No newline at end of file