use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class ListChain method activate.
@Override
protected void activate(ComponentContext ctx) throws ConfigurationException {
super.activate(ctx);
Object value = ctx.getProperties().get(PROPERTY_ENGINE_LIST);
List<String> configuredChain = new ArrayList<String>();
if (value instanceof String[]) {
configuredChain.addAll(Arrays.asList((String[]) value));
} else if (value instanceof List<?>) {
for (Object o : (List<?>) value) {
if (o != null) {
configuredChain.add(o.toString());
}
}
} else {
throw new ConfigurationException(PROPERTY_ENGINE_LIST, "The engines of a List Chain MUST BE configured as Array/List of " + "Strings (parsed: " + (value != null ? value.getClass() : "null") + ")");
}
Set<String> engineNames = new HashSet<String>(configuredChain.size());
BlankNodeOrIRI last = null;
Graph ep = new SimpleGraph();
BlankNodeOrIRI epNode = createExecutionPlan(ep, getName(), getChainProperties());
log.debug("Parse ListChain config:");
for (String line : configuredChain) {
try {
Entry<String, Map<String, List<String>>> parsed = ConfigUtils.parseConfigEntry(line);
if (!engineNames.add(parsed.getKey())) {
throw new ConfigurationException(PROPERTY_ENGINE_LIST, "The EnhancementEngine '" + parsed.getKey() + "' is mentioned" + "twice in the configured list!");
}
boolean optional = getState(parsed.getValue(), "optional");
log.debug(" > Engine: {} ({})", parsed.getKey(), optional ? "optional" : "required");
last = writeExecutionNode(ep, epNode, parsed.getKey(), optional, last == null ? null : Collections.singleton(last), getEnhancementProperties(parsed.getValue()));
} catch (IllegalArgumentException e) {
throw new ConfigurationException(PROPERTY_ENGINE_LIST, "Unable to parse Chain Configuraiton (message: '" + e.getMessage() + "')!", e);
}
}
if (engineNames.isEmpty()) {
throw new ConfigurationException(PROPERTY_ENGINE_LIST, "The configured chain MUST at least contain a single valid entry!");
}
this.engineNames = Collections.unmodifiableSet(engineNames);
this.executionPlan = ep.getImmutableGraph();
}
use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class ZemantaAPIWrapper method parseResponse.
private ImmutableGraph parseResponse(InputStream is) {
JenaParserProvider jenaParserProvider = new JenaParserProvider();
//NOTE(rw): the new third parameter is the base URI used to resolve relative paths
Graph g = new SimpleGraph();
jenaParserProvider.parse(g, is, SupportedFormat.RDF_XML, null);
log.debug("graph: " + g.toString());
return g.getImmutableGraph();
}
use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class ZemantaEnhancementEngine method computeEnhancements.
public void computeEnhancements(ContentItem ci) throws EngineException {
Entry<IRI, Blob> contentPart = ContentItemHelper.getBlob(ci, SUPPORTED_MIMETYPES);
if (contentPart == null) {
throw new IllegalStateException("No ContentPart with a supported Mime Type" + "found for ContentItem " + ci.getUri() + "(supported: '" + SUPPORTED_MIMETYPES + "') -> this indicates that canEnhance was" + "NOT called and indicates a bug in the used EnhancementJobManager!");
}
String text;
try {
text = ContentItemHelper.getText(contentPart.getValue());
} catch (IOException e) {
throw new InvalidContentException(this, ci, e);
}
if (text.trim().length() == 0) {
log.warn("ContentPart {} of ContentItem {} does not contain any text to enhance", contentPart.getKey(), ci.getUri());
return;
}
Graph graph = ci.getMetadata();
IRI ciId = ci.getUri();
//we need to store the results of Zemanta in an temp graph
Graph results = new SimpleGraph();
ZemantaAPIWrapper zemanta = new ZemantaAPIWrapper(key);
try {
results.addAll(zemanta.enhance(text));
} catch (IOException e) {
throw new EngineException("Unable to get Enhancement from remote Zemanta Service", e);
}
//now we need to process the results and convert them into the Enhancer
//annotation structure
ci.getLock().writeLock().lock();
try {
processRecognition(results, graph, text, ciId);
processCategories(results, graph, ciId);
} finally {
ci.getLock().writeLock().unlock();
}
}
use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class PermissionDefinitionsTest method setUp.
@Before
public void setUp() {
final ImmutableGraph graph = Parser.getInstance().parse(getClass().getResourceAsStream("systemgraph.nt"), "text/rdf+n3");
this.permissionDefinitions = new PermissionDefinitions(new SimpleGraph(graph.iterator()));
this.allPermissions = new PermissionInfo[] { new PermissionInfo("(java.io.FilePermission \"file:///home/foo/-\" \"read,write,delete\")"), new PermissionInfo("(java.io.FilePermission \"file:///home/foo/*\" \"read,write\")"), new PermissionInfo("(java.io.FilePermission \"file:///home/*\" \"read,write\")") };
this.nullPermission = null;
}
use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class RdfEntityFactoryTest method testInterfaceHierarchies.
@Test
public void testInterfaceHierarchies() throws Exception {
Graph graph = new SimpleGraph();
RdfEntityFactory factory = RdfEntityFactory.createInstance(graph);
String testUri = "urn:RdfEntityFactoryTest:SubTestEntity";
String testUri2 = "urn:RdfEntityFactoryTest:TestEntity2";
String testUri3 = "urn:RdfEntityFactoryTest:TestEntity";
IRI node = new IRI(testUri);
IRI node2 = new IRI(testUri2);
IRI node3 = new IRI(testUri3);
SubTestRdfEntity entity = factory.getProxy(node, SubTestRdfEntity.class);
TestRdfEntity entity2 = factory.getProxy(node2, TestRdfEntity.class, SubTestRdfEntity.class, TestRdfEntity2.class);
TestRdfEntity entity3 = factory.getProxy(node3, TestRdfEntity.class);
//Start with checking the types for entity2
//first type cast to the hierarchy
assertTrue(entity instanceof TestRdfEntity);
assertTrue(entity instanceof RdfEntity);
// test if the rdf:type triples are present in the Graph
Set<String> typeStrings = getRdfTypes(graph, node);
assertTrue(typeStrings.contains(SubTestRdfEntity.class.getAnnotation(Rdf.class).id()));
assertTrue(typeStrings.contains(TestRdfEntity.class.getAnnotation(Rdf.class).id()));
typeStrings = null;
//now the same for entity2
//first type cast to the hierarchy
assertTrue(entity2 instanceof SubTestRdfEntity);
assertTrue(entity2 instanceof TestRdfEntity2);
assertTrue(entity2 instanceof RdfEntity);
// test if the rdf:type triples are present in the Graph
typeStrings = getRdfTypes(graph, node2);
assertTrue(typeStrings.contains(SubTestRdfEntity.class.getAnnotation(Rdf.class).id()));
assertTrue(typeStrings.contains(TestRdfEntity.class.getAnnotation(Rdf.class).id()));
assertTrue(typeStrings.contains(TestRdfEntity2.class.getAnnotation(Rdf.class).id()));
typeStrings = null;
//Now check Entity3
assertTrue(!(entity3 instanceof SubTestRdfEntity));
assertTrue(entity3 instanceof TestRdfEntity);
//Now create an new Entity for the same Node that implements SubEntity2
SubTestRdfEntity entity4 = factory.getProxy(node3, SubTestRdfEntity.class);
//check if entity4 implements SubTestRefEntity
assertTrue(entity4 instanceof SubTestRdfEntity);
//now check if the additional type was added to node3
typeStrings = getRdfTypes(graph, node3);
assertTrue(typeStrings.contains(SubTestRdfEntity.class.getAnnotation(Rdf.class).id()));
assertTrue(typeStrings.contains(TestRdfEntity.class.getAnnotation(Rdf.class).id()));
//and that entity3 still dose not implement SubTestEntity
// ... because adding/removing rdf:type triples in the graph can not affect existing proxy instances!
assertTrue(!(entity3 instanceof SubTestRdfEntity));
}
Aggregations