@@ -75,9 +75,58 @@ pub fn translate_named_entity(v: &Value) -> Value {
7575 json ! ( o)
7676}
7777
78+
79+ pub fn strip_rdf_literal ( v : & Value ) -> Value {
80+ match v. as_str ( ) {
81+ Some ( s) if s. starts_with ( '"' ) => {
82+ let bytes = s. as_bytes ( ) ;
83+ let mut i = 1usize ;
84+ let mut escaped = false ;
85+
86+ while i < bytes. len ( ) {
87+ match bytes[ i] {
88+ b'\\' if !escaped => { escaped = true ; }
89+ b'"' if !escaped => {
90+ // Found closing quote
91+ return json ! ( & s[ 1 ..i] ) ;
92+ }
93+ _ => { escaped = false ; }
94+ }
95+ i += 1 ;
96+ }
97+ // No closing quote found → return unchanged
98+ json ! ( s)
99+ }
100+ Some ( s) => json ! ( s) , // not a quoted literal
101+ None => v. clone ( ) , // not a string
102+ }
103+ }
104+
105+
78106pub fn get_object ( v : & Value ) -> Value {
79- let o: Value = translate ( & v) ;
107+ let mut o: Value = translate ( v) ;
80108 let d: String = String :: from ( util:: translate_datatype ( & o) . as_str ( ) . unwrap ( ) ) ;
109+ if d == "<http://www.w3.org/2001/XMLSchema#string>" ||
110+ d == "<http://www.w3.org/2001/XMLSchema#boolean>" ||
111+ d == "<http://www.w3.org/2001/XMLSchema#integer>" ||
112+ d == "<http://www.w3.org/2001/XMLSchema#decimal>" ||
113+ d == "<http://www.w3.org/2001/XMLSchema#integer" ||
114+ d == "<http://www.w3.org/2001/XMLSchema#nonNegativeInteger" ||
115+ d == "<http://www.w3.org/2001/XMLSchema#nonPositiveInteger" ||
116+ d == "<http://www.w3.org/2001/XMLSchema#positiveInteger" ||
117+ d == "<http://www.w3.org/2001/XMLSchema#negativeInteger" ||
118+ d == "<http://www.w3.org/2001/XMLSchema#long" ||
119+ d == "<http://www.w3.org/2001/XMLSchema#int" ||
120+ d == "<http://www.w3.org/2001/XMLSchema#short" ||
121+ d == "<http://www.w3.org/2001/XMLSchema#byte" ||
122+ d == "<http://www.w3.org/2001/XMLSchema#unsignedLong" ||
123+ d == "<http://www.w3.org/2001/XMLSchema#unsignedInt" ||
124+ d == "<http://www.w3.org/2001/XMLSchema#unsignedShort" ||
125+ d == "<http://www.w3.org/2001/XMLSchema#unsignedByte" ||
126+ d == "<http://www.w3.org/2002/07/owl#real>" ||
127+ d == "<http://www.w3.org/2002/07/owl#rational>" {
128+ o = strip_rdf_literal ( & o) ;
129+ } ;
81130
82131 json ! ( { "object" : o,
83132 "datatype" : d} )
@@ -141,7 +190,7 @@ pub fn translate_has_value(v: &Value) -> Value {
141190
142191pub fn translate_has_self ( v : & Value ) -> Value {
143192 let property_o: Value = get_object ( & v[ 1 ] ) ;
144- let has_self_o: Value = get_object ( & json ! ( "true^^xsd: boolean" ) ) ;
193+ let has_self_o: Value = get_object ( & json ! ( "\" true\" ^^<http://www.w3.org/2001/XMLSchema# boolean> " ) ) ;
145194 let type_o: Value = get_object ( & json ! ( "<http://www.w3.org/2002/07/owl#Restriction>" ) ) ;
146195
147196 json ! ( { "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>" : vec![ type_o] ,
0 commit comments