From 2bc30cc0fa75ab5ca432bee68c3f593e679446c7 Mon Sep 17 00:00:00 2001 From: omaus Date: Mon, 25 Aug 2025 16:15:04 +0200 Subject: [PATCH 1/2] Add method to return Ontology as triplets --- src/Ontology.NET/Ontology.fs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Ontology.NET/Ontology.fs b/src/Ontology.NET/Ontology.fs index 0746744..52525aa 100644 --- a/src/Ontology.NET/Ontology.fs +++ b/src/Ontology.NET/Ontology.fs @@ -201,6 +201,20 @@ type Ontology() = onto + /// + /// Returns the Ontology as a collection of Triplets. + /// + /// A collection of Triplets in the form of SourceTerm * Relation * TargetTerm. + member this.ToTriplets() = + FGraph.toSeq this + |> Seq.collect ( + fun (nk1,nd1,nk2,nd2,es) -> + es + |> Seq.map ( + fun e -> nd1, e, nd2 + ) + ) + // basic functionality: @@ -1306,4 +1320,11 @@ type Ontology() = /// A sequence of term IDs representing all transitively is_a source-related terms and their xref-related terms that can be reached within the given depth. /// A source relation is an incoming relation. E.g. "Term A -> Term B", Term A is the source-related term to Term B. If "->" is an is_a relation, Term A is the subclass of Term B. static member getSubClassesWithDepthWithXrefsTransitively termID depth (onto : Ontology) = - onto.GetSubClassesWithDepthWithXrefsTransitively(termID, depth) \ No newline at end of file + onto.GetSubClassesWithDepthWithXrefsTransitively(termID, depth) + + /// + /// Returns the given Ontology as a collection of Triplets. + /// + /// A collection of Triplets in the form of SourceTerm * Relation * TargetTerm. + static member toTriplets (onto : Ontology) = + onto.ToTriplets() \ No newline at end of file From 5fe2aa174f532640403e01cae2c0c6fd5bdbb594 Mon Sep 17 00:00:00 2001 From: omaus Date: Mon, 25 Aug 2025 16:15:16 +0200 Subject: [PATCH 2/2] Add unit test for triplet returning method --- tests/Ontology.NET.Tests/Ontology.Tests.fs | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/Ontology.NET.Tests/Ontology.Tests.fs b/tests/Ontology.NET.Tests/Ontology.Tests.fs index 5e7fa0a..128de2c 100644 --- a/tests/Ontology.NET.Tests/Ontology.Tests.fs +++ b/tests/Ontology.NET.Tests/Ontology.Tests.fs @@ -358,4 +358,37 @@ module OntologyTests = Expect.equal actual.Ontology expected.Ontology "ontology (i.e., ontology name) differs" ] + testList "ToTriplets" [ + testCase "returns correct triplets" <| fun _ -> + let actual = ReferenceObjects.testOnto1.ToTriplets() |> Seq.toList + let expected = [ + ({ Accession = "test:01" + Name = "Frosch" + RefUri = "test" }, Xref, { Accession = "test:02" + Name = "Kröte" + RefUri = "test" }); + ({ Accession = "test:01" + Name = "Frosch" + RefUri = "test" }, IsA, { Accession = "test:04" + Name = "Tier" + RefUri = "test" }); + ({ Accession = "test:02" + Name = "Kröte" + RefUri = "test" }, IsA, { Accession = "test:04" + Name = "Tier" + RefUri = "test" }); + ({ Accession = "test:03" + Name = "Quakendes Geschöpf" + RefUri = "test" }, Xref, { Accession = "test:02" + Name = "Kröte" + RefUri = "test" }); + ({ Accession = "test:03" + Name = "Quakendes Geschöpf" + RefUri = "test" }, IsA, { Accession = "test:04" + Name = "Tier" + RefUri = "test" }) + ] + Expect.sequenceEqual actual expected "Triplets differ" + ] + ] \ No newline at end of file