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


Java Model类代码示例

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


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

示例1: mergeResourceWithPrefixes

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
public static Model mergeResourceWithPrefixes(InputStream inputStreamPrefixes,
    InputStream inputStreamData) throws IOException {
  final Resource mergedDataResource =
      new InputStreamResource(new SequenceInputStream(inputStreamPrefixes, inputStreamData));
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

  RDFWriter turtleWriter = Rio.createWriter(RDFFormat.TURTLE, byteArrayOutputStream);
  RDFParser trigParser = Rio.createParser(RDFFormat.TRIG);
  trigParser.setRDFHandler(turtleWriter);
  trigParser.parse(mergedDataResource.getInputStream(), "");

  Model result = Rio.parse(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()), "",
      RDFFormat.TURTLE);

  byteArrayOutputStream.close();
  inputStreamData.close();
  return result;
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:19,代码来源:RdfModelTransformer.java

示例2: get_GetDocResource_ThroughLdApi

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
@Test
public void get_GetDocResource_ThroughLdApi() {
  // Arrange
  Model model = new ModelBuilder().subject(DBEERPEDIA.BREWERIES).add(RDFS.LABEL,
      DBEERPEDIA.BREWERIES_LABEL).build();
  SparqlHttpStub.returnGraph(model);
  MediaType mediaType = MediaType.valueOf("text/turtle");

  // Act
  Response response = target.path("/dbp/ld/v1/doc/breweries").request().accept(mediaType).get();

  // Assert
  assertThat(response.getStatus(), equalTo(Status.OK.getStatusCode()));
  assertThat(response.getMediaType(), equalTo(mediaType));
  assertThat(response.getLength(), greaterThan(0));
  assertThat(response.readEntity(String.class),
      containsString(DBEERPEDIA.BREWERIES_LABEL.stringValue()));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:19,代码来源:LdIntegrationTest.java

示例3: create_createTermParameterDefinition_ForBooleanShape

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
@Test
public void create_createTermParameterDefinition_ForBooleanShape() {
  // Arrange
  ModelBuilder builder = new ModelBuilder();
  BNode blankNode = VALUE_FACTORY.createBNode();

  builder.subject(DBEERPEDIA.NAME_PARAMETER_ID).add(RDF.TYPE, ELMO.TERM_FILTER).add(
      ELMO.NAME_PROP, DBEERPEDIA.NAME_PARAMETER_VALUE).add(ELMO.SHAPE_PROP, blankNode).subject(
          blankNode).add(SHACL.DATATYPE, XMLSchema.BOOLEAN);

  Model model = builder.build();

  // Act
  ParameterDefinition result =
      parameterDefinitionFactory.create(model, DBEERPEDIA.NAME_PARAMETER_ID);

  // Assert
  assertThat(result, instanceOf(TermParameterDefinition.class));
  assertThat(result.getIdentifier(), is(DBEERPEDIA.NAME_PARAMETER_ID));
  assertThat(result.getName(), is(DBEERPEDIA.NAME_PARAMETER_VALUE.stringValue()));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:22,代码来源:TermParameterDefinitionFactoryTest.java

示例4: create_createTermParameterDefinition_ForNoShape

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
@Test
public void create_createTermParameterDefinition_ForNoShape() {
  // Arrange
  ModelBuilder builder = new ModelBuilder();

  builder.subject(DBEERPEDIA.NAME_PARAMETER_ID).add(RDF.TYPE, ELMO.TERM_FILTER).add(
      ELMO.NAME_PROP, DBEERPEDIA.NAME_PARAMETER_VALUE);

  Model model = builder.build();

  // Act
  ParameterDefinition result =
      parameterDefinitionFactory.create(model, DBEERPEDIA.NAME_PARAMETER_ID);

  // Assert
  assertThat(result, instanceOf(TermParameterDefinition.class));
  assertThat(result.getIdentifier(), is(DBEERPEDIA.NAME_PARAMETER_ID));
  assertThat(result.getName(), is(DBEERPEDIA.NAME_PARAMETER_VALUE.stringValue()));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:20,代码来源:TermParameterDefinitionFactoryTest.java

示例5: map

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
void map(Model model, EvaluateExpression evaluate, Resource subject, Set<IRI> subjectGraphs) {

		Resource[] contexts = Stream
				.concat(
					subjectGraphs.stream(),
					graphGenerators.stream()
							.map(g -> g.apply(evaluate))
							.filter(Optional::isPresent)
							.map(Optional::get)
				)
				.distinct()
				.toArray(Resource[]::new);
		
		predicateMappers.forEach(p -> p.map(model, evaluate, subject, contexts));
		
	}
 
开发者ID:carml,项目名称:carml,代码行数:17,代码来源:PredicateObjectMapper.java

示例6: mapSubject

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
private Resource mapSubject(Resource subject, Model model, EvaluateExpression evaluate) {
	// use graphs when generating statements later
	Set<IRI> graphs = graphGenerators.stream()
		.map(g -> g.apply(evaluate))
		.filter(Optional::isPresent)
		.map(Optional::get)
		.collect(ImmutableCollectors.toImmutableSet());
	
	Resource[] contexts = new Resource[graphs.size()];
	graphs.toArray(contexts);
	
	// generate rdf:type triples from classes
	classes.forEach(c -> model.add(subject, RDF.TYPE, c, contexts));

	predicateObjectMappers.forEach(p -> p.map(model, evaluate, subject, graphs));
	
	return subject;
}
 
开发者ID:carml,项目名称:carml,代码行数:19,代码来源:SubjectMapper.java

示例7: expandStatements

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
private void expandStatements(Model model, Statement statement) {
	IRI p = statement.getPredicate();
	
	// add statements that are NOT shortcut properties
	// as-is to the result model
	if (!shortcutPredicates.contains(p)) {
		model.add(statement);
		return;
	}
	
	// 'p' is a shortcut predicate
	Resource context = statement.getContext();
	BNode bNode = f.createBNode();
	// TODO verify that 'context' works properly, even if it is null
	model.add(statement.getSubject(), getExpandedPredicate(p), bNode, context);
	model.add(bNode, constant, statement.getObject(), context);
}
 
开发者ID:carml,项目名称:carml,代码行数:18,代码来源:RmlConstantShorthandExpander.java

示例8: getRdf4jModel_NoErrors_ReturnRdf4jModel

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
@Test
public void getRdf4jModel_NoErrors_ReturnRdf4jModel() throws Exception {
  // Act
  final Model rdf4jModel = RdfModelTransformer.getModel(validDataResource.getInputStream());

  // Assert
  assertNotNull(rdf4jModel);
  assertThat(rdf4jModel.toString(),
      equalTo("[(http://example.org#Marco, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, "
          + "http://example.org#Persoon) [null], (http://example.org#Marco, http://example.org#naam,"
          + " \"Marco\"^^<http://www.w3.org/2001/XMLSchema#string>) [null], "
          + "(http://example.org#Nanda, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, "
          + "http://example.org#Persoon) [null], (http://example.org#Nanda, http://example.org#naam,"
          + " \"Nanda\"^^<http://www.w3.org/2001/XMLSchema#string>) [null], "
          + "(http://example.org#HuwelijkMarcoNanda, "
          + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://example.org#Huwelijk) [null], "
          + "(http://example.org#HuwelijkMarcoNanda, http://example.org#lid, "
          + "http://example.org#Marco) [null], (http://example.org#HuwelijkMarcoNanda,"
          + " http://example.org#lid, http://example.org#Nanda) [null]]"));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:21,代码来源:RdfModelTransformerTest.java

示例9: map_withClasses_appliesEveryClassToGeneratedSubject

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
@Test
public void map_withClasses_appliesEveryClassToGeneratedSubject() throws Exception {

	EvaluateExpression evaluator = null;
	SimpleValueFactory f = SimpleValueFactory.getInstance();
	IRI subjectIRI = f.createIRI("http://foo.bar/subjectIRI");

	when(subjectGenerator.apply(evaluator))
			.thenReturn(Optional.of(subjectIRI));

	Set<IRI> expectedClasses = 
		ImmutableSet.of(
			f.createIRI("http://www.none.invalid/foo"),
			f.createIRI("http://www.none.invalid/bar"),
			f.createIRI("http://www.none.invalid/baz")
		);

	Model model = new ModelBuilder().build();
	SubjectMapper s = new SubjectMapper(subjectGenerator, ImmutableSet.of(), expectedClasses, ImmutableSet.of());
	s.map(model, evaluator);

	expectedClasses.forEach(iri -> Assert.assertTrue(model.contains(subjectIRI, RDF.TYPE, iri)));
}
 
开发者ID:carml,项目名称:carml,代码行数:24,代码来源:SubjectMapperTest.java

示例10: create_InformationProductIsCreated_WithValidData

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
@Test
public void create_InformationProductIsCreated_WithValidData() {
  // Arrange
  Model statements = new ModelBuilder().add(DBEERPEDIA.ORIGIN_INFORMATION_PRODUCT, ELMO.QUERY,
      DBEERPEDIA.SELECT_ALL_QUERY).build();

  // Act
  Parameter<?> parameter1Mock = mock(Parameter.class);
  Parameter<?> parameter2Mock = mock(Parameter.class);
  Parameter<?> parameter3Mock = mock(Parameter.class);

  Collection<Parameter> parameters =
      ImmutableList.of(parameter1Mock, parameter2Mock, parameter3Mock);

  InformationProduct result =
      informationProductFactory.create(DBEERPEDIA.ORIGIN_INFORMATION_PRODUCT,
          DBEERPEDIA.BREWERIES_LABEL.stringValue(), backendMock, parameters, statements);

  // Assert
  assertThat(result, instanceOf(SparqlBackendInformationProduct.class));
  assertThat(((SparqlBackendInformationProduct) result).getQuery(),
      equalTo(DBEERPEDIA.SELECT_ALL_QUERY.stringValue()));

  assertThat(((SparqlBackendInformationProduct) result).getParameters(),
      contains(parameter1Mock, parameter2Mock, parameter3Mock));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:27,代码来源:SparqlBackendInformationProductFactoryTest.java

示例11: expandAndTestShorthandStatement

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
private Model expandAndTestShorthandStatement(Statement toExpand, IRI expandedPredicate) {
	model.add(toExpand);
	Model expanded = SHORTHAND_EXPANDER.apply(model);
	assertThat(expanded.size(), is(2));
	
	Statement firstStatement = 
		Iterators.getOnlyElement(
			expanded
				.filter(null, expandedPredicate, null)
				.iterator()
		); 
	assertThat(firstStatement.getSubject(), is(toExpand.getSubject()));
	assertThat(firstStatement.getObject(), instanceOf(BNode.class));
	
	Statement otherSt = 
		Iterators.getOnlyElement(
			expanded
				.filter((Resource)firstStatement.getObject(), null, null)
				.iterator()
		);
	assertThat(otherSt.getPredicate(), is(Rr.constant));
	assertThat(otherSt.getObject(), is(toExpand.getObject()));
	
	return expanded;
}
 
开发者ID:carml,项目名称:carml,代码行数:26,代码来源:RmlConstantShorthandExpanderTest.java

示例12: load

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
public static <T> Set<T> load(
	Function<Model, Set<Resource>> resourceSelector, 
	Class<T> clazz,
	Model model,
	UnaryOperator<Model> modelAdapter,
	Consumer<MappingCache> populateCache,
	Consumer<Mapper> configureMapper
) {
	
	requireNonNull(resourceSelector, RESOURCE_SELECTOR_MSG);
	requireNonNull(clazz, CLASS_MSG);
	requireNonNull(model, MODEL_MSG);
	requireNonNull(modelAdapter, MODEL_ADAPTER_MSG);
	requireNonNull(populateCache, POPULATE_CACHE_MSG);
	
	MapperImpl mapper = new MapperImpl();
	populateCache.accept(mapper);
	configureMapper.accept(mapper);
	
	Set<Resource> resources = resourceSelector.apply(model);
	
	return resources
		.stream()
		.<T> map(r -> mapper.map(modelAdapter.apply(model), r, clazz))
		.collect(ImmutableCollectors.toImmutableSet());
}
 
开发者ID:carml,项目名称:carml,代码行数:27,代码来源:RdfObjectLoader.java

示例13: create_createTermParameterDefinition_ForIriShape

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
@Test
public void create_createTermParameterDefinition_ForIriShape() {
  // Arrange
  ModelBuilder builder = new ModelBuilder();
  BNode blankNode = VALUE_FACTORY.createBNode();

  builder.subject(DBEERPEDIA.NAME_PARAMETER_ID).add(RDF.TYPE, ELMO.TERM_FILTER).add(
      ELMO.NAME_PROP, DBEERPEDIA.NAME_PARAMETER_VALUE).add(ELMO.SHAPE_PROP, blankNode).subject(
          blankNode).add(SHACL.DATATYPE, XMLSchema.ANYURI);

  Model model = builder.build();

  // Act
  ParameterDefinition result =
      parameterDefinitionFactory.create(model, DBEERPEDIA.NAME_PARAMETER_ID);

  // Assert
  assertThat(result, instanceOf(TermParameterDefinition.class));
  assertThat(result.getIdentifier(), is(DBEERPEDIA.NAME_PARAMETER_ID));
  assertThat(result.getName(), is(DBEERPEDIA.NAME_PARAMETER_VALUE.stringValue()));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:22,代码来源:TermParameterDefinitionFactoryTest.java

示例14: modelGetter_givenSparqlQuery_ShouldReturnAllCorrespondingStatements

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
@Test
public void modelGetter_givenSparqlQuery_ShouldReturnAllCorrespondingStatements() {
	String sparqlQuery = ""
			+ "CONSTRUCT {"
			+ "  ?s <http://schema.org/name> ?name . "
			+ "  ?s <http://schema.org/gender> ?gender "
			+ "} "
			+ "FROM NAMED <http://example.org/A>" 
			+ "WHERE { "
			+ "  GRAPH ?g { "
			+ "    ?s <http://schema.org/name> ?name . "
			+ "    ?s <http://schema.org/gender> ?gender "
			+ "  } "
			+ "}";
	
	Model model = QueryUtils.getModelFromRepo(repo, sparqlQuery);
	assertThat(
		"All statements corresponding to sparql query should be loaded",
		model,
		hasSize(2)
	);
}
 
开发者ID:carml,项目名称:carml,代码行数:23,代码来源:QueryUtilsTest.java

示例15: create_createTermParameterDefinition_ForIntegerShape

import org.eclipse.rdf4j.model.Model; //导入依赖的package包/类
@Test
public void create_createTermParameterDefinition_ForIntegerShape() {
  // Arrange
  ModelBuilder builder = new ModelBuilder();
  BNode blankNode = VALUE_FACTORY.createBNode();

  builder.subject(DBEERPEDIA.NAME_PARAMETER_ID).add(RDF.TYPE, ELMO.TERM_FILTER).add(
      ELMO.NAME_PROP, DBEERPEDIA.NAME_PARAMETER_VALUE).add(ELMO.SHAPE_PROP, blankNode).subject(
          blankNode).add(SHACL.DATATYPE, XMLSchema.INTEGER);

  Model model = builder.build();

  // Act
  ParameterDefinition result =
      parameterDefinitionFactory.create(model, DBEERPEDIA.NAME_PARAMETER_ID);

  // Assert
  assertThat(result, instanceOf(TermParameterDefinition.class));
  assertThat(result.getIdentifier(), is(DBEERPEDIA.NAME_PARAMETER_ID));
  assertThat(result.getName(), is(DBEERPEDIA.NAME_PARAMETER_VALUE.stringValue()));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:22,代码来源:TermParameterDefinitionFactoryTest.java


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