/** * @param literal the wrapped literal */ public RDFLiteral(OWLLiteral literal) { this(literal.getLiteral(), literal.getLang(), literal.getDatatype().getIRI()); }
@Override public void visit(OWLLiteral node) { writer.writeStartElement(LITERAL); if (node.hasLang()) { writer.writeLangAttribute(node.getLang()); } else if (!node.isRDFPlainLiteral() && !OWL2Datatype.XSD_STRING.matches(node.getDatatype())) { writer.writeDatatypeAttribute(node.getDatatype()); } writer.writeTextContent(node.getLiteral()); writer.writeEndElement(); }
@Override public void visit(OWLDataPropertyAssertionAxiom axiom) { process(axiom); axiom.getSubject().accept(this); axiom.getProperty().accept(this); axiom.getObject().accept(this); }
@Override public OWLLiteral visit(OWLLiteral node) { if (node.hasLang()) { return df.getOWLLiteral(node.getLiteral(), node.getLang()); } return df.getOWLLiteral(node.getLiteral(), get(node.getDatatype())); }
protected boolean isBuiltin(OWLLiteral node) { return node.getDatatype().isBuiltIn() && !node.getDatatype().getBuiltInDatatype().isInLexicalSpace(node.getLiteral()); }
private static boolean isStrictBooleanTrueLiteral(OWLLiteral literal) { return OWL2Datatype.XSD_BOOLEAN.getIRI().equals(literal.getDatatype().getIRI()) && Boolean.parseBoolean(literal.getLiteral()); }
public void visit(OWLNegativeDataPropertyAssertionAxiom axiom) { axiom.getSubject().accept(this); OWLIndividual ind = (OWLIndividual) obj; axiom.getProperty().accept(this); OWLDataPropertyExpression prop = (OWLDataPropertyExpression) obj; axiom.getObject().accept(this); OWLLiteral con = (OWLLiteral) obj; obj = dataFactory.getOWLNegativeDataPropertyAssertionAxiom(prop, ind, con, duplicateAxiomAnnotations(axiom)); }
/** * Adds the qualifiers. * * @param c the c * @param qualifier the qualifier */ protected static void addQualifiers(Clause c, OWLAnnotation qualifier) { String prop = owlObjectToTag(qualifier.getProperty()); if (prop == null) { prop = qualifier.getProperty().getIRI().toString(); } if (SKIPPED_QUALIFIERS.contains(prop)) { return; } String value = qualifier.getValue().toString(); if (qualifier.getValue() instanceof OWLLiteral) { value = ((OWLLiteral) qualifier.getValue()).getLiteral(); } else if (qualifier.getValue().isIRI()) { value = getIdentifier((IRI) qualifier.getValue()); } QualifierValue qv = new QualifierValue(prop, value); c.addQualifierValue(qv); }
@Override public void visit(OWLLiteral node) { String literal = EscapeUtils.escapeString(node.getLiteral()); if (node.isRDFPlainLiteral() || node.getDatatype().getIRI() .equals(OWL2Datatype.RDF_LANG_STRING.getIRI())) { // We can use a syntactic shortcut sb.append('"').append(literal).append('"'); if (node.hasLang()) { sb.append('@').append(node.getLang()); } } else { sb.append('"').append(literal).append("\"^^"); node.getDatatype().accept(this); } }
public void visit(@Nonnull OWLAnnotation annotation) { int propStart = builder.mark(); annotation.getProperty().accept(this); int propEnd = builder.mark(); builder.applyStyle(propStart, propEnd, ProtegeStyles.getStyles().getAnnotationPropertyStyle()); renderSpace(); if (annotation.getValue() instanceof OWLLiteral) { OWLLiteral literal = (OWLLiteral) annotation.getValue(); Style langStyle = ProtegeStyles.getStyles().getAnnotationLangStyle(); if (literal.isRDFPlainLiteral()) { if (!literal.getLang().isEmpty()) { builder.appendWithStyle("[language: ", langStyle); builder.appendWithStyle(literal.getLang(), langStyle); builder.appendWithStyle("] ", langStyle); } } else { builder.appendWithStyle("[type: ", langStyle); int dtStart = builder.mark(); literal.getDatatype().accept(this); int dtEnd = builder.mark(); builder.applyStyle(dtStart, dtEnd, langStyle); builder.appendWithStyle("] ", langStyle); } builder.append(literal.getLiteral()); } else { annotation.getValue().accept(this); } }
protected void expandAssertions(OWLOntology o, OWLAnnotationProperty p) { OWLAnnotationProperty ap425 = df.getOWLAnnotationProperty(IRI_IAO_0000425.getIRI()); getAnnotationObjects(p, o.importsClosure(), ap425).map(a -> a.getValue().asLiteral()) .filter(v -> v.isPresent()) .forEach(v -> { String str = v.get().getLiteral(); LOG.info("assertion mapping {} to {}", p, str); expandAssertionToMap.put(p.getIRI(), str); }); }
private Set<String> getAnnotation(OWLEntity entity, String property) { Set<String> annotations = new HashSet<>(); try { OWLAnnotationProperty owlAnnotationProperty = factory.getOWLAnnotationProperty(IRI.create(property)); for (OWLAnnotation annotation : entity.getAnnotations(ontology, owlAnnotationProperty)) { if (annotation.getValue() instanceof OWLLiteral) { OWLLiteral val = (OWLLiteral) annotation.getValue(); annotations.add(val.getLiteral()); } } } catch (Exception e) { throw new RuntimeException("Failed to get label for OWLClass " + entity); } return annotations; }
private boolean getIsRuleEnabled(@NonNull SWRLRule owlapiRule) { OWLAnnotationProperty enabledAnnotationProperty = getOWLDataFactory() .getOWLAnnotationProperty(IRI.create("http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled")); for (OWLAnnotation annotation : owlapiRule.getAnnotations(enabledAnnotationProperty)) { if (annotation.getValue() instanceof OWLLiteral) { OWLLiteral literal = (OWLLiteral)annotation.getValue(); if (literal.isBoolean()) return literal.parseBoolean(); } } return true; }
@Override public void visit(SWRLLiteralArgument node) { OWLLiteral literal=node.getLiteral(); if (literal.isBoolean()) terms.add(fac.getBooleanConstant(literal.parseBoolean())); else if(literal.hasLang()) terms.add(fac.getConstantLiteral(literal.getLiteral(), literal.getLang())); else if (literal.isDouble()) terms.add(fac.getConstantLiteral(literal.getLiteral(), Predicate.COL_TYPE.DOUBLE)); else if (literal.isFloat()) terms.add(fac.getConstantLiteral(literal.getLiteral(), Predicate.COL_TYPE.DECIMAL)); else if (literal.isInteger()) terms.add(fac.getConstantLiteral(literal.getLiteral(), Predicate.COL_TYPE.INTEGER)); else fac.getConstantLiteral(literal.getLiteral()); }
public String getOntologyLabel() { OWLAnnotationProperty labelProperty = factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()); String ontologyLabel = StringUtils.EMPTY; for (OWLAnnotation annotation : ontology.getAnnotations()) { if (annotation.getProperty().equals(labelProperty) && annotation.getValue() instanceof OWLLiteral) { OWLLiteral val = (OWLLiteral) annotation.getValue(); ontologyLabel = val.getLiteral(); } } return ontologyLabel; }
protected void examineAssertion(OWLPrimitive owlEntity, Set<OWLAxiom> axioms, OWLAnnotationAssertionAxiom ax) { if (ax.getSubject().equals(owlEntity)) { axioms.add(ax); } else { ax.getValue().asLiteral().ifPresent(lit -> { if (OWL2Datatype.XSD_ANY_URI.matches(lit.getDatatype()) && lit.getLiteral().equals(owlEntity.toString())) { axioms.add(ax); } }); } }
public void visit(@Nonnull OWLLiteral owlLiteral) { if (owlLiteral.isBoolean()) { builder.append(owlLiteral.getLiteral()); } else if (owlLiteral.isDouble()) { builder.append(owlLiteral.getLiteral()); } else if (owlLiteral.isFloat()) { builder.append(owlLiteral.getLiteral()); } else if (owlLiteral.isInteger()) { builder.append(owlLiteral.getLiteral()); } else { builder.append("\""); builder.append(owlLiteral.getLiteral()); builder.append("\"^^"); owlLiteral.getDatatype().accept(this); } }
/** * Pre process. */ protected void preProcess() { // converse of postProcess in obo2owl String viewRel = null; OWLAnnotationProperty logicalDef = manager.getOWLDataFactory().getOWLAnnotationProperty( Obo2OWLVocabulary.IRI_OIO_LogicalDefinitionViewRelation.getIRI()); List<OWLAnnotation> collect = asList(getOWLOntology().annotations(logicalDef)); for (OWLAnnotation ann : collect) { OWLAnnotationValue v = ann.getValue(); if (v instanceof OWLLiteral) { viewRel = ((OWLLiteral) v).getLiteral(); } else if (v.isIRI()) { viewRel = getIdentifier((IRI) v); } break; } if (viewRel == null) { return; } String view = viewRel; Set<OWLAxiom> rmAxioms = new HashSet<>(); Set<OWLAxiom> newAxioms = new HashSet<>(); getOWLOntology().axioms(AxiomType.EQUIVALENT_CLASSES) .forEach(eca -> preprocessEquivalents(view, rmAxioms, newAxioms, eca)); getOWLOntology().remove(rmAxioms); getOWLOntology().add(newAxioms); }
@NonNull private String getRuleComment(@NonNull SWRLRule owlapiRule) { OWLAnnotationProperty commentAnnotationProperty = getOWLDataFactory() .getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_COMMENT.getIRI()); for (OWLAnnotation annotation : owlapiRule.getAnnotations(commentAnnotationProperty)) { if (annotation.getValue() instanceof OWLLiteral) { OWLLiteral literal = (OWLLiteral)annotation.getValue(); return literal.getLiteral(); // We pick the first one } } return ""; }
private Label getLabel (OWLClass c, OWLOntology ont) { Label classLabel = new Label(null, null); for (OWLAnnotation annotation : c.getAnnotations(ont, this.dataFactory.getRDFSLabel())) { if (annotation.getValue() instanceof OWLLiteral) { OWLLiteral val = (OWLLiteral) annotation.getValue(); classLabel.setText(val.getLiteral().replace("'", "\\'")); classLabel.setLang(val.getLang()); } } return classLabel; }