Commit ff936590 authored by Thorsten Wißmann's avatar Thorsten Wißmann
Browse files

Parse OWL prefixes

parent 6261fa28
......@@ -53,4 +53,5 @@ let flip f y x = f x y
let eval a f = f a
let id a = a
let foreach_l a f = List.iter f a
let (<<) f g x = f(g(x))
......@@ -27,3 +27,5 @@ val flip : ('a -> 'b -> 'c) -> ('b -> 'a -> 'c)
val eval : 'a -> ('a -> 'b) -> 'b
val id : 'a -> 'a
val foreach_l : ('a list) -> ('a -> unit) -> unit
val (<<) : ('b -> 'c) -> ('a -> 'b) -> ('a -> 'c)
......@@ -182,15 +182,27 @@ let rec tree_of_intree it =
in
Node (tree_list_of_intree it)
let parse_prefix a lst : OWL.prefix =
match lst with
| [INode ((str,a),[])] -> (
match split (regexp "=") str with
| [l;r] -> (l,r)
| _ -> raise (ParseError (a,("Invalid Prefix-Definition")))
)
| _ -> raise (ParseError (a,("Missing Prefix-definition")))
let parse_intree_list (strAnIts: string annotated intree list) =
let prefixes = ref [] in
let prefs : OWL.prefixes ref = ref [] in
let ontos = ref [] in
let ap (lref:'a list ref) (el:'a): unit =
(lref := ((!lref) @ [el]))
in
foreach_l strAnIts (fun f -> match f with
| INode (("Prefix", _), lst) -> ()
| INode (("Prefix", a), lst) -> (ap prefs (parse_prefix a lst))
| INode (("Ontology", _), lst) -> ()
| INode ((n, a), _) -> raise (ParseError (a,(
"Unknown toplevel element \""^n^"\""))));
(!prefixes, !ontos)
(!prefs, !ontos)
let parse str =
let tree = tree_of_string str in
......
......@@ -24,9 +24,11 @@ let owlcat () =
let show sometree =
(OWLFP.string_of_intree (OWLFP.string_of_annotated id) sometree)
in
let ast = String.concat "\n" (L.map show ts) in
let ast:string = String.concat "\n" (L.map show ts) in
let _ = ast in
print_endline ast
let (ps,os) = OWLFP.parse content in
foreach_l ps (print_endline << string_of_prefix);
foreach_l os (print_endline << string_of_ontology)
(*
print_endline (OWLFP.string_of_tree (OWLFP.string_of_annotated id) t)
*)
......@@ -57,7 +59,11 @@ let _ =
let cmd = Sys.argv.(1) in
try (
let (_,f,_) = List.find (fun (n,_,_) -> (n = cmd)) subcmds in
f ()
try f ()
with | OWLFP.ParseError (a,str) -> (
print_endline ((OWLFP.string_of_annotation a)^": "^str);
exit 1
)
) with Not_found -> (
Printf.printf "Error: Subcommand %s not found.\n" cmd;
printUsage ()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment