]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/mathql_interpreter/property.ml
Relation patched, property added.
[helm.git] / helm / ocaml / mathql_interpreter / property.ml
1 (* Copyright (C) 2000, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (*
27  *
28  *)
29
30 open Dbconn;;
31 open Utility;;
32 open Intersect;;
33
34
35 let getpid p =
36   if (p = "refObj") then "F"
37   else "B"
38 ;;
39
40 (*
41  * implementazione delle funzioni dublin core
42  *)
43 let rec property_ex rop path inv = function
44     [] -> []
45   | s::tl -> let mprop = fst path in
46              print_endline mprop;
47              let prop = List.hd (snd path) in
48              match mprop with
49                
50                "refObj" (* in base al valore di prop restituisco i valori del relativo campo della tabella relativa all'uri rappresentata da s *)
51              | "backPointer" ->
52                print_endline mprop;
53                let mpid = getpid mprop in
54                let res =
55                let c = pgc () in
56                let tv = pgresult_to_string (c#exec ("select id from registry where uri='" ^ s ^ "'")) in
57                let q = "select t" ^ tv ^ "." ^ prop ^  "  from t" ^ tv ^ " where prop_id= '" ^ mpid ^ "'" in
58                 print_endline q;
59                 pgresult_to_string_list (c#exec q)
60                in
61                  append (res,(property_ex rop path inv tl))
62                
63                           (*Rimane da capire cosa restituire  nelle inverse!!!!*)
64                            
65                
66              | "refRel"
67              | "refSort" ->
68              if inv then     (* restituisco gli uri che il valore della prop richiesta uguale a s *)
69                let res =
70                let c = pgc () in
71                let q = ("select h" ^ mprop ^ ".uri from h" ^ mprop ^ " where h" ^ mprop ^ "." ^ prop ^ "= '" ^ s ^ "'") in
72                  print_endline q;
73                  pgresult_to_string_list (c#exec q)
74                in
75                  append (res,(property_ex rop path inv tl))
76                
77              else
78                let res =         (* restituisco il valore della prop relativo all'uri rappresentato da s*)
79                let c = pgc () in
80                let q = ("select h" ^ mprop ^ "." ^ prop ^" from h" ^ mprop ^ " where h" ^ mprop ^ ".uri = '" ^ s ^ "'") in
81                  pgresult_to_string_list (c#exec q)
82                in
83                  append (res,(property_ex rop path inv tl))
84                
85              
86              
87              | _ ->        (* metadati DC  !!!! Controllare se i nomi delle tabelle cominciano con h !!!!*)
88              if inv then
89                let res =
90                let c = pgc () in
91                let q = ("select " ^ mprop ^ ".uri from " ^ mprop ^ " where " ^ mprop ^ ".value = '" ^ s ^ "'") in
92                  pgresult_to_string_list (c#exec q)
93                in
94                  append (res,(property_ex rop path inv tl))
95              else
96                let res =
97                let c = pgc () in
98                let q = ("select " ^ mprop ^ ".value from " ^ mprop ^ " where " ^ mprop ^ ".uri = '" ^ s ^ "'") in
99                  pgresult_to_string_list (c#exec q)
100                in
101                  append (res,(property_ex rop path inv tl))
102
103 ;;
104