|
18 | 18 | */ |
19 | 19 | package ubic.basecode.ontology.jena; |
20 | 20 |
|
| 21 | +import com.hp.hpl.jena.datatypes.DatatypeFormatException; |
21 | 22 | import com.hp.hpl.jena.datatypes.xsd.XSDDateTime; |
22 | 23 | import com.hp.hpl.jena.ontology.OntModel; |
23 | 24 | import com.hp.hpl.jena.ontology.OntResource; |
@@ -223,28 +224,35 @@ private static Directory index( String name, OntModel model, Analyzer analyzer, |
223 | 224 | Fieldable f; |
224 | 225 | if ( s.getObject().isLiteral() ) { |
225 | 226 | Literal l = s.getObject().asLiteral(); |
226 | | - if ( l.getValue() instanceof String ) { |
227 | | - f = new Field( field, l.getString(), Field.Store.NO, indexablePropertiesByField.get( field ).isAnalyzed() ? Field.Index.ANALYZED : Field.Index.NOT_ANALYZED ); |
228 | | - } else if ( l.getValue() instanceof Number ) { |
| 227 | + Object v; |
| 228 | + try { |
| 229 | + v = l.getValue(); |
| 230 | + } catch ( DatatypeFormatException e ) { |
| 231 | + log.warn( "Invalid datatype for literal: {}", l, e ); |
| 232 | + continue; |
| 233 | + } |
| 234 | + if ( v instanceof String ) { |
| 235 | + f = new Field( field, ( String ) v, Field.Store.NO, indexablePropertiesByField.get( field ).isAnalyzed() ? Field.Index.ANALYZED : Field.Index.NOT_ANALYZED ); |
| 236 | + } else if ( v instanceof Number ) { |
229 | 237 | NumericField nf = new NumericField( field ); |
230 | | - if ( l.getValue() instanceof Integer ) { |
231 | | - nf.setIntValue( s.getInt() ); |
232 | | - } else if ( l.getValue() instanceof Long ) { |
233 | | - nf.setLongValue( s.getLong() ); |
234 | | - } else if ( l.getValue() instanceof Float ) { |
235 | | - nf.setFloatValue( s.getFloat() ); |
236 | | - } else if ( l.getValue() instanceof Double ) { |
237 | | - nf.setDoubleValue( s.getDouble() ); |
| 238 | + if ( v instanceof Integer ) { |
| 239 | + nf.setIntValue( ( Integer ) v ); |
| 240 | + } else if ( v instanceof Long ) { |
| 241 | + nf.setLongValue( ( Long ) v ); |
| 242 | + } else if ( v instanceof Float ) { |
| 243 | + nf.setFloatValue( ( Float ) v ); |
| 244 | + } else if ( v instanceof Double ) { |
| 245 | + nf.setDoubleValue( ( Double ) v ); |
238 | 246 | } else { |
239 | 247 | log.warn( "Skipping numeric literal of unsupported type: {}", l ); |
240 | 248 | continue; |
241 | 249 | } |
242 | 250 | f = nf; |
243 | | - } else if ( l.getValue() instanceof XSDDateTime ) { |
| 251 | + } else if ( v instanceof XSDDateTime ) { |
244 | 252 | f = new NumericField( field ) |
245 | | - .setLongValue( ( ( XSDDateTime ) l.getValue() ).asCalendar().getTime().getTime() ); |
246 | | - } else if ( l.getValue() instanceof Boolean ) { |
247 | | - f = new NumericField( field ).setIntValue( Boolean.TRUE.equals( l.getValue() ) ? 1 : 0 ); |
| 253 | + .setLongValue( ( ( XSDDateTime ) v ).asCalendar().getTime().getTime() ); |
| 254 | + } else if ( v instanceof Boolean ) { |
| 255 | + f = new NumericField( field ).setIntValue( Boolean.TRUE.equals( v ) ? 1 : 0 ); |
248 | 256 | } else { |
249 | 257 | log.warn( "Skipping literal of unsupported type: {}", l ); |
250 | 258 | continue; |
|
0 commit comments