Skip to content
Snippets Groups Projects
Commit 58c30aee authored by Thorsten Wißmann's avatar Thorsten Wißmann
Browse files

Implement tree printing

parent 090c8b8a
No related branches found
No related tags found
No related merge requests found
......@@ -50,4 +50,6 @@ let intlist_of_string str = List.map int_of_string (Str.split (Str.regexp "[ \t,
let compose f g x = f (g (x))
let flip f y x = f x y
let eval a f = f a
let id a = a
......@@ -24,3 +24,5 @@ val intlist_of_string : string -> int list
val compose : ('b -> 'c) -> ('a -> 'b) -> ('a -> 'c)
val flip : ('a -> 'b -> 'c) -> ('b -> 'a -> 'c)
val eval : 'a -> ('a -> 'b) -> 'b
val id : 'a -> 'a
module L = List
open CoolUtils
open Str
open Stream
......@@ -42,7 +43,7 @@ let line_stream_of_string string =
let list_of_stream stream =
let cons a b = a::b in
stream_fold cons stream []
L.rev (stream_fold cons stream [])
let tokens_from_string (buf:string) : string annotated list =
let lastline = ref 0 in
......@@ -71,6 +72,9 @@ let tokens_from_string (buf:string) : string annotated list =
let string_of_annotation (file,line,col) =
file ^ ":" ^ (string_of_int line) ^ ":" ^ (string_of_int col)
let string_of_annotated str_of_a (obj,anno) : string =
string_of_annotation anno ^ " " ^ str_of_a obj
let tree_of_tokens lst : string annotated tree =
let stream:string annotated Stream.t = Stream.of_list lst in
(* returns the next tree in our forest *)
......@@ -93,5 +97,11 @@ let tree_of_tokens lst : string annotated tree =
let forest = list_of_stream (Stream.from (fun _ -> tree_of_token_stream ())) in
Node forest
let string_of_tree str_of_a atree : string =
let indent str = " "^str in
let rec lines_of_tree t = match t with
| (Leaf a) -> [str_of_a a]
| (Node lst) -> L.map indent (L.concat (L.map lines_of_tree lst))
in
String.concat "\n" (lines_of_tree atree)
......@@ -10,9 +10,13 @@ type 'a tree =
| Leaf of 'a
| Node of (('a tree) list)
val list_of_stream : 'a Stream.t -> 'a list
val string_of_annotation : annotation -> string
val string_of_annotated : ('a -> string) -> 'a annotated -> string
val tokens_from_string : string -> string annotated list
val tree_of_tokens : string annotated list -> string annotated tree
val string_of_tree : ('a -> string) -> 'a tree -> string
(*val parse : string -> OWL.Ontology *)
......@@ -6,6 +6,9 @@
module CM = CoAlgMisc
module CF = CoAlgFormula
module OWLFP = OWLFunctionalParser
open CoolUtils
(* The type of formulae that are accepted. *)
(*
......@@ -37,7 +40,7 @@ let _ = Gc.set { (Gc.get()) with Gc.minor_heap_size = 4194304; major_heap_increm
let printUsage () =
print_endline "Usage: \"alc <task> <functor> [<flags>]\" where";
print_endline " <task> in { sat print nnf prov (is »not.(sat ¬f)«) }";
print_endline " <task> in { sat print nnf prov (is »not.(sat ¬f)«) owlcat }";
print_endline " <functor> in { MultiModalK MultiModalKD CoalitionLogic GML";
print_endline " (or: K) (or: KD) (or: CL) }";
print_endline " <flags> = a list of the following items";
......@@ -142,6 +145,18 @@ let choiceNNF () =
done
with End_of_file -> ()
let choiceOWLCat () =
let buf = ref "" in
try
while true do
let input = read_line () in
buf := !buf ^ input ^ "\n"
done
with End_of_file -> () ;
let t = OWLFP.tree_of_tokens (OWLFP.tokens_from_string !buf) in
print_endline (OWLFP.string_of_tree (OWLFP.string_of_annotated id) t)
let rec parseFlags arr offs : unit =
let offs = ref (offs) in
let getParam () =
......@@ -173,6 +188,7 @@ let _ =
| "prov" -> choiceProvable ()
| "print" -> choicePrint ()
| "nnf" -> choiceNNF ()
| "owlcat" -> choiceOWLCat ()
| _ -> printUsage ()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment