Java Code Examples for org.apache.jena.rdf.model.ModelFactory#createInfModel()

The following examples show how to use org.apache.jena.rdf.model.ModelFactory#createInfModel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleSubClassInferencerFactory.java    From gerbil with GNU Affero General Public License v3.0 6 votes vote down vote up
public static SimpleSubClassInferencer createInferencer(Model classModel) {
    String resourceName = GerbilConfiguration.getInstance().getString(SUB_CLASS_INFERENCER_RULE_FILE_KEY);
    if (resourceName == null) {
        LOGGER.error("Couldn't load subclass inferencer rules resource name from properties. Returning null.");
        return null;
    }
    InputStream is = RootConfig.class.getClassLoader().getResourceAsStream(resourceName);
    List<String> lines;
    try {
        lines = IOUtils.readLines(is);
    } catch (IOException e) {
        LOGGER.error("Couldn't load subclass inferencer rules from resource \"" + resourceName
                + "\". Returning null.", e);
        return null;
    }
    IOUtils.closeQuietly(is);
    StringBuilder sb = new StringBuilder();
    for (String line : lines) {
        sb.append(line);
    }

    Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(sb.toString()));
    InfModel inf = ModelFactory.createInfModel(reasoner, classModel);
    SimpleSubClassInferencer inferencer = new SimpleSubClassInferencer(inf);
    return inferencer;
}
 
Example 2
Source File: JenaDriver.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void read(final String modelPath) throws IOException {
	final Model defaultModel = ModelFactory.createDefaultModel();
	defaultModel.read(modelPath);

	// run inferencing if required
	if (inferencing) {
		final Reasoner reasoner = ReasonerRegistry.getRDFSSimpleReasoner();
		model = ModelFactory.createInfModel(reasoner, defaultModel);
	} else {
		model = defaultModel;
	}
}