Skip to content

Commit

Permalink
working on shacl
Browse files Browse the repository at this point in the history
  • Loading branch information
jimkont committed Sep 26, 2015
1 parent de22e0b commit 2015e28
Show file tree
Hide file tree
Showing 12 changed files with 530 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.aksw.rdfunit.model.helper;

import com.google.common.collect.Maps;
import com.google.common.collect.Range;
import com.hp.hpl.jena.rdf.model.Property;

import java.util.HashMap;
import java.util.Set;

/**
* Description
*
* @author Dimitris Kontokostas
* @since 8/28/15 8:47 PM
*/
public final class AnnotationTemplate {
private final HashMap<Property, Range<Integer>> template = Maps.newHashMap();

private AnnotationTemplate() { }

public static AnnotationTemplate create() { return new AnnotationTemplate(); }

public void addTemplateMin(Property property, int minOccurs) {
template.put(property, Range.<Integer>atLeast(minOccurs));
}

public void addTemplateMax(Property property, int maxOccurs) {
template.put(property, Range.<Integer>atMost(maxOccurs));
}

public void addTemplateMinMax(Property property, int minOccurs, int maxOccurs) {
template.put(property, Range.<Integer>closed(minOccurs, maxOccurs));
}

public Set<Property> getProprtiesAsSet() {
return template.keySet();
}

public boolean existsInTemplate(SimpleAnnotation simpleAnnotation) {
return template.containsKey(simpleAnnotation.getProperty());
}

public boolean isValidAccordingToTemplate(SimpleAnnotation simpleAnnotation) {
int occurences = simpleAnnotation.getValues().size();
if (existsInTemplate(simpleAnnotation)) {
return template.get(simpleAnnotation.getProperty()).contains(occurences);
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.aksw.rdfunit.model.helper;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* Holds a select variable mapping
*
* @author Dimitris Kontokostas
* @since 8/28/15 4:39 PM
*/
public final class SelectVar {
private final String name;
private final String label;

private SelectVar(String name, String label) {
this.name = checkNotNull(name);
this.label = checkNotNull(label);
}

public static SelectVar create(String name) {
return new SelectVar(name, name);
}

public static SelectVar create(String name, String label) {
return new SelectVar(name, label);
}

@Override
public String toString() {
if (isLabeled()) {
return " ( ?" + name + " AS ?" +label + " ) ";
} else {
return " ?" + name + " ";
}
}

private boolean isLabeled() {
return !label.equals(name);
}

public String getName() {
return name;
}

public String getLabel() {
return label;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.aksw.rdfunit.model.helper;

import com.google.common.collect.ImmutableList;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;

import java.util.Arrays;
import java.util.Collection;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* Description
*
* @author Dimitris Kontokostas
* @since 8/28/15 8:36 PM
*/
public final class SimpleAnnotation {
private final Property property;
private final Collection<RDFNode> values;

private SimpleAnnotation(Property property, Collection<RDFNode> values) {
this.property = checkNotNull(property);
this.values = ImmutableList.copyOf(checkNotNull(values));
}

public static SimpleAnnotation create(Property property, RDFNode rdfNode) {
return new SimpleAnnotation(property, Arrays.asList(rdfNode));
}

public static SimpleAnnotation create(Property property, Collection<RDFNode> rdfNode) {
return new SimpleAnnotation(property, rdfNode);
}

public Property getProperty() {
return property;
}

public Collection<RDFNode> getValues() {
return values;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.aksw.rdfunit.model.impl;

import com.google.common.base.Optional;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import org.aksw.rdfunit.enums.RLOGLevel;
import org.aksw.rdfunit.model.interfaces.Argument;
import org.aksw.rdfunit.model.interfaces.ConstraintTemplate;
import org.aksw.rdfunit.model.interfaces.ResultAnnotation;

import java.util.Collection;

/**
* Description
*
* @author Dimitris Kontokostas
* @since 8/21/15 4:06 PM
* @version $Id: $Id
*/
public class ConstraintTemplateImpl implements ConstraintTemplate {



/** {@inheritDoc} */
@Override
public String getDefaultMessage() {
return null;
}

/** {@inheritDoc} */
@Override
public Property getPrperty() {
return null;
}

/** {@inheritDoc} */
@Override
public Collection<ResultAnnotation> getResultAnnotations() {
return null;
}

/** {@inheritDoc} */
@Override
public RLOGLevel getSeverity() {
return null;
}

/** {@inheritDoc} */
@Override
public Collection<Argument> getArguments() {
return null;
}

/** {@inheritDoc} */
@Override
public String getSparql() {
return null;
}

/** {@inheritDoc} */
@Override
public Optional<String> getLabelTemplate() {
return null;
}

/** {@inheritDoc} */
@Override
public Optional<Resource> getResource() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.aksw.rdfunit.model.interfaces;

import com.hp.hpl.jena.rdf.model.Property;
import org.aksw.rdfunit.enums.RLOGLevel;

import java.util.Collection;

/**
* Description
*
* @author Dimitris Kontokostas
* @since 8/21/15 2:12 PM
* @version $Id: $Id
*/
public interface ConstraintTemplate extends Template {

//TODO multiple languages
/**
* <p>getDefaultMessage.</p>
*
* @return a {@link java.lang.String} object.
*/
String getDefaultMessage();

/**
* <p>getPrperty.</p>
*
* @return a {@link com.hp.hpl.jena.rdf.model.Property} object.
*/
Property getPrperty();

/**
* <p>getResultAnnotations.</p>
*
* @return a {@link java.util.Collection} object.
*/
Collection<ResultAnnotation> getResultAnnotations();

/**
* <p>getSeverity.</p>
*
* @return a {@link org.aksw.rdfunit.enums.RLOGLevel} object.
*/
RLOGLevel getSeverity();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.aksw.rdfunit.model.interfaces;

/**
* Description
*
* @author Dimitris Kontokostas
* @since 8/21/15 12:18 AM
* @version $Id: $Id
*/
public interface PropertyConstraint {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.aksw.rdfunit.model.interfaces;

/**
* aSHACL scope
*
* @author Dimitris Kontokostas
* @since 8/21/15 11:46 AM
* @version $Id: $Id
*/
public interface Scope extends Element{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.aksw.rdfunit.model.interfaces;

import com.google.common.base.Optional;
import org.aksw.rdfunit.enums.RLOGLevel;

import java.util.Collection;

/**
* A SHACL Shape
*
* @author Dimitris Kontokostas
* @since 8/21/15 12:18 AM
* @version $Id: $Id
*/
public interface Shape extends Element{

/**
* <p>getScope.</p>
*
* @return a {@link com.google.common.base.Optional} object.
*/
Optional<Scope> getScope();

/**
* <p>getLogLevel.</p>
*
* @return a {@link com.google.common.base.Optional} object.
*/
Optional<RLOGLevel> getSeverityLevel();

/**
* <p>getPropertyConstraints.</p>
*
* @return a {@link java.util.Collection} object.
*/
Collection<PropertyConstraint> getPropertyConstraints();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.aksw.rdfunit.model.interfaces;

import com.google.common.base.Optional;

import java.util.Collection;

/**
* Description
*
* @author Dimitris Kontokostas
* @since 8/21/15 2:30 PM
* @version $Id: $Id
*/
public interface Template extends Element {

/**
* <p>getArguments.</p>
*
* @return a {@link java.util.Collection} object.
*/
Collection<Argument> getArguments();

/**
* <p>getSparql.</p>
*
* @return a {@link java.lang.String} object.
*/
String getSparql();

/**
* <p>getLabelTemplate.</p>
*
* @return a {@link com.google.common.base.Optional} object.
*/
Optional<String> getLabelTemplate();
}
Loading

0 comments on commit 2015e28

Please sign in to comment.