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


Java ModelFactory.createDefaultModel方法代码示例

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


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

示例1: createModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
@Override
protected Model createModel(String dbId) {
    File ntriplesFile = getNTriplesPath(dbId).toFile();
    if (!ntriplesFile.exists()) {
        logger.warn(marker, "Can't find NT file {}", ntriplesFile);
    } else {

        try (InputStream is = new FileInputStream(ntriplesFile)) {
            Model model = ModelFactory.createDefaultModel();
            model.read(is, null, "N-TRIPLES");
            return model;
        } catch (Exception e) {
            throw new StarGraphException(e);
        }
    }

    return null;
}
 
开发者ID:Lambda-3,项目名称:Stargraph,代码行数:19,代码来源:NTriplesModelFactory.java

示例2: createModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
private Model createModel(Logger logger) throws IOException {
		LoggingUtils.configureSilentLog4J();
		Model model = ModelFactory.createDefaultModel();
		model.setNsPrefixes(PrefixMapping.Standard);
		model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
		model.setNsPrefix("skos", "http://www.w3.org/2004/02/skos/core#");
		model.setNsPrefix("oboInOwl", "http://www.geneontology.org/formats/oboInOwl#");
		model.setNsPrefixes(prefixes);
		for (InputStream is : Iterators.loop(source.getInputStreams())) {
			logger.info("loading model from: " + source.getStreamName(is));
//			System.err.println("is = " + is);
//			model.read(is, null, Lang.RDFXML.toString());
			RDFDataMgr.read(model, is, Lang.RDFXML);
		}
		return model;
	}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:17,代码来源:RDFProjector.java

示例3: getJenaModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的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

示例4: makeSampleModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
private static Model makeSampleModel() {
	String BASE = "http://example/";
	
	Model model = ModelFactory.createDefaultModel();
	model.setNsPrefix("", BASE);
	Resource r1 = model.createResource(BASE + "r1");
	Resource r2 = model.createResource(BASE + "r2");
	Property p1 = model.createProperty(BASE + "p");
	Property p2 = model.createProperty(BASE + "p2");
	RDFNode v1 = model.createTypedLiteral("1", XSDDatatype.XSDinteger);
	RDFNode v2 = model.createTypedLiteral("2", XSDDatatype.XSDinteger);

	r1.addProperty(p1, v1).addProperty(p1, v2);
	r1.addProperty(p2, v1).addProperty(p2, v2);
	r2.addProperty(p1, v1).addProperty(p1, v2);

	return model;
}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:19,代码来源:SDADatasetAccessor.java

示例5: getCheckedModelString

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
protected String getCheckedModelString(String modelString, String modelType, String projectName) {
    try {
        Model model = ModelFactory.createDefaultModel();
        model.read(new StringReader(modelString), null, "TTL");
        return modelString;
    } catch (Exception e) {
        String parsingError = "Couldn't parse " + modelType + " model from " + projectName
                + ". It won't be available. " + e.getMessage();
        if (parsingErrors.contains(parsingError)) {
            LOGGER.info(parsingError + " (Error already reported before)");
        } else {
            LOGGER.info("Couldn't parse " + modelType + " model from " + projectName + ". It won't be available.",
                    e);
            sortedParsingErrors.addLast(parsingError);
            parsingErrors.add(parsingError);
            // If the cached errors become to long, remove the oldest
            if (sortedParsingErrors.size() > MAX_PARSING_ERRORS) {
                parsingErrors.remove(sortedParsingErrors.pop());
            }
        }
    }
    return null;
}
 
开发者ID:hobbit-project,项目名称:platform,代码行数:24,代码来源:GitlabControllerImpl.java

示例6: loadOntologyTest

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
@Test
public void loadOntologyTest() {
    final WebResource resource = ONTOLOGY_REGISTRY.get(URI.create(ONT5));

    final OntModel transitive = toTest.parseOntology(resource).model;

    // 5 includes 4, 4 includes 1
    final Model expectedTriples = ModelFactory.createDefaultModel();
    expectedTriples.add(ModelFactory.createDefaultModel().read(ONTOLOGY_REGISTRY.get(URI.create(ONT1))
            .representation(), null, "N-TRIPLES"));
    expectedTriples.add(ModelFactory.createDefaultModel().read(ONTOLOGY_REGISTRY.get(URI.create(ONT4))
            .representation(), null, "N-TRIPLES"));
    expectedTriples.add(ModelFactory.createDefaultModel().read(ONTOLOGY_REGISTRY.get(URI.create(ONT5))
            .representation(), null, "N-TRIPLES"));

    expectedTriples.removeAll(null, expectedTriples.getProperty(OWL_IMPORTS), null);

    assertTrue(transitive.containsAll(expectedTriples));

}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-api-x,代码行数:21,代码来源:JenaOntologyServiceTest.java

示例7: test

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
@Test
public void test() {
    Model model = ModelFactory.createDefaultModel();
    InputStream is = this.getClass().getClassLoader().getResourceAsStream(GRAPH_FILE);
    model.read(is, null, "N3");
    IOUtils.closeQuietly(is);

    GraphCreator creator = new GraphCreator();
    ColouredGraph graph = creator.processModel(model);

    InDegreeDistributionMetric metric = new InDegreeDistributionMetric();
    IntDistribution distribution = metric.apply(graph);

    Assert.assertArrayEquals(EXPECTED_DEGREES, distribution.sampleSpace);
    for (int i = 0; i < EXPECTED_DEGREE_VALUES.length; ++i) {
        Assert.assertEquals(EXPECTED_DEGREE_VALUES[i], distribution.values[i], DELTA);
    }
    Assert.assertEquals(EXPECTED_DEGREE_VALUES.length, distribution.values.length);
}
 
开发者ID:dice-group,项目名称:Lemming,代码行数:20,代码来源:InDegreeDistributionMetricTest.java

示例8: loadGraph

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
public Model loadGraph(String path) {
	// load model from static dump (can find an example in
	// /cLODg/src/main/resources/data/all-names.rdf)

	Model m = ModelFactory.createDefaultModel();
	InputStream is = null;
	String syntax = null;
	if (path == null) {
		is = getClass().getClassLoader().getResourceAsStream(GRAPH_NAME);
		syntax = "RDF/XML";
	} else {
		try {
			is = new FileInputStream(new File(path));
			syntax = FileUtils.guessLang(path);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	if (is != null)
		m.read(is, null, syntax);

	return m;
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:25,代码来源:AnalyseNames.java

示例9: main

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	// Model model =
	// FileManager.get().loadModel("out/eswc_data_final_swdf.rdf");

	Model model = FileManager.get().loadModel("out/twitterWidget.rdf");
	Model model2 = ModelFactory.createDefaultModel();

	OutputStream out = null;
	try {
		out = new FileOutputStream("./out/eswc.json");
		model2.setNsPrefixes(model.getNsPrefixMap());
		model2.add(model);
		// model2.write(out);

		// model2.write(out, "RDF/JSON") ;
		model2.write(out, "JSON-LD");

	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:26,代码来源:JsonSerializer.java

示例10: main

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
public static void main(String[] args) {
	String sample = "{     \"_id\" : ObjectId(\"560c9d741ee8203c53a63569\"),     \"rn\" : \"CONTENT_INST_5\",     \"ty\" : 4,     \"ri\" : \"CONTENT_INST_5\",     \"pi\" : \"CONTAINER_37\",     \"lbl\" : [          \"cnt-switch\"     ],     \"cr\" : \"C_AE-D-GASLOCK1004\",     \"cnf\" : \"text/plain:0\",     \"cs\" : 3,     \"con\" : \"Off\",     \"_uri\" : \"/herit-in/herit-cse/ae-gaslock1004/cnt-switch/CONTENT_INST_5\",     \"ct\" : \"20151001T114156\",     \"lt\" : \"20151001T114156\" , \"or\":\"http://www.iotoasis.org/ontology/StateCondition\" }";
	Gson gson = new Gson();
	OneM2MContentInstanceDTO cont = gson.fromJson(sample, OneM2MContentInstanceDTO.class);
	System.out.println(cont);

	OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(cont);
	Model model = ModelFactory.createDefaultModel();
	model.add(mapper.from());

	// 스트링 변환부분
	RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
	
	// gooper
	if(! model.isClosed()) {
		model.close();
	}
	if(model != null) {
		model = null;
	}

}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:23,代码来源:OneM2MCSEBaseDTO.java

示例11: addRolesFromModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
public void addRolesFromModel(Model model){
	String sparql = "PREFIX swc: <http://data.semanticweb.org/ns/swc/ontology#> "
			+ "SELECT ?role ?roletype "
			+ "WHERE{?role a swc:Chair . ?role a ?roletype . filter(?roletype != swc:Chair)}";
	Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
	QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
	ResultSet resultSet = queryExecution.execSelect();
	
	Model tmp = ModelFactory.createDefaultModel();
	while(resultSet.hasNext()){
		QuerySolution querySolution = resultSet.next();
		Resource role = querySolution.getResource("role");
		Resource roleType = querySolution.getResource("roletype");
		tmp.add(role, RDF.type, roleType);
	}
	
	
	
	//ResultSetFormatter.out(System.out, resultSet);
	
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:22,代码来源:RoleKB.java

示例12: createOrReplaceObjectRdf

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
/**
 * Create a resource at a specified path, or replace triples with provided RDF.
 *
 * @param requestContentType the request content type
 * @param requestBodyStream  the request body stream
 * @param contentDisposition the content disposition value
 * @param ifMatch            the if-match value
 * @param links              the link values
 * @param digest             the digest header
 * @return 204
 * @throws InvalidChecksumException      if invalid checksum exception occurred
 * @throws MalformedRdfException         if malformed rdf exception occurred
 * @throws UnsupportedAlgorithmException
 */
@PUT
@Consumes
public Response createOrReplaceObjectRdf(
    @HeaderParam(CONTENT_TYPE) final MediaType requestContentType,
    @ContentLocation final InputStream requestBodyStream,
    @HeaderParam(CONTENT_DISPOSITION) final ContentDisposition contentDisposition,
    @HeaderParam("If-Match") final String ifMatch,
    @HeaderParam(LINK) final List<String> links,
    @HeaderParam("Digest") final String digest)
    throws InvalidChecksumException, MalformedRdfException, UnsupportedAlgorithmException {

    final URI internalUri = createFromPath(externalPath);
    if (isRoot(internalUri)) {
        //method not allowed if root
        return Response.status(METHOD_NOT_ALLOWED).build();
    }

    final ContainerService containerService = getContainerService();
    //create resource if exists
    if (!containerService.exists(internalUri)) {
        final Container container = containerService.findOrCreate(internalUri);
        final Model model = ModelFactory.createDefaultModel();
        model.read(requestBodyStream, null, "TTL");
        final Stream<Triple> triples = model.listStatements().toList().stream().map(Statement::asTriple);
        container.updateTriples(triples);
        return created(toExternalURI(container.getIdentifier(), headers)).build();
    } else {
        //TODO delete resource, create resource, and update triples.
        return noContent().build();
    }
}
 
开发者ID:duraspace,项目名称:lambdora,代码行数:46,代码来源:LambdoraLdp.java

示例13: listNotifications

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
public List<String> listNotifications(String inboxUrl) throws InterruptedException, IOException{
		List<String> notifications=new ArrayList<String>();
		
		UrlRequest urlReq=new UrlRequest(inboxUrl, "Accept", "application/ld+json");
		FetchRequest fetched = httpFetcher.fetch(urlReq);
		if (fetched.getResponseStatusCode()==200) {
			if(fetched.getContent().getType().getMimeType().equals("application/ld+json")) {
				Model dcModelRdf = ModelFactory.createDefaultModel();
				ByteArrayInputStream bytesIs = new ByteArrayInputStream(fetched.getContent().asBytes());
				RDFDataMgr.read(dcModelRdf, bytesIs, inboxUrl, Lang.JSONLD);
				try {
					bytesIs.close();
				} catch (IOException e) {
					throw new RuntimeException(e.getMessage(), e); 
				}
					
				Resource resource = dcModelRdf.getResource(inboxUrl);
				
				StmtIterator seeAlsoStms = resource.listProperties(RdfReg.LDN_CONTAINS);
				while (seeAlsoStms.hasNext()) {
					Statement st = seeAlsoStms.next();
//					System.out.println(st);
					notifications.add(st.getObject().toString());
				}
			}
		}
		
		return notifications;
	}
 
开发者ID:nfreire,项目名称:LDN4IIIF,代码行数:30,代码来源:Consumer.java

示例14: SemaphoreModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
public SemaphoreModel(File inputFile) {
	Date startDate = new Date();
	
	model = ModelFactory.createDefaultModel();
	addFile(inputFile);

	Date readDate = new Date();
	logger.info(String.format("Data read in %#.3f seconds", 0.001*(readDate.getTime() - startDate.getTime())));
	
	setPrefixes();
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:12,代码来源:SemaphoreModel.java

示例15: loadOEModelToMem

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
/**
  * Fetch a model from Ontology Editor, load and return as memory-backed Jena model.
  *
  * @param endpoint
  * @return
* @throws OEConnectionException 
* @throws IOException 
  */
 public static Model loadOEModelToMem(OEModelEndpoint endpoint) throws IOException, OEConnectionException {
   Preconditions.checkNotNull(endpoint);

   logger.debug("OEModelEndpoint base URL: {}", endpoint.toString());

   String modelAsTTL = endpoint.fetchData();
   
   logger.debug("Downloaded model: {}", modelAsTTL);
   
   Model model = ModelFactory.createDefaultModel();
   model.read(new ByteArrayInputStream(modelAsTTL.getBytes()), null, "TTL");
   return model;
 }
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:22,代码来源:ModelLoader.java


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