Java Code Examples for org.apache.jena.rdf.model.Model#contains()

The following examples show how to use org.apache.jena.rdf.model.Model#contains() . 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: TransferProcess.java    From fcrepo-import-export with Apache License 2.0 6 votes vote down vote up
/**
 * Utility method to determine whether the current uri is repository root or not. The repository root is the
 * container with type fcrepo:RepositoryRoot
 * @param uri the URI for the resource
 * @param client the FcrepoClient to query the repository
 * @param config the Config for import/export
 * @throws IOException if there is a error with the network connection
 * @throws FcrepoOperationFailedException if there is a error with Fedora
 * @return True if the URI is the root of the repository
 */
public static boolean isRepositoryRoot(final URI uri, final FcrepoClient client, final Config config)
        throws IOException, FcrepoOperationFailedException {
    final String userName = config.getUsername();
    final String rdfLanguage = config.getRdfLanguage();
    try (FcrepoResponse response = client.head(uri).disableRedirects().perform()) {
        checkValidResponse(response, uri, userName);
        // The repository root will not be a binary
        if (response.getLinkHeaders("type").contains(URI.create(NON_RDF_SOURCE.getURI()))) {
            return false;
        }
        try (FcrepoResponse resp = client.get(uri).accept(rdfLanguage).disableRedirects()
                .perform()) {
            final Model model = createDefaultModel().read(resp.getBody(), null, rdfLanguage);
            if (model.contains(null, RDF_TYPE, REPOSITORY_ROOT)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 2
Source File: ValidationUtil.java    From shacl with Apache License 2.0 5 votes vote down vote up
public static Model ensureToshTriplesExist(Model shapesModel) {
	// Ensure that the SHACL, DASH and TOSH graphs are present in the shapes Model
	if(!shapesModel.contains(TOSH.hasShape, RDF.type, (RDFNode)null)) { // Heuristic
		Model unionModel = SHACLSystemModel.getSHACLModel();
		MultiUnion unionGraph = new MultiUnion(new Graph[] {
			unionModel.getGraph(),
			shapesModel.getGraph()
		});
		shapesModel = ModelFactory.createModelForGraph(unionGraph);
	}
	return shapesModel;
}
 
Example 3
Source File: SHACLUtil.java    From shacl with Apache License 2.0 5 votes vote down vote up
public static List<SHResult> getAllTopLevelResults(Model model) {
	List<SHResult> results = new LinkedList<SHResult>();
	for(Resource type : RESULT_TYPES) {
		for(Resource r : model.listResourcesWithProperty(RDF.type, type).toList()) {
			if(!model.contains(null, SH.detail, r)) {
				results.add(r.as(SHResult.class));
			}
		}
	}
	return results;
}
 
Example 4
Source File: DatasetBasedSameAsRetriever.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a DatasetBasedSameAsRetriever or null if the dataset does not
 * contain any owl:sameAs relations.
 * 
 * @param dataset
 * @return
 */
public static DatasetBasedSameAsRetriever create(Dataset dataset) {
    if (dataset instanceof RdfModelContainingDataset) {
        RdfModelContainingDataset rdfDataset = (RdfModelContainingDataset) dataset;
        Model model = rdfDataset.getRdfModel();
        if (model == null) {
            return null;
        }
        if (model.contains(null, OWL.sameAs)) {
            return new DatasetBasedSameAsRetriever(model, rdfDataset);
        }
    }
    return null;
}
 
Example 5
Source File: ImporterIT.java    From fcrepo-import-export with Apache License 2.0 4 votes vote down vote up
private boolean resourceLinksTo(final URI linkFrom, final URI linkTo) throws FcrepoOperationFailedException {
    final FcrepoResponse response = clientBuilder.build().get(linkFrom).perform();
    final Model model = createDefaultModel().read(response.getBody(), null, "text/turtle");
    return model.contains(createResource(linkFrom.toString()), null, createResource(linkTo.toString()));
}