本文整理汇总了Java中com.hp.hpl.jena.rdf.model.ResIterator.toList方法的典型用法代码示例。如果您正苦于以下问题:Java ResIterator.toList方法的具体用法?Java ResIterator.toList怎么用?Java ResIterator.toList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.rdf.model.ResIterator
的用法示例。
在下文中一共展示了ResIterator.toList方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResourcesOfType
import com.hp.hpl.jena.rdf.model.ResIterator; //导入方法依赖的package包/类
List<Resource> getResourcesOfType(final String type) {
Preconditions.checkState(this.model!=null);
final ResIterator iterator =
this.model.
listResourcesWithProperty(
this.model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
NodeFactory.createURI(type));
try {
return iterator.toList();
} finally {
iterator.close();
}
}
示例2: saveMapping
import com.hp.hpl.jena.rdf.model.ResIterator; //导入方法依赖的package包/类
private boolean saveMapping(String modelUrl, String graphContext) {
try {
TripleStoreUtil utilObj = new TripleStoreUtil();
if (graphContext == null || graphContext.trim().compareTo("") == 0)
return false;
URL url = new URL(modelUrl);
StringWriter test = new StringWriter();
Model model = WorksheetR2RMLJenaModelParser.loadSourceModelIntoJenaModel(url);
Property rdfTypeProp = model.getProperty(Uris.RDF_TYPE_URI);
RDFNode node = model.getResource(Uris.KM_R2RML_MAPPING_URI);
ResIterator res = model.listResourcesWithProperty(rdfTypeProp, node);
List<Resource> resList = res.toList();
for(Resource r: resList)
{
model.add(r, model.getProperty(Uris.OWL_SAMEAS_URI), model.getResource(url.toString()));
}
model.write(test,"TTL");
model.close();
String content = test.getBuffer().toString();
test.close();
if (utilObj.testURIExists(tripleStoreUrl, graphContext, modelUrl)) {
utilObj.deleteMappingFromTripleStore(tripleStoreUrl, graphContext, modelUrl);
}
boolean result = utilObj.saveToStoreFromString(content, tripleStoreUrl, graphContext, new Boolean(false), null);
return result;
}catch (Exception e) {
return false;
}
}
示例3: getMappingResourceFromSourceName
import com.hp.hpl.jena.rdf.model.ResIterator; //导入方法依赖的package包/类
private Resource getMappingResourceFromSourceName() throws KarmaException {
Property sourceNameProp = model.getProperty(Uris.KM_SOURCE_NAME_URI);
RDFNode node = model.createLiteral(id.getName());
ResIterator res = model.listResourcesWithProperty(sourceNameProp, node);
List<Resource> resList = res.toList();
if (resList.size() > 1) {
throw new KarmaException("More than one resource exists with source name: " + id.getName());
} else if (resList.size() == 1) {
return resList.get(0);
} else {
//If we didnt find the sourceName in the model, maybe it is a different source with the
//same schema.
//Maybe we need to substitute the sourceName in the model with this one
NodeIterator sourceObjectIter = model.listObjectsOfProperty(sourceNameProp);
List<RDFNode> sourceObjects = sourceObjectIter.toList();
if(sourceObjects.size() > 1) {
throw new KarmaException("More than one resource exists with source name: " + id.getName());
} else if(sourceObjects.size() == 1) {
RDFNode prevSourceObject = sourceObjects.get(0);
//We got the previous source object, now get the Subject Node for this
ResIterator prevSourceSubjectsIter = model.listResourcesWithProperty(sourceNameProp, prevSourceObject);
List<Resource> prevSourceSubjects = prevSourceSubjectsIter.toList();
if (prevSourceSubjects.size() == 1) {
Resource subject = prevSourceSubjects.get(0);
model.remove(subject, sourceNameProp, prevSourceObject);
model.add(subject, sourceNameProp, node);
return subject;
} else if(prevSourceSubjects.size() > 1) {
throw new KarmaException("More than one resource exists with model source name: " + prevSourceObject.toString());
}
}
return null;
}
}
示例4: importOpenData
import com.hp.hpl.jena.rdf.model.ResIterator; //导入方法依赖的package包/类
/**
* Imports a private dataset in Open Data format (DCAT).
*
* @param authorization authorization string.
* @param dcatInputStream
* @return
* @throws java.text.ParseException
* @throws com.fasterxml.jackson.core.JsonProcessingException
*/
@POST
@Path("/importOpenData")
@ApiOperation(
value = "Import Open Data."
)
@ApiResponses(value = {
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 500, message = "Internal server error")
})
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.APPLICATION_JSON)
public Response importOpenData(@HeaderParam("Authorization") String authorization,
InputStream dcatInputStream) throws ParseException, JsonProcessingException {
log.info(MGS_IMPORT_OPENDATA);
model = ModelFactory.createDefaultModel(); // new allocation of the model, not sure if really needed
model.read(dcatInputStream, null);
StringWriter res = new StringWriter();
RDFWriter writer = model.getWriter("RDF/XML");
writer.setProperty("showXmlDeclaration", true);
writer.write(model, res, null);
log.debug("Serialized RDF result:\n" + res);
ResIterator iterator = model.listSubjects();
List<Resource> resourcesList = iterator.toList();
String datasetId = "";
for (Resource resource : resourcesList) {
if (resource.getURI() != null && resource.getURI().startsWith(URI_DATASET)) {
Dataset dataset = new Dataset();
dataset.setId(resource.getProperty(dctIdentifier).getString());
dataset.setName(resource.getProperty(dctTitle).getString());
dataset.setDescription(resource.getProperty(dctDescription).getString());
dataset.setType("Default type");
Date dt = format.parse(resource.getProperty(dctIssued).getString());
dataset.setCreationDate(dt.getTime() / 1000);
dt = format.parse(resource.getProperty(dctModified).getString());
dataset.setLastModifiedDate(dt.getTime() / 1000);
dataset.setPermissions(new ArrayList<Permission>());
// get owner
String str = resource.getProperty(dctPublisher).getObject().toString();
String id[] = str.split("#");
dataset.setOwner(id[id.length - 1]);
// get status
dataset.setStatus("public");
// get readonly
dataset.setReadOnly(false);
// get structure
dataset.setStructure(new DatasetStructure());
log.debug("here's the dataset: " + dataset.toString());
datasetId = INSTANCE.getDatasetService().createDataset(dataset);
break; // exit while the dataset is completed
}
}
return Response.ok(datasetId, MediaType.APPLICATION_JSON).build();
}
示例5: createModelURL
import com.hp.hpl.jena.rdf.model.ResIterator; //导入方法依赖的package包/类
private void createModelURL() throws IOException {
/**
* VALIDATE THE OPTIONS *
*/
if(modelFilePath != null)
{
File modelFile = new File(modelFilePath);
if (!modelFile.exists()) {
throw new IOException("File not found: " + modelFile.getAbsolutePath());
}
modelURL = modelFile.toURI().toURL();
}
else
{
modelURL = new URL(modelURLString);
}
if (contextFile != null) {
File tmp = new File(contextFile);
if (!tmp.exists()) {
throw new IOException("File not found: " + tmp.getAbsolutePath());
}
contextURL = tmp.toURI().toURL();
}
else if(contextURLString != null)
{
contextURL = new URL(contextURLString);
}
if (baseURI != null && !baseURI.trim().isEmpty())
return;
try {
Model model = WorksheetR2RMLJenaModelParser.loadSourceModelIntoJenaModel(modelURL);
Property rdfTypeProp = model.getProperty(Uris.RDF_TYPE_URI);
Property baseURIProp = model.getProperty(Uris.KM_HAS_BASEURI);
RDFNode node = model.getResource(Uris.KM_R2RML_MAPPING_URI);
ResIterator res = model.listResourcesWithProperty(rdfTypeProp, node);
List<Resource> resList = res.toList();
for(Resource r: resList)
{
if (r.hasProperty(baseURIProp)) {
baseURI = r.getProperty(baseURIProp).asTriple().getObject().toString();
baseURI = baseURI.replace("\"", "");
}
}
} catch (IOException e) {
}
}