use of edu.stanford.bmir.protege.web.shared.form.data.FormDataPrimitive in project webprotege by protegeproject.
the class PropertyValueFormDataTranslator method toOWLObject.
private Set<OWLObject> toOWLObject(FormDataValue dataValue) {
if (dataValue instanceof FormDataPrimitive) {
FormDataPrimitive formDataPrimitive = (FormDataPrimitive) dataValue;
OWLObject owlObject = formDataPrimitive.toOWLObject();
return Collections.singleton(owlObject);
} else if (dataValue instanceof FormDataList) {
FormDataList formDataList = (FormDataList) dataValue;
return formDataList.getList().stream().flatMap(e -> toOWLObject(e).stream()).collect(toSet());
} else {
throw new RuntimeException("Cannot convert to OWL Object");
}
}
use of edu.stanford.bmir.protege.web.shared.form.data.FormDataPrimitive in project webprotege by protegeproject.
the class FormDataValueConverter method encodeObject.
@Override
public Object encodeObject(FormDataValue value, MappedField optionalExtraInfo) {
if (value instanceof FormDataObject) {
Document document = new Document();
FormDataObject object = (FormDataObject) value;
object.getMap().forEach((key, val) -> document.put(key, encodeObject(val, optionalExtraInfo)));
return document;
} else if (value instanceof FormDataList) {
List<Object> result = new ArrayList<>();
FormDataList list = (FormDataList) value;
list.getList().forEach(e -> result.add(encodeObject(e, optionalExtraInfo)));
return result;
} else if (value instanceof FormDataPrimitive) {
FormDataPrimitive primitive = (FormDataPrimitive) value;
if (primitive.isNumber()) {
return primitive.getValueAsDouble();
} else if (primitive.isString()) {
return primitive.getValueAsString();
} else if (primitive.isBoolean()) {
return primitive.getValueAsBoolean();
} else if (primitive instanceof FormDataPrimitive.LiteralPrimitive) {
OWLLiteral literal = primitive.asLiteral().get();
Document document = new Document();
document.put("literal", literal.getLiteral());
if (literal.isRDFPlainLiteral()) {
document.put("lang", literal.getLang());
} else {
document.put("datatype", literal.getDatatype());
}
return document;
} else if (primitive instanceof FormDataPrimitive.IRIPrimitive) {
return new Document("iri", primitive.asIRI().get().toString());
} else if (primitive instanceof FormDataPrimitive.OWLEntityPrimitive) {
OWLEntity entity = (OWLEntity) primitive.getValue();
return entityConverter.encodeObject(entity, optionalExtraInfo);
}
} else {
throw new RuntimeException("Unknown type of object " + value);
}
return null;
}
Aggregations