Skip to content

Commit

Permalink
Update document header tag parsing (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
omaus committed May 8, 2024
1 parent a0c0284 commit 4258b67
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions playground.fsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,88 @@
#I "src/OBO.NET/bin/Debug/netstandard2.0"
#I "src/OBO.NET/bin/Release/netstandard2.0"
#I "src/OBO.NET.CodeGeneration/bin/Debug/netstandard2.0"
#I "src/OBO.NET.CodeGeneration/bin/Release/netstandard2.0"

#r "OBO.NET.dll"
#r "OBO.NET.CodeGeneration.dll"

open OBO.NET
open OBO.NET.DBXref
open OBO.NET.CodeGeneration

#r "nuget: FSharpAux"
#r "nuget: ARCTokenization"

open FSharpAux
open ARCTokenization.Terms

open type System.Environment




type OboOntology =

{
Terms : OboTerm list
TypeDefs : OboTypeDef list
FormatVersion : string
DataVersion : string option
Ontology : string option
Date : System.DateTime option
SavedBy : string option
AutoGeneratedBy : string option
Subsetdef : string option
Import : string option
Synonymtypedef : TermSynonym option // rethink type, maybe create a mother t
}

static member create terms typedefs formatVersion =
{
Terms = terms
TypeDefs = typedefs
FormatVersion = formatVersion
}

/// Reads an OBO Ontology containing term and type def stanzas from lines.
static member fromLines verbose (input : seq<string>) =

let en = input.GetEnumerator()
let rec loop (en:System.Collections.Generic.IEnumerator<string>) terms typedefs lineNumber =

match en.MoveNext() with
| true ->
match (en.Current |> trimComment) with
| "[Term]" ->
let lineNumber,parsedTerm = OboTerm.fromLines verbose en lineNumber "" "" false [] "" "" [] [] [] [] [] [] [] [] false [] [] [] false "" ""
loop en (parsedTerm :: terms) typedefs lineNumber
| "[Typedef]" ->
let lineNumber,parsedTypeDef = OboTypeDef.fromLines verbose en lineNumber "" "" "" "" [] [] false false false false false false false
loop en terms (parsedTypeDef :: typedefs) lineNumber
| _ -> loop en terms typedefs (lineNumber + 1)
| false -> OboOntology.create (List.rev terms) (List.rev typedefs)

loop en [] [] 1




let expected =
$"namespace ARCTokenization.StructuralOntology{NewLine}{NewLine} open ControlledVocabulary{NewLine}{NewLine} module Investigation ={NewLine}{NewLine} let Investigation_Metadata = CvTerm.create(\"INVMSO:00000001\", \"Investigation Metadata\", \"INVMSO\"){NewLine}{NewLine} let ONTOLOGY_SOURCE_REFERENCE = CvTerm.create(\"INVMSO:00000002\", \"ONTOLOGY SOURCE REFERENCE\", \"INVMSO\"){NewLine}{NewLine} let Term_Source_Name = CvTerm.create(\"INVMSO:00000003\", \"Term Source Name\", \"INVMSO\")"
|> String.replace "\r" ""
let actual =
CodeGeneration.toSourceCode "Investigation" InvestigationMetadata.ontology
|> String.splitS NewLine
|> Array.take 11
|> String.concat "\n"
|> String.replace "\r" ""

OBO.NET.OboOntology.toFile @"C:\Repos\CSBiology\OBO.NET\tests\OBO.NET.CodeGeneration.Tests\References\ReferenceOboFile.obo" InvestigationMetadata.ontology


// DEPRECATED


#I "src/FsOboParser/bin/Debug/netstandard2.0"
#I "src/FsOboParser/bin/Release/netstandard2.0"
#r "FsOboParser.dll"
Expand Down

0 comments on commit 4258b67

Please sign in to comment.