From 9ea37b3e6f7a18fb671fa7fc0ab975cc29320441 Mon Sep 17 00:00:00 2001 From: Richard Marcus <richard.marcus@fau.de> Date: Sun, 2 Aug 2020 22:24:48 +0200 Subject: [PATCH] sending works correctly now but format/request is still wrong --- Assets/Scenes/TreeWorld_02.unity | 5 +++++ Assets/Scripts/InteractionEngine/Fact.cs | 20 ++++++++--------- Assets/Scripts/JSONManager.cs | 28 +++++++++++++++++++----- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/Assets/Scenes/TreeWorld_02.unity b/Assets/Scenes/TreeWorld_02.unity index fa181c5f..947462c0 100644 --- a/Assets/Scenes/TreeWorld_02.unity +++ b/Assets/Scenes/TreeWorld_02.unity @@ -41104,6 +41104,11 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 2089306640899292912, guid: 4d99275c6663c25469ad3b65efcd4f5f, + type: 3} + propertyPath: m_AnchoredPosition.y + value: -0.00035664605 + objectReference: {fileID: 0} - target: {fileID: 2524590709578595355, guid: 4d99275c6663c25469ad3b65efcd4f5f, type: 3} propertyPath: m_AnchorMax.x diff --git a/Assets/Scripts/InteractionEngine/Fact.cs b/Assets/Scripts/InteractionEngine/Fact.cs index a5423a7e..a63e2dd3 100644 --- a/Assets/Scripts/InteractionEngine/Fact.cs +++ b/Assets/Scripts/InteractionEngine/Fact.cs @@ -37,10 +37,11 @@ public static AddFactResponse sendAdd(string path, string body) //Put constructor parses stringbody to byteArray internally (goofy workaround) UnityWebRequest www = UnityWebRequest.Put(path, body); www.method = UnityWebRequest.kHttpVerbPOST; - // www.SetRequestHeader("Content-Type", "application/json"); - // www.timeout = 1; + www.SetRequestHeader("Content-Type", "application/json"); + www.timeout = 1; + //TODO: implement real asynchronous communication ... - AsyncOperation op = www.Send(); + AsyncOperation op = www.SendWebRequest(); while (!op.isDone) { } if (www.isNetworkError || www.isHttpError) { @@ -60,7 +61,7 @@ public class PointFact : Fact { public Vector3 Point; public Vector3 Normal; - public string ConceptName = "point"; + public PointFact(int i, Vector3 P, Vector3 N) { @@ -75,12 +76,11 @@ public PointFact(int i, Vector3 P, Vector3 N) new JSONManager.OMF(P.z) }; - JSONManager.MMTTerm tp = new JSONManager.OMA(new JSONManager.OMS(ConceptName), arguments); - JSONManager.MMTDeclaration mmtDecl = new JSONManager.MMTDeclaration() - { - label = "test", //TODO: rework label/id ? - tp = tp //JSONManager adds the id prefix - }; + //OMS constructor generates full URI + JSONManager.MMTTerm tp = new JSONManager.OMS("point"); + JSONManager.MMTTerm df = new JSONManager.OMA(new JSONManager.OMS("tuple"), arguments); + + JSONManager.MMTDeclaration mmtDecl = new JSONManager.MMTDeclaration("test", tp, df); string body = JSONManager.ToJson(mmtDecl); AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress+"/fact/add", body); diff --git a/Assets/Scripts/JSONManager.cs b/Assets/Scripts/JSONManager.cs index 6695d1f4..e1e552bb 100644 --- a/Assets/Scripts/JSONManager.cs +++ b/Assets/Scripts/JSONManager.cs @@ -7,7 +7,15 @@ public static class JSONManager { - public static string URIPrefix = "http://mathhub.info/MitM/core/geometry?3DGeometry?"; + public static Dictionary<string, string> URIDictionary = new Dictionary<string, string> { + {"point", "http://mathhub.info/MitM/core/geometry?3DGeometry?point" }, + {"tuple", "http://gl.mathhub.info/MMT/LFX/Sigma?Symbols?Tuple"}, + {"line", "http://mathhub.info/MitM/core/geometry?Geometry/Common?line_type" }, + {"distance", "http://mathhub.info/MitM/core/geometry?Geometry/Common?lineOf" } + }; + + + [JsonConverter(typeof(JsonSubtypes), "kind")] public class MMTTerm @@ -32,9 +40,12 @@ public class OMS : MMTTerm public string uri; public string kind = "OMS"; - public OMS(string uri) + public OMS(string uri, bool convertToURI = true) { - this.uri = URIPrefix + uri; + if (convertToURI) + this.uri = URIDictionary[uri]; + else + this.uri = uri; } } @@ -51,13 +62,13 @@ public OMF(float f) } } - + /* class DeclarationBody : MMTTerm { MMTTerm original; MMTTerm simplified; string kind = "O/S"; - } + }*/ public class MMTDeclaration @@ -65,6 +76,13 @@ public class MMTDeclaration public string label; public MMTTerm tp; public MMTTerm df; + + public MMTDeclaration(string label, MMTTerm tp, MMTTerm df) + { + this.label = label; + this.tp = tp; + this.df = df; + } } public static MMTDeclaration FromJson(string json) -- GitLab