当前位置: 首页>>代码示例>>Java>>正文


Java Statement类代码示例

本文整理汇总了Java中org.apache.jena.rdf.model.Statement的典型用法代码示例。如果您正苦于以下问题:Java Statement类的具体用法?Java Statement怎么用?Java Statement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Statement类属于org.apache.jena.rdf.model包,在下文中一共展示了Statement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createObject

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
/**
 * Creates a new object.
 *
 * This originally used application/octet-stream;qs=1001 as a workaround
 * for JERSEY-2636, to ensure requests without a Content-Type get routed here.
 * This qs value does not parse with newer versions of Jersey, as qs values
 * must be between 0 and 1.  We use qs=1.000 to mark where this historical
 * anomaly had been.
 *
 * @param contentDisposition the content Disposition value
 * @param requestContentType the request content type
 * @param slug the slug value
 * @param requestBodyStream  the request body stream
 * @param link the link value
 * @param digest the digest header
 * @return 201
 * @throws InvalidChecksumException if invalid checksum exception occurred
 * @throws IOException if IO exception occurred
 * @throws MalformedRdfException if malformed rdf exception occurred
 */
@POST
@Consumes({MediaType.APPLICATION_OCTET_STREAM + ";qs=1.000", WILDCARD})
@Produces({TURTLE_WITH_CHARSET + ";qs=1.0", JSON_LD + ";qs=0.8",
        N3_WITH_CHARSET, N3_ALT2_WITH_CHARSET, RDF_XML, NTRIPLES, TEXT_PLAIN_WITH_CHARSET,
        TURTLE_X, TEXT_HTML_WITH_CHARSET, "*/*"})
public Response createObject(@HeaderParam(CONTENT_DISPOSITION) final ContentDisposition contentDisposition,
                             @HeaderParam(CONTENT_TYPE) final MediaType requestContentType,
                             @HeaderParam("Slug") final String slug,
                             @ContentLocation final InputStream requestBodyStream,
                             @HeaderParam(LINK) final String link,
                             @HeaderParam("Digest") final String digest)
        throws InvalidChecksumException, IOException, MalformedRdfException {
    LOGGER.info("POST: {}", externalPath);

    final ContainerService containerService = getContainerService();
    final URI resourceUri = createFromPath(externalPath);

    //check that resource exists
    if (!containerService.exists(resourceUri)) {
        if (!isRoot(resourceUri)) {
            return status(NOT_FOUND).build();
        } else {
            createRoot();
        }
    }

    final String newResourceName = slug == null ? UUID.randomUUID().toString() : slug;
    final String resourcePath = (isRoot(resourceUri) ? "" : resourceUri.getPath());
    final URI newResourceUri = createFromPath(resourcePath + "/" + newResourceName);
    final Container container = containerService.findOrCreate(newResourceUri);
    final Model model = ModelFactory.createDefaultModel();

    model.read(requestBodyStream, container.getIdentifier().toString(), "TTL");
    final Stream<Triple> triples = model.listStatements().toList().stream().map(Statement::asTriple);
    container.updateTriples(triples);
    return created(toExternalURI(container.getIdentifier(), headers)).build();
}
 
开发者ID:duraspace,项目名称:lambdora,代码行数:58,代码来源:LambdoraLdp.java

示例2: toTriple

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
/**
 * This method converts a string (in n-triples format) into a Jena triple
 *
 * @param string containing single n-triples triple
 * @return Triple
 */
public static Triple toTriple(final String string) {
    // Create Jena model
    Model inputModel = createDefaultModel();
    try {
        // Load model with arg string (expecting n-triples)
        inputModel = inputModel.read(new StringInputStream(string), null, strLangNTriples);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }

    // Since there is only one statement, get it
    final Statement stmt = inputModel.listStatements().nextStatement();

    // Return the Jena triple which the statement represents
    return stmt.asTriple();
}
 
开发者ID:duraspace,项目名称:lambdora,代码行数:23,代码来源:TripleUtil.java

示例3: buildNext

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
@Override
protected Indexable buildNext(Statement statement) {
    InstanceEntity instanceEntity = createInstance(applyNS(statement.getSubject().getURI()));
    PropertyEntity propertyEntity = createProperty(applyNS(statement.getPredicate().getURI()));

    LabeledEntity labeledEntity;

    if (!statement.getObject().isLiteral()) {
        //Is created as an instance but can be changed to a class down on the workflow in EntityClassifierProcessor.
        labeledEntity = createInstance(applyNS(statement.getObject().asResource().getURI()));
    } else {
        Literal literal = statement.getObject().asLiteral();
        String dataType = literal.getDatatypeURI();
        String langTag = literal.getLanguage();
        String value = literal.getLexicalForm();
        labeledEntity = new ValueEntity(value, dataType, langTag);
    }


    return new Indexable(new Fact(kbId, instanceEntity, propertyEntity, labeledEntity), kbId);
}
 
开发者ID:Lambda-3,项目名称:Stargraph,代码行数:22,代码来源:FactIterator.java

示例4: print

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
public void print(PrintStream ps, boolean printChildren) {
  Property nameProperty = model.getProperty("http://example.com/owl/csvtupler/map2sparql#","name");
  Statement nameStatement = resource.getProperty(nameProperty);

  Property rootProperty = model.getProperty("http://example.com/owl/csvtupler/map2sparql#","root");
  Statement rootStatement = resource.getProperty(rootProperty);
  if (rootStatement != null) {
    ps.print("Root node:\t");
  }
  ps.print("Node: "+name+"\n");

  if (printChildren) {
    Iterator iter = getChildren().iterator();
    while (iter.hasNext()) {
      ps.print("\t");
      ((Node)iter.next()).print(ps,printChildren);
    }
  }
}
 
开发者ID:tag42git,项目名称:CsvTupler,代码行数:20,代码来源:Node.java

示例5: getJenaModel

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
private Model getJenaModel(@NonNull org.eclipse.rdf4j.model.Model model) {
  Model jenaModel = ModelFactory.createDefaultModel();
  java.util.Iterator<org.eclipse.rdf4j.model.Statement> iterator = model.iterator();

  while (iterator.hasNext()) {
    org.eclipse.rdf4j.model.Statement rdf4jStatement = iterator.next();

    // create resource / subject
    Resource resource = rdf4jResourceToJenaResource(jenaModel, rdf4jStatement.getSubject());
    // create property / predicate
    Property property =
        rdf4jPropertyToJenaProperty(jenaModel, (SimpleIRI) rdf4jStatement.getPredicate());
    // create rdfnode / object
    RDFNode node = rdf4jValueToJenaRdfNode(jenaModel, rdf4jStatement.getObject());

    Statement statement = ResourceFactory.createStatement(resource, property, node);
    jenaModel.add(statement);
  }
  return jenaModel;
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:21,代码来源:ShaclValidator.java

示例6: getLabelFromLinkedData

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
/**
   * Dereference the IRI and look for label property value.
   * @param iri the IRI
   * @return the label if exist, otherwise <code>null</code>
   */
  private String getLabelFromLinkedData(String iri){
  	logger.debug("Get label for " + iri + " from Linked Data...");
  	
try {
	// 1. get triples for the IRI by sending a Linked Data request
	Model model = uriDereferencer.dereference(iri);
	
	// 2. check if we find a label in the triples
	for (String labelProperty : labelProperties) {
		for(Statement st : model.listStatements(model.getResource(iri), model.getProperty(labelProperty), (RDFNode)null).toList()){
			Literal literal = st.getObject().asLiteral();
			
			// language check
			String language = literal.getLanguage();
			if(language != null && language.equals(this.language)){
				return literal.getLexicalForm();
			}
		}
	}
} catch (DereferencingFailedException e) {
	logger.error(e.getMessage(), e);
}
  	return null;
  }
 
开发者ID:dice-group,项目名称:RDF2PT,代码行数:30,代码来源:DefaultIRIConverter.java

示例7: compareModels

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
private boolean compareModels(String resourceName, Model expModel, Model carwledModel) {
    StmtIterator iterator = expModel.listStatements();
    Statement statement;
    boolean modelsAreEqual = true;
    while (iterator.hasNext()) {
        statement = iterator.next();
        if (!carwledModel.contains(statement)) {
            LOGGER.error("The crawled model of \"" + resourceName + "\" does not contain the expected statement "
                    + statement.toString());
            modelsAreEqual = false;
        }
    }
    iterator = carwledModel.listStatements();
    while (iterator.hasNext()) {
        statement = iterator.next();
        if (!expModel.contains(statement)) {
            LOGGER.error("The crawled model of \"" + resourceName + "\" contains the unexpected statement "
                    + statement.toString());
            modelsAreEqual = false;
        }
    }
    return modelsAreEqual;
}
 
开发者ID:dice-group,项目名称:Squirrel,代码行数:24,代码来源:ScenarioBasedTest.java

示例8: from

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
@Override
public List<Statement> from() {
	Type type = new TypeToken<List<SurveyInfoDTO>>() {
	}.getType();
	Gson gson = new Gson();
	List<SurveyInfoDTO> surveyList = gson.fromJson(content, type);

	Iterator<SurveyInfoDTO> it = surveyList.iterator();
	
	while (it.hasNext()) {
		Resource _surveury = model.createResource(baseuri+"/campus/Survey_"+UUID.randomUUID());
		List<Statement> _slist = getStatementList( it.next(), _surveury);
		slist.addAll(_slist);
	}
	
	return slist;
}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:18,代码来源:SurveyServiceMapper.java

示例9: from

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
@Override
public List<Statement> from() {
	Type type = new TypeToken<List<SurveyInfoDTO>>() {
	}.getType();
	Gson gson = new Gson();
	List<SurveyInfoDTO> surveyList = gson.fromJson(content, type);

	Iterator<SurveyInfoDTO> it = surveyList.iterator();
	
	while (it.hasNext()) {
		Resource _surveury = model.createResource(baseuri+"/Survey_"+UUID.randomUUID());
		List<Statement> _slist = getStatementList( it.next(), _surveury);
		slist.addAll(_slist);
	}
	
	return slist;
}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:18,代码来源:SurveyServiceMapper.java

示例10: testParameterForwarding

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
@Test
public void testParameterForwarding() {
    ExperimentConfiguration config = new ExperimentConfiguration("123", benchmarkUri,
            RabbitMQUtils.writeModel2String(benchmarkParamModel), systemUri);
    String serializedSystemModel = ExperimentManager.getSerializedSystemParams(config, this);
    Model result = RabbitMQUtils.readModel(serializedSystemModel);

    // Compare the models
    String expectedModelString = expectedResult.toString();
    String resultModelString = result.toString();
    // Check the precision and recall
    Set<Statement> missingStatements = ModelComparisonHelper.getMissingStatements(expectedResult, result);
    Set<Statement> unexpectedStatements = ModelComparisonHelper.getMissingStatements(result, expectedResult);

    StringBuilder builder = new StringBuilder();
    if (unexpectedStatements.size() != 0) {
        builder.append("The result contains the unexpected statements " + unexpectedStatements.toString()
                + ". expected model:\n" + expectedModelString + "\nresult model:\n" + resultModelString + "\n");
    }
    if (missingStatements.size() != 0) {
        builder.append("The result does not contain the expected statements " + missingStatements.toString()
                + ". expected model:\n" + expectedModelString + "\nresult model:\n" + resultModelString + "\n");
    }

    Assert.assertTrue(builder.toString(), missingStatements.size() == 0 && unexpectedStatements.size() == 0);
}
 
开发者ID:hobbit-project,项目名称:platform,代码行数:27,代码来源:ParameterForwardingTest.java

示例11: test

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
@Test
public void test() {
    // load the models
    Model originalModel = loadModel(storeContentResource);
    // load expected result
    Model expectedResult = loadModel(expectedResultResource);

    // execte query
    Model result = performTransformation(originalModel);

    // Compare the models
    String expectedModelString = expectedResult.toString();
    String resultModelString = result.toString();
    // Check the recall
    Set<Statement> statements = ModelComparisonHelper.getMissingStatements(expectedResult, result);
    Assert.assertTrue("The result does not contain the expected statements " + statements.toString()
            + ". expected model:\n" + expectedModelString + "\nresult model:\n" + resultModelString,
            statements.size() == 0);
    // Check the precision
    statements = ModelComparisonHelper.getMissingStatements(result, expectedResult);
    Assert.assertTrue("The result contains the unexpected statements " + statements.toString()
            + ". expected model:\n" + expectedModelString + "\nresult model:\n" + resultModelString,
            statements.size() == 0);
}
 
开发者ID:hobbit-project,项目名称:platform,代码行数:25,代码来源:AbstractRdfHelperTest.java

示例12: filterInboundReferences

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
private Set<URI> filterInboundReferences(final URI uri, final Model model) {
    final String withSlash = withSlash(uri).toString();
    final String withoutSlash = withoutSlash(uri).toString();
    final Set<URI> inboundMembers = new HashSet<>();
    final List<Statement> removeList = new ArrayList<>();
    for (final StmtIterator inbound = model.listStatements(); inbound.hasNext(); ) {
        final Statement s = inbound.next();
        final String subject = s.getSubject().toString();
        if (!subject.equals(withSlash) && !subject.equals(withoutSlash)) {
            removeList.add(s);
            logger.trace("Filtering inbound reference: {}", s);
            inboundMembers.add(URI.create(subject));
        }
    }

    model.remove(removeList);
    return inboundMembers;
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-import-export,代码行数:19,代码来源:Exporter.java

示例13: filterBinaryReferences

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
/**
 * Filter out the binary resource references from the model
 * @param uri the URI for the resource
 * @param model the RDF Model of the resource
 * @return the RDF model with no binary references
 * @throws FcrepoOperationFailedException
 * @throws IOException
 */
private void filterBinaryReferences(final URI uri, final Model model) throws IOException,
        FcrepoOperationFailedException {

    final List<Statement> removeList = new ArrayList<>();
    for (final StmtIterator it = model.listStatements(); it.hasNext();) {
        final Statement s = it.nextStatement();

        final RDFNode obj = s.getObject();
        if (obj.isResource() && obj.toString().startsWith(repositoryRoot.toString())
                && !s.getPredicate().toString().equals(REPOSITORY_NAMESPACE + "hasTransactionProvider")) {
            try (final FcrepoResponse resp = client().head(URI.create(obj.toString())).disableRedirects()
                    .perform()) {
                checkValidResponse(resp, URI.create(obj.toString()), config.getUsername());
                final List<URI> linkHeaders = resp.getLinkHeaders("type");
                if (linkHeaders.contains(binaryURI)) {
                    removeList.add(s);
                }
            }
        }
    }

    model.remove(removeList);
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-import-export,代码行数:32,代码来源:Exporter.java

示例14: sanitize

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
/**
 * Removes statements from the provided model that affect triples that need not be (and indeed
 * cannot be) modified directly through PUT, POST or PATCH requests to fedora.
 *
 * Certain triples included in a resource from fedora cannot be explicitly stored, but because
 * they're derived from other content that *can* be stored will still appear identical when the
 * other RDF and content is ingested.  Examples include those properties that reflect innate
 * characteristics of binary resources like file size and message digest,  Or triples that
 * represent characteristics of rdf resources like the number of children, whether it has
 * versions and some of the types.
 *
 * @param model the RDF statements about an exported resource
 * @return the provided model updated to omit statements that may not be updated directly through
 *         the fedora API
 * @throws IOException
 * @throws FcrepoOperationFailedException
 */
private Model sanitize(final Model model) throws IOException, FcrepoOperationFailedException {
    final List<Statement> remove = new ArrayList<>();
    for (final StmtIterator it = model.listStatements(); it.hasNext(); ) {
        final Statement s = it.nextStatement();

        if ((s.getPredicate().getNameSpace().equals(REPOSITORY_NAMESPACE) && !relaxedPredicate(s.getPredicate()))
                || s.getSubject().getURI().endsWith("fcr:export?format=jcr/xml")
                || s.getSubject().getURI().equals(REPOSITORY_NAMESPACE + "jcr/xml")
                || s.getPredicate().equals(DESCRIBEDBY)
                || s.getPredicate().equals(CONTAINS)
                || s.getPredicate().equals(HAS_MESSAGE_DIGEST)
                || s.getPredicate().equals(HAS_SIZE)
                || (s.getPredicate().equals(RDF_TYPE) && forbiddenType(s.getResource()))) {
            remove.add(s);
        } else if (s.getObject().isResource()) {
            // make sure that referenced repository objects exist
            final String obj = s.getResource().toString();
            if (obj.startsWith(repositoryRoot.toString())) {
                ensureExists(URI.create(obj));
            }
        }
    }
    return model.remove(remove);
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-import-export,代码行数:42,代码来源:Importer.java

示例15: sortStatementsByHash

import org.apache.jena.rdf.model.Statement; //导入依赖的package包/类
/**
 * Sort statements by hash
 * 
 * @param stmtIterator
 *            Iterator which is used to get the statements
 * @return List of statements sorted by hash
 */
@Deprecated
protected List<Statement> sortStatementsByHash(StmtIterator stmtIterator) {
	IntObjectOpenHashMap<Statement> map = new IntObjectOpenHashMap<Statement>();
	Statement s;
	while (stmtIterator.hasNext()) {
		s = stmtIterator.next();
		map.put(s.hashCode(), s);
	}
	int keys[] = new int[map.assigned];
	int pos = 0;
	for (int i = 0; i < map.allocated.length; ++i) {
		if (map.allocated[i]) {
			keys[pos] = map.keys[i];
			++pos;
		}
	}
	Arrays.sort(keys);
	List<Statement> result = new ArrayList<Statement>(keys.length);
	for (int i = 0; i < keys.length; ++i) {
		result.add(map.get(keys[i]));
	}
	return result;
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:31,代码来源:AbstractSelector.java


注:本文中的org.apache.jena.rdf.model.Statement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。