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

Parse basic OWL Annotations

parent 54b29b1f
......@@ -29,6 +29,7 @@ type declaration =
type axiom =
| ANNOTATION of string
(* class expression axioms *)
| DECLARATION of declaration
| SUBCLASS of class_exp * class_exp
......@@ -78,6 +79,7 @@ let string_of_class_exp ce =
let string_of_axiom ax =
let soc = string_of_class_exp in
match ax with
| ANNOTATION str -> "»"^str^"«"
| DECLARATION a -> "Declaration (TODO)"
| SUBCLASS (a,b) -> (soc a) ^" ⊑ "^(soc b)
| EQUIVALENTCLASSES la -> String.concat " ≡ " (L.map soc la)
......
......@@ -26,6 +26,7 @@ type declaration =
| NAMEDINDIVIDUAL of uri
type axiom =
| ANNOTATION of string
(* class expression axioms *)
| DECLARATION of declaration
| SUBCLASS of class_exp * class_exp
......
......@@ -49,6 +49,9 @@ let list_of_stream stream =
let cons a b = a::b in
L.rev (stream_fold cons stream [])
let rec intree_flatten (INode (v,sub)) : 'a list =
v :: L.concat (L.map intree_flatten sub)
let tokens_of_string_stream (lines:string Stream.t) : string annotated list =
let lastline = ref 0 in
let nextline () =
......@@ -198,21 +201,40 @@ let parse_role t : OWL.role = match t with
let rec parse_class_exp (INode ((name,anno), sub): string annotated intree) : OWL.class_exp =
let pr = parse_role in
let pc = parse_class_exp in
if (String.contains name ':') then (OWL.NAMED name)
if (String.contains name ':') then
match name with
| "owl:Thing" -> OWL.THING
| "owl:Nothing" -> OWL.NOTHING
| _ -> (OWL.NAMED name)
else match name, sub with
| "ObjectSomeValuesFrom", [role; obj] -> OWL.SOME (pr role, pc obj)
| "ObjectSomeValuesFrom", _ ->
raise (ParseError(anno, name^" requires exactly one role and a class expression"))
| "ObjectAllValuesFrom", [role; obj] -> OWL.ALL (pr role, pc obj)
| "ObjectAllValuesFrom", _ ->
raise (ParseError(anno, name^" requires exactly one role and a class expression"))
| "ObjectIntersectionOf", _ -> OWL.AND (L.map pc sub)
| "ObjectUnionOf", _ -> OWL.OR (L.map pc sub)
| "ObjectComplementOf", [c] -> OWL.NOT (pc c)
| "ObjectMinCardinality", _
| "ObjectMaxCardinality", _
| "ObjectExactCardinality", _
| "ObjectOneOf", _
| "ObjectHasValue", _
| "ObjectHasSelf", _
| "DataSomeValuesFrom", _
| "DataAllValuesFrom", _
| "DataHasValue", _
| "DataMinCardinality", _
| "DataMaxCardinality", _
| "DataExactCardinality", _ -> raise (ParseError (anno, name^" not implemented yet."))
| _,_ ->
raise (ParseError(anno, "Unknown class expression name \""^name^"\""))
raise (ParseError(anno, "Unknown class expression name \""^name^"\" or wrong parameter count"))
let parse_axiom (ax: string annotated intree) : OWL.axiom =
let INode ((name,anno), sub) = ax in
let pce = parse_class_exp in
match name with
| "Annotation" -> let sub = L.map intree_flatten sub in (* flatten structure *)
let sub = L.concat sub in (* flatten more...*)
let sub = L.map (fun (s,_) -> s) sub in (* drop annotations *)
OWL.ANNOTATION (String.concat " " sub)
| "Declaration" -> (match sub with
| [(INode ((name,anno),[INode ((child,_),[])]))] ->
(match name with
......
......@@ -16,6 +16,7 @@ type 'a intree = (* tree carrying values in leafes and inner nodes *)
val intree_list_of_tree : 'a tree -> 'a intree list
val tree_of_intree : 'a intree -> 'a tree
val intree_flatten : 'a intree -> 'a list
val list_of_stream : 'a Stream.t -> 'a list
val string_of_annotation : annotation -> string
......
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