Project

General

Profile

Statistics
| Branch: | Revision:

cool / src / owl / OWL.ml @ 7c4d2eb4

History | View | Annotate | Download (1.96 KB)

1

    
2
open CoolUtils
3
module L = List
4

    
5
(* Just a copy'n'paste from the *.mli file *)
6
type uri = string
7
type role = uri
8

    
9
type class_exp =
10
  | THING
11
  | NOTHING
12
  | NAMED   of uri
13
  | NOT     of class_exp
14
  | AND     of class_exp list
15
  | OR      of class_exp list
16
  | SOME    of role * class_exp
17
  | ALL     of role * class_exp
18
  | MIN     of int * role * class_exp
19
  | MAX     of int * role * class_exp
20
  (* TODO: | OneOf of  * formula *)
21

    
22

    
23
type axiom =
24
  (* class expression axioms *)
25
  | SUBCLASS of class_exp * class_exp
26
  | EQUIVALENTCLASSES of class_exp list
27
  | DISJOINTCLASSES of class_exp list
28

    
29
type ontology = axiom list
30

    
31
(* actual content *)
32
let dummy = "remove this as soon there are any useful declarations"
33

    
34

    
35
let precedence ce = match ce with
36
    | THING | NOTHING -> 0
37
    | NAMED _ -> 0
38
    | NOT _ -> 1
39
    | SOME (_,_) | ALL  (_,_)  -> 2
40
    | MIN (_,_,_)     | MAX  (_,_,_) -> 2
41
    | AND _       | OR  _    -> 3
42

    
43
let string_of_role : role -> string = id
44

    
45
let string_of_class_exp ce =
46
    let rec soc oldpred ce =
47
        let p = precedence ce in
48
        (if p >= oldpred then "(" else "")^(
49
        let s = soc p in (* something like "show" *)
50
        match ce with
51
            | THING     -> "⊤"
52
            | NOTHING   -> "⊥"
53
            | NAMED u   -> u
54
            | NOT c -> "¬"^(s c)
55
            | AND la -> String.concat " ⊓ " (L.map s la)
56
            | OR  la -> String.concat " ⊔ " (L.map s la)
57
            | SOME (r,c) -> "∃"^(string_of_role r)^"."^(s c)
58
            | ALL  (r,c) -> "∀"^(string_of_role r)^"."^(s c)
59
            | MIN  (n,r,c) -> "≥"^(string_of_role r)^"."^(s c)
60
            | MAX  (n,r,c) -> "≤"^(string_of_role r)^"."^(s c)
61
        )^(if p >= oldpred then ")" else "")
62
    in
63
    soc 10 ce
64

    
65
let string_of_axiom ax =
66
    let soc = string_of_class_exp in
67
    match ax with
68
    | SUBCLASS (a,b) -> (soc a) ^" ⊑ "^(soc b)
69
    | EQUIVALENTCLASSES la -> String.concat " ≡ " (L.map soc la)
70
    | DISJOINTCLASSES la -> String.concat " ⊍ " (L.map soc la)
71

    
72