Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/Ontology.NET/Ontology.fs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ type Ontology() =

onto

/// <summary>
/// Returns the Ontology as a collection of Triplets.
/// </summary>
/// <returns>A collection of Triplets in the form of SourceTerm * Relation * TargetTerm.</returns>
member this.ToTriplets() =
FGraph.toSeq this
|> Seq.collect (
fun (nk1,nd1,nk2,nd2,es) ->
es
|> Seq.map (
fun e -> nd1, e, nd2
)
)


// basic functionality:

Expand Down Expand Up @@ -1306,4 +1320,11 @@ type Ontology() =
/// <returns>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.</returns>
/// <remarks>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.</remarks>
static member getSubClassesWithDepthWithXrefsTransitively termID depth (onto : Ontology) =
onto.GetSubClassesWithDepthWithXrefsTransitively(termID, depth)
onto.GetSubClassesWithDepthWithXrefsTransitively(termID, depth)

/// <summary>
/// Returns the given Ontology as a collection of Triplets.
/// </summary>
/// <returns>A collection of Triplets in the form of SourceTerm * Relation * TargetTerm.</returns>
static member toTriplets (onto : Ontology) =
onto.ToTriplets()
33 changes: 33 additions & 0 deletions tests/Ontology.NET.Tests/Ontology.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]

]
Loading