diff --git a/src/OBO.NET/OboTerm.fs b/src/OBO.NET/OboTerm.fs index 431c9db..df22d6a 100644 --- a/src/OBO.NET/OboTerm.fs +++ b/src/OBO.NET/OboTerm.fs @@ -496,7 +496,7 @@ type OboTerm = if term.Definition = "" |> not then yield $"def: {term.Definition}" if term.Comment = "" |> not then yield $"comment: {term.Comment}" for subset in term.Subsets do yield $"subset: {subset}" - for synonym in term.Synonyms do yield $"synonym: {synonym}" + for synonym in term.Synonyms do yield $"synonym: {synonym.ToLine()}" for xref in term.Xrefs do yield $"xref: {xref.Name}" if term.BuiltIn then yield "builtin" for property_value in term.PropertyValues do yield $"property_value: {property_value}" diff --git a/src/OBO.NET/TermSynonym.fs b/src/OBO.NET/TermSynonym.fs index af5f99b..0ce83bd 100644 --- a/src/OBO.NET/TermSynonym.fs +++ b/src/OBO.NET/TermSynonym.fs @@ -4,14 +4,14 @@ open DBXref -//The value consists of a quote enclosed synonym text, a scope identifier, an optional synonym type name, and an optional dbxref list, like this: -//synonym: "The other white meat" EXACT MARKETING_SLOGAN [MEAT:00324, BACONBASE:03021] - -//The synonym scope may be one of four values: EXACT, BROAD, NARROW, RELATED. If the first form is used to specify a synonym, the scope is assumed to be RELATED. - -//The synonym type must be the id of a synonym type defined by a synonymtypedef line in the header. If the synonym type has a default scope, that scope is used regardless of any scope declaration given by a synonym tag. - -//The dbxref list is formatted as specified in dbxref formatting. A term may have any number of synonyms. +///The value consists of a quote enclosed synonym text, a scope identifier, an optional synonym type name, and an optional dbxref list, like this: +///synonym: "The other white meat" EXACT MARKETING_SLOGAN [MEAT:00324, BACONBASE:03021] +/// +///The synonym scope may be one of four values: EXACT, BROAD, NARROW, RELATED. If the first form is used to specify a synonym, the scope is assumed to be RELATED. +/// +///The synonym type must be the id of a synonym type defined by a synonymtypedef line in the header. If the synonym type has a default scope, that scope is used regardless of any scope declaration given by a synonym tag. +/// +///The dbxref list is formatted as specified in dbxref formatting. A term may have any number of synonyms. type TermSynonymScope = | Exact | Broad @@ -27,13 +27,28 @@ type TermSynonymScope = | _ -> printfn "[WARNING@L %i]unable to recognize %s as synonym scope" line s Related + member this.ToOboString() = + match this with + | Exact -> "EXACT" + | Broad -> "BROAD" + | Narrow -> "NARROW" + | Related -> "RELATED" + type TermSynonym = { Text : string Scope : TermSynonymScope TypeName : string DBXrefs : DBXref list -} +} with + static member create(text: string, scope: TermSynonymScope, typeName: string, dbxrefs: DBXref list) = { + Text = text + Scope = scope + TypeName = typeName + DBXrefs = dbxrefs + } + + member this.ToLine() = $"{this.Text} {this.Scope.ToOboString()} {this.TypeName} {this.DBXrefs}" module TermSynonym = diff --git a/tests/OBO.NET.Tests/OBO.NET.Tests.fsproj b/tests/OBO.NET.Tests/OBO.NET.Tests.fsproj index 8c20c74..158c8a4 100644 --- a/tests/OBO.NET.Tests/OBO.NET.Tests.fsproj +++ b/tests/OBO.NET.Tests/OBO.NET.Tests.fsproj @@ -9,6 +9,7 @@ + @@ -24,4 +25,8 @@ + + + + diff --git a/tests/OBO.NET.Tests/OboTerm.Tests.fs b/tests/OBO.NET.Tests/OboTerm.Tests.fs index cb60f80..3b401f1 100644 --- a/tests/OBO.NET.Tests/OboTerm.Tests.fs +++ b/tests/OBO.NET.Tests/OboTerm.Tests.fs @@ -22,4 +22,17 @@ module OboTermTests = let expected = ["id:1", "related_to", "id:2"; "id:1", "unrelated_to", "id:3"] Expect.sequenceEqual actual expected "is not equal" ] + testList "ToLines" [ + testCase "synonym" <| fun _ -> + let actual = + OboTerm.Create("NCBITaxon:562", Name="Escherichia coli", Synonyms=[TermSynonym.create("\"Bacillus coli\"", Related, "synonym", [])]) + |> OboTerm.toLines + |> List.ofSeq + let expected = [ + "id: NCBITaxon:562" + "name: Escherichia coli" + "synonym: \"Bacillus coli\" RELATED synonym []" + ] + Expect.sequenceEqual actual expected "" + ] ] \ No newline at end of file diff --git a/tests/OBO.NET.Tests/TermSynonym.Tests.fs b/tests/OBO.NET.Tests/TermSynonym.Tests.fs new file mode 100644 index 0000000..b439fd6 --- /dev/null +++ b/tests/OBO.NET.Tests/TermSynonym.Tests.fs @@ -0,0 +1,21 @@ +namespace OBO.NET.Tests + +open Expecto +open OBO.NET + +module TermSynonymTests = + + [] + let main = + testList "TermSynonym" [ + testCase "create" <| fun _ -> + let actual = TermSynonym.create("\"Bacillus coli\"", Related, "synonym", []) + Expect.equal actual.Text "\"Bacillus coli\"" "text" + Expect.equal actual.Scope Related "scope" + Expect.equal actual.TypeName "synonym" "typeName" + Expect.equal actual.DBXrefs [] "dbxrefs" + testCase "ToOboString" <| fun _ -> + let actual = TermSynonym.create("\"Bacillus coli\"", Related, "synonym", []).ToLine() + let expected = "\"Bacillus coli\" RELATED synonym []" + Expect.equal actual expected "is not equal" + ] \ No newline at end of file