Debian Codegraph @

wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/values/EntityIdValueConverter.java

raw
1 package org.wikidata.wdtk.rdf.values;
2
3 /*
4 * #%L
5 * Wikidata Toolkit RDF
6 * %%
7 * Copyright (C) 2014 Wikidata Toolkit Developers
8 * %%
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * #L%
21 */
22
23 import org.eclipse.rdf4j.model.Value;
24 import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue;
25 import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
26 import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
27 import org.wikidata.wdtk.rdf.OwlDeclarationBuffer;
28 import org.wikidata.wdtk.rdf.PropertyRegister;
29 import org.wikidata.wdtk.rdf.RdfWriter;
30
31 public class EntityIdValueConverter extends
32 AbstractValueConverter<EntityIdValue> {
33
34 public EntityIdValueConverter(RdfWriter rdfWriter,
35 PropertyRegister propertyRegister,
36 OwlDeclarationBuffer rdfConversionBuffer) {
37 super(rdfWriter, propertyRegister, rdfConversionBuffer);
38 }
39
40 @Override
41 public Value getRdfValue(EntityIdValue value,
42 PropertyIdValue propertyIdValue, boolean simple) {
43 String datatype = this.propertyRegister
44 .setPropertyTypeFromEntityIdValue(propertyIdValue, value);
45
46 if(datatype == null) {
47 // we failed to guess the datatype: represent the value by a blank node
48 return this.rdfWriter.getFreshBNode();
49 }
50
51 switch (datatype) {
52 case DatatypeIdValue.DT_ITEM:
53 case DatatypeIdValue.DT_PROPERTY:
54 case DatatypeIdValue.DT_LEXEME:
55 case DatatypeIdValue.DT_FORM:
56 case DatatypeIdValue.DT_SENSE:
57 if (simple) {
58 this.rdfConversionBuffer.addObjectProperty(propertyIdValue);
59 return this.rdfWriter.getUri(value.getIri());
60 } else {
61 return null;
62 }
63 default:
64 logIncompatibleValueError(propertyIdValue, datatype, "entity");
65 return this.rdfWriter.getFreshBNode();
66 }
67 }
68 }