Search in sources :

Example 1 with IncorrectPropertyCountException

use of won.protocol.exception.IncorrectPropertyCountException in project webofneeds by researchstudio-sat.

the class SolrMatcherEvaluation method createNeedId.

public static String createNeedId(Dataset need) {
    String title = "";
    String description = "";
    try {
        DefaultNeedModelWrapper needModelWrapper = new DefaultNeedModelWrapper(need);
        title = needModelWrapper.getTitles(NeedContentPropertyType.ALL).iterator().next();
        title = title.replaceAll("[^A-Za-z0-9 ]", "_");
        title = title.replaceAll("NOT", "_");
        title = title.replaceAll("AND", "_");
        title = title.replaceAll("OR", "_");
        description = needModelWrapper.getSomeDescription(NeedContentPropertyType.ALL);
    } catch (IncorrectPropertyCountException e) {
    // do nothing
    }
    if (title.isEmpty()) {
        throw new IllegalArgumentException("need has no title!!");
    }
    return title + "_" + (title + description).hashCode();
}
Also used : DefaultNeedModelWrapper(won.protocol.util.DefaultNeedModelWrapper) IncorrectPropertyCountException(won.protocol.exception.IncorrectPropertyCountException)

Example 2 with IncorrectPropertyCountException

use of won.protocol.exception.IncorrectPropertyCountException in project webofneeds by researchstudio-sat.

the class SolrMatcherEvaluation method createAtomId.

public static String createAtomId(Dataset atom) {
    String title = "";
    String description = "";
    try {
        DefaultAtomModelWrapper atomModelWrapper = new DefaultAtomModelWrapper(atom);
        title = atomModelWrapper.getAllTitles().iterator().next();
        title = title.replaceAll("[^A-Za-z0-9 ]", "_");
        title = title.replaceAll("NOT", "_");
        title = title.replaceAll("AND", "_");
        title = title.replaceAll("OR", "_");
        description = atomModelWrapper.getSomeDescription();
    } catch (IncorrectPropertyCountException e) {
    // do nothing
    }
    if (title.isEmpty()) {
        throw new IllegalArgumentException("atom has no title!!");
    }
    return title + "_" + (title + description).hashCode();
}
Also used : DefaultAtomModelWrapper(won.protocol.util.DefaultAtomModelWrapper) IncorrectPropertyCountException(won.protocol.exception.IncorrectPropertyCountException)

Example 3 with IncorrectPropertyCountException

use of won.protocol.exception.IncorrectPropertyCountException in project webofneeds by researchstudio-sat.

the class LinkedDataWebController method getObjectOfPropertyAsString.

private String getObjectOfPropertyAsString(org.apache.jena.rdf.model.Model model, Property property) {
    NodeIterator nodeIteratr = model.listObjectsOfProperty(property);
    if (!nodeIteratr.hasNext()) {
        return null;
    }
    String ret = nodeIteratr.next().asLiteral().getString();
    if (nodeIteratr.hasNext()) {
        throw new IncorrectPropertyCountException("found more than one property of cnt:bytes", 1, 2);
    }
    return ret;
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) IncorrectPropertyCountException(won.protocol.exception.IncorrectPropertyCountException)

Example 4 with IncorrectPropertyCountException

use of won.protocol.exception.IncorrectPropertyCountException in project webofneeds by researchstudio-sat.

the class NeedModelWrapper method getContentPropertyObject.

private Node getContentPropertyObject(NeedContentPropertyType type, String propertyPath) {
    Path path = PathParser.parse(propertyPath, DefaultPrefixUtils.getDefaultPrefixes());
    Collection<Resource> nodes = getContentNodes(type);
    if (nodes.size() != 1) {
        throw new IncorrectPropertyCountException("expected exactly one occurrence of object for property path " + propertyPath, 1, nodes.size());
    }
    Node node = nodes.iterator().next().asNode();
    return RdfUtils.getNodeForPropertyPath(getNeedModel(), node, path);
}
Also used : Path(org.apache.jena.sparql.path.Path) Node(org.apache.jena.graph.Node) IncorrectPropertyCountException(won.protocol.exception.IncorrectPropertyCountException)

Example 5 with IncorrectPropertyCountException

use of won.protocol.exception.IncorrectPropertyCountException in project webofneeds by researchstudio-sat.

the class RdfDatasetAttachmentConverter method getObjectOfPropertyAsString.

private String getObjectOfPropertyAsString(Model model, Property property) {
    NodeIterator nodeIteratr = model.listObjectsOfProperty(property);
    if (!nodeIteratr.hasNext())
        return null;
    String ret = nodeIteratr.next().asLiteral().getString();
    if (nodeIteratr.hasNext()) {
        throw new IncorrectPropertyCountException("found more than one property of cnt:bytes", 1, 2);
    }
    return ret;
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) IncorrectPropertyCountException(won.protocol.exception.IncorrectPropertyCountException)

Aggregations

IncorrectPropertyCountException (won.protocol.exception.IncorrectPropertyCountException)7 NodeIterator (org.apache.jena.rdf.model.NodeIterator)2 OutputStream (java.io.OutputStream)1 Node (org.apache.jena.graph.Node)1 Path (org.apache.jena.sparql.path.Path)1 DefaultAtomModelWrapper (won.protocol.util.DefaultAtomModelWrapper)1 DefaultNeedModelWrapper (won.protocol.util.DefaultNeedModelWrapper)1