Newer
Older
public CylinderVolumeFact(string Cid1, string Cid2, float volume, string eqProof, OMA proof, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.Cid1 = Cid1;
this.Cid2 = Cid2;
this.vol = volume;
this.proof = proof;
this.equalCirclesProof = eqProof;
this._URI = backendURI;
_ = this.Label;
}
/// \copydoc Fact.parseFact(ScrollFact)
public new static CylinderVolumeFact parseFact(MMTDeclaration 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;
OMA proof = (OMA)(((OMA)((OMA)((MMTValueDeclaration)fact).lhs).arguments[0]).arguments[3]);
if (!FactOrganizer.AllFacts.ContainsKey(Circle1Uri)
|| !FactOrganizer.AllFacts.ContainsKey(Circle2Uri))
return null;
return new CylinderVolumeFact(Circle1Uri, Circle2Uri, volume, EqualCirclesProof, proof, fact.@ref.uri, StageStatic.stage.factState);
}
/// \copydoc Fact.generateLabel
protected override string generateLabel()
public override MMTDeclaration MakeMMTDeclaration()
MaZiFAU
committed
SOMDoc lhs =
new OMA(
MaZiFAU
committed
new OMS(MMT_OMS_URI.CylinderVolume),
new OMS(Cid1),
new OMS(Cid2),
new OMS(equalCirclesProof),
proof,
}
);
MaZiFAU
committed
SOMDoc valueTp = new OMS(MMT_OMS_URI.RealLit);
return new MMTValueDeclaration(this.Label, lhs, valueTp, value);
}
/// \copydoc Fact.hasDependentFacts
MaZiFAU
committed
public override bool HasDependentFacts => true;
/// \copydoc Fact.getDependentFactIds
=> new string[] { Cid1, Cid2, equalCirclesProof };
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(CylinderVolumeFact f1, CylinderVolumeFact f2)
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new CylinderVolumeFact(old_to_new[this.Cid1], old_to_new[this.Cid2], this.vol, old_to_new[this.equalCirclesProof], this.proof, organizer);
/// <summary>
/// A fact that describes, that two circles have the same size and is comprised of two <see cref="CircleFact">CircleFacts</see>
/// </summary>
public class EqualCirclesFact : FactWrappedCRTP<EqualCirclesFact>
{
/// @{ <summary>
/// two circles that are meant to be equal in area
/// </summary>
public string Cid1, Cid2;
/// @}
MaZiFAU
committed
[JsonIgnore]
public CircleFact Circle1 { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
MaZiFAU
committed
[JsonIgnore]
public CircleFact Circle2 { get => (CircleFact)FactOrganizer.AllFacts[Cid2]; }
/// <summary> \copydoc Fact.Fact </summary>
public EqualCirclesFact() : base()
{
this.Cid1 = null;
this.Cid2 = null;
}
/// <summary>
/// Standard Constructor:
/// Initiates members and creates MMT %Fact Server-Side
/// </summary>
/// <param name="cid1">sets <see cref="Cid1"/></param>
/// <param name="cid2">sets <see cref="Cid2"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public EqualCirclesFact(string cid1, string cid2, FactOrganizer organizer) : base(organizer)
{
this.Cid1 = cid1;
this.Cid2 = cid2;
{
Position = Circle1.Position;
Rotation = Circle1.Rotation;
}
/// <summary>
/// Bypasses initialization of new MMT %Fact by using existend URI, _which is not checked for existence_.
/// </summary>
/// <param name="Cid1">sets <see cref="Cid1"/></param>
/// <param name="Cid2">sets <see cref="Cid2"/></param>
/// <param name="backendURI">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public EqualCirclesFact(string Cid1, string Cid2, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.Cid1 = Cid1;
this.Cid2 = Cid2;
this._URI = backendURI;
_ = this.Label;
}
/// \copydoc Fact.parseFact(ScrollFact)
public new static EqualCirclesFact parseFact(MMTDeclaration fact)
if (((MMTSymbolDeclaration)fact).type is not OMA proof_OMA) // proof DED
return null;
OMA parallel_circles_OMA = (OMA)proof_OMA.arguments[0]; // parallel
string circleAUri = ((OMS)parallel_circles_OMA.arguments[0]).uri;
string circleBUri = ((OMS)parallel_circles_OMA.arguments[1]).uri;
if (!FactOrganizer.AllFacts.ContainsKey(circleAUri)
|| !FactOrganizer.AllFacts.ContainsKey(circleBUri))
return new EqualCirclesFact(circleAUri, circleBUri, fact.@ref.uri, StageStatic.stage.factState);
}
/// \copydoc Fact.generateLabel
protected override string generateLabel()
public override MMTDeclaration MakeMMTDeclaration()
MaZiFAU
committed
SOMDoc tp = new OMA(
new OMS(MMT_OMS_URI.EqualityCircles),
new OMS(Cid1),
new OMS(Cid2),
MaZiFAU
committed
SOMDoc df = null;
return new MMTSymbolDeclaration(this.Label, tp, df);
}
/// \copydoc Fact.hasDependentFacts
MaZiFAU
committed
public override bool HasDependentFacts => true;
/// \copydoc Fact.getDependentFactIds
=> new string[] { Cid1, Cid2 };
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(EqualCirclesFact f1, EqualCirclesFact f2)
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new EqualCirclesFact(old_to_new[this.Cid1], old_to_new[this.Cid2], organizer);
}
/// <summary>
/// A fact that describes, that two circles have not the same size and is comprised of two <see cref="CircleFact">CircleFacts</see>
/// </summary>
public class UnEqualCirclesFact : FactWrappedCRTP<UnEqualCirclesFact>
{
/// @{ <summary>
/// two circles that are meant to be unequal in area
/// </summary>
public string Cid1, Cid2;
/// @}
MaZiFAU
committed
[JsonIgnore]
public CircleFact Circle1 { get => (CircleFact)FactOrganizer.AllFacts[Cid1]; }
MaZiFAU
committed
[JsonIgnore]
public CircleFact Circle2 { get => (CircleFact)FactOrganizer.AllFacts[Cid2]; }
/// <summary> \copydoc Fact.Fact </summary>
public UnEqualCirclesFact() : base()
{
this.Cid1 = null;
this.Cid2 = null;
}
/// <summary>
/// Standard Constructor:
/// Initiates members and creates MMT %Fact Server-Side
/// </summary>
/// <param name="cid1">sets <see cref="Cid1"/></param>
/// <param name="cid2">sets <see cref="Cid2"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public UnEqualCirclesFact(string cid1, string cid2, FactOrganizer organizer) : base(organizer)
{
this.Cid1 = cid1;
this.Cid2 = cid2;
{
Position = Circle2.Position;
Rotation = Circle2.Rotation;
}
/// <summary>
/// Bypasses initialization of new MMT %Fact by using existend URI, _which is not checked for existence_.
/// </summary>
/// <param name="Cid1">sets <see cref="Cid1"/></param>
/// <param name="Cid2">sets <see cref="Cid2"/></param>
/// <param name="backendURI">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public UnEqualCirclesFact(string Cid1, string Cid2, string backendURI, FactOrganizer organizer) : base(organizer)
{
this.Cid1 = Cid1;
this.Cid2 = Cid2;
this._URI = backendURI;
_ = this.Label;
}
/// \copydoc Fact.parseFact(ScrollFact)
public new static UnEqualCirclesFact parseFact(MMTDeclaration fact)
if (((MMTSymbolDeclaration)fact).type is not OMA proof_OMA) // proof DED
return null;
OMA unequal_circles_OMA = (OMA)proof_OMA.arguments[0]; // unequal
MaZiFAU
committed
string circleAUri = ((OMS)unequal_circles_OMA.arguments[0]).uri;
string circleBUri = ((OMS)unequal_circles_OMA.arguments[1]).uri;
if (!FactOrganizer.AllFacts.ContainsKey(circleAUri)
|| !FactOrganizer.AllFacts.ContainsKey(circleBUri))
return null;
MaZiFAU
committed
return new UnEqualCirclesFact(circleAUri, circleBUri, fact.@ref.uri, StageStatic.stage.factState);
}
/// \copydoc Fact.generateLabel
protected override string generateLabel()
public override MMTDeclaration MakeMMTDeclaration()
MaZiFAU
committed
SOMDoc tp = new OMA(
new OMA(new OMS(MMT_OMS_URI.UnEqualityCircles),
new OMS(Cid1),
new OMS(Cid2),
MaZiFAU
committed
SOMDoc df = null;
return new MMTSymbolDeclaration(this.Label, tp, df);
}
/// \copydoc Fact.hasDependentFacts
MaZiFAU
committed
public override bool HasDependentFacts => true;
/// \copydoc Fact.getDependentFactIds
=> new string[] { Cid1, Cid2 };
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(UnEqualCirclesFact f1, UnEqualCirclesFact f2)
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new UnEqualCirclesFact(old_to_new[this.Cid1], old_to_new[this.Cid2], organizer);
/// <seealso cref="SOMDoc.MakeList(string[], string)"/>
/// <remarks>Needed to refere to lists serverside</remarks>
public class ListFact : FactWrappedCRTP<ListFact>
{
public string typeURI;
[JsonIgnore]
public Type ListType
{
get => MMT_OMS_URI.OMS_TO_TYPE[typeURI];
private set => typeURI = MMT_OMS_URI.TYPE_TO_OMS[value];
}
public ListFact() : base()
{
lids = new string[0];
}
public ListFact(string[] lids, Type ListType, FactOrganizer organizer) : base(organizer)
public ListFact(string[] lids, string typeURI, string backendURI, FactOrganizer organizer) : base(organizer)
protected override bool EquivalentWrapped(ListFact f1, ListFact f2)
=> f1.typeURI == f2.typeURI
&& DependentFactsEquivalent(f1, f2);
public override bool HasDependentFacts
=> true;
protected override string[] GetGetDependentFactIds()
=> lids;
public override MMTDeclaration MakeMMTDeclaration()
{
OMA List = SOMDoc.MakeList(lids, typeURI);
return new MMTSymbolDeclaration(Label, List.applicant, List.arguments[0]);
public static new ListFact parseFact(MMTDeclaration fact)
=> new(parseFactList(fact, out string typeURI).ToArray(), typeURI, fact.@ref.uri, StageStatic.stage.factState);
public static List<string> parseFactList(MMTDeclaration decl, out string typeURI)
if (decl is not MMTSymbolDeclaration MMTSymbol
|| MMTSymbol.type is not OMA listOMA
|| listOMA.arguments[0] is not OMS typeOMS)
{
typeURI = null;
while (true)
{
if (next_element is not OMA current_element)
return ret;
{
case 2:
if (current_element.arguments[1] is not OMS oMS)
return ret;
ret.Add(oMS.uri);
next_element = current_element.arguments[0];
break;
case 0:
case 1:
default:
return ret;
}
}
}
public static List<T> parseFactList<T>(MMTDeclaration decl)
{
if (decl is not MMTSymbolDeclaration mMTSymbol)
return null;
List<T> ret = new();
SOMDoc next_element = mMTSymbol.defines;
while (true)
{
if (next_element is not OMA current_element)
return ret;
{
case 2:
ret.Add((current_element.arguments[1].GetLambdaExpression().Compile() as Func<T>)());
next_element = current_element.arguments[0];
break;
case 0:
case 1:
default:
return ret;
}
}
}
protected override void RecalculateTransform() { }
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new ListFact(lids.Select(id => old_to_new[id]).ToArray(), ListType, organizer);
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
/// <summary>
///
/// </summary>
/// <seealso cref="SOMDoc.MakeTupel(SOMDoc[])"/>
/// <remarks>Needed to refere to tupels serverside</remarks>
public class TupelFact : FactWrappedCRTP<ListFact>
{
public string[] lids = new string[0];
public SOMDoc[] payload = new SOMDoc[0];
public TupelFact() : base() { }
public TupelFact(string[] lids, SOMDoc[] payload, FactOrganizer organizer) : base(organizer)
{
Init(lids, payload);
SendToMMT();
}
public TupelFact(string[] lids, SOMDoc[] payload, string backendURI, FactOrganizer organizer) : base(organizer)
{
Init(lids, payload);
_URI = backendURI;
}
private void Init(string[] lids, SOMDoc[] payload)
{
this.lids = lids ?? new string[0];
if (!HasDependentFacts)
{
if (payload.Any(p => p == null))
throw new ArgumentException(nameof(payload) + "must not include null elements iff " + nameof(lids) + " is all nulls or empty!");
this.payload = payload;
}
else
{
this.payload = new SOMDoc[math.max(lids.Length, payload.Length)];
for (int i = 0; i < this.payload.Length; i++)
if (lids[i] != null)
payload[i] = new OMS(lids[i]);
else
if (lids[i] == null && payload[i] == null)
throw new ArgumentException(nameof(lids) + " and " + nameof(payload) + " have to be complementary not null!");
}
}
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new, FactOrganizer organizer)
=> new TupelFact(lids.Select(id => old_to_new[id]).ToArray(), payload, organizer);
public static new TupelFact parseFact(MMTDeclaration fact)
{
if (fact is not MMTSymbolDeclaration MMTSymbol
|| MMTSymbol.defines is not OMA defineOMA)
{
return null;
}
string[] lids = defineOMA.arguments
.Select(oms => (oms as OMS)?.uri)
.ToArray();
return new(lids, defineOMA.arguments, fact.@ref.uri, StageStatic.stage.factState);
}
public override MMTDeclaration MakeMMTDeclaration()
{
OMA List = SOMDoc.MakeTupel(payload);
return new MMTSymbolDeclaration(Label, List.applicant, List);
}
protected override string[] GetGetDependentFactIds()
=> lids.Where(lid => lid != null).ToArray();
protected override void RecalculateTransform() { }
protected override bool EquivalentWrapped(ListFact f1, ListFact f2)
=> f1.typeURI == f2.typeURI
&& DependentFactsEquivalent(f1, f2);
}
#pragma warning disable // Testing...
/// use this if you need to test certain implementations of facts.
/// </summary>
public class TestFact : FactWrappedCRTP<TestFact>
{
/// <summary> \copydoc Fact.Fact </summary>
public TestFact() : base()
{
/// Standard Constructor:
/// Initiates members and creates MMT %Fact Server-Side
/// </summary>
/// <param name="pid1">sets <see cref="Pid1"/></param>
/// <param name="pid2">sets <see cref="Pid2"/></param>
/// <param name="radius">sets <see cref="radius"/></param>
/// <param name="normal">sets <see cref="normal"/></param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public TestFact(FactOrganizer organizer) : base(organizer)
protected override void RecalculateTransform() { }
/// <summary>
/// Bypasses initialization of new MMT %Fact by using existend URI, _which is not checked for existence_.
/// </summary>
/// <param name="Pid1">sets <see cref="Pid1"/></param>
/// <param name="Pid2">sets <see cref="Pid2"/></param>
/// <param name="radius">sets <see cref="radius"/></param>
/// <param name="normal">sets <see cref="normal"/></param>
/// <param name="backendURI">MMT URI</param>
/// <param name="organizer">sets <see cref="Fact._Facts"/></param>
public TestFact(string backendURI, FactOrganizer organizer) : base(organizer)
this._URI = backendURI;
_ = this.Label;
}
/// <summary>
/// parses the Circlefact response of the MMT-Server
/// </summary>
/// \copydoc Fact.parseFact(ScrollFact)
public new static TestFact parseFact(MMTDeclaration fact)
{
string uri = fact.@ref.uri;
Debug.Log("TestFact Uri:" + uri);
return new TestFact(uri, StageStatic.stage.factState);
}
/// \copydoc Fact.generateLabel
=> "test";
/// \copydoc Fact.hasDependentFacts
MaZiFAU
committed
public override bool HasDependentFacts => false;
/// \copydoc Fact.getDependentFactIds
=> new string[] { };
/// \copydoc Fact.GetHashCode
=> base.GetHashCode();// this.Pid1.GetHashCode() ^ this.Pid2.GetHashCode();
/// \copydoc Fact.Equivalent(Fact, Fact)
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()
{
throw new NotImplementedException();
}
}
#pragma warning restore // Testing over