it.uniroma2.art.semanticturkey.utils.Utils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of st-core-services Show documentation
Show all versions of st-core-services Show documentation
The set of core services bundled with the default Semantic Turkey XPI
package it.uniroma2.art.semanticturkey.utils;
import it.uniroma2.art.semanticturkey.data.role.RDFResourceRole;
import it.uniroma2.art.semanticturkey.services.AnnotatedValue;
import it.uniroma2.art.semanticturkey.services.STServiceContext;
import it.uniroma2.art.semanticturkey.services.support.QueryBuilder;
import it.uniroma2.art.semanticturkey.tx.RDF4JRepositoryUtils;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import java.util.Collection;
public class Utils {
public static RDFResourceRole typeof(STServiceContext stServiceContext, Resource resource) {
Repository repo = stServiceContext.getProject().getRepository();
RepositoryConnection repoConn = RDF4JRepositoryUtils.getConnection(repo);
try {
QueryBuilder qb;
StringBuilder sb = new StringBuilder();
sb.append(
// @formatter:off
" SELECT ?resource WHERE { \n" +
" BIND (?temp as ?resource) \n" +
" } \n" +
" GROUP BY ?resource \n"
// @formatter:on
);
qb = new QueryBuilder(stServiceContext, sb.toString());
qb.setBinding("temp", resource);
qb.processRole();
Collection> res = qb.runQuery();
Value role = res.iterator().next().getAttributes().get("role");
return RDFResourceRole.valueOf(role.stringValue());
} finally {
RDF4JRepositoryUtils.releaseConnection(repoConn, repo);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy