Java Code Examples for org.apache.jena.rdf.model.Model#setNsPrefixes()

The following examples show how to use org.apache.jena.rdf.model.Model#setNsPrefixes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractDataGenerator.java    From IGUANA with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Will send a {@link org.apache.jena.rdf.model.Model} 
 */
public void sendData(Model m) throws Exception {
	int sendedSize=0;
	//split Model into small parts
	StmtIterator sti = m.listStatements();
	while(sti.hasNext()){
		Model send = ModelFactory.createDefaultModel();
		send.setNsPrefixes(m.getNsPrefixMap());
		while(sendedSize < maxSize){
			Statement stmt = sti.next();
			send.add(stmt);
			sendedSize+=1;
		}
		sendDataSnippet(RabbitMQUtils.getData(send));
	}
	
}
 
Example 2
Source File: ValidationEngine.java    From shacl with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new ValidationEngine.
 * @param dataset  the Dataset to operate on
 * @param shapesGraphURI  the URI of the shapes graph (must be in the dataset)
 * @param shapesGraph  the ShapesGraph with the shapes to validate against
 * @param report  the sh:ValidationReport object in the results Model, or null to create a new one
 */
protected ValidationEngine(Dataset dataset, URI shapesGraphURI, ShapesGraph shapesGraph, Resource report) {
	super(dataset, shapesGraph, shapesGraphURI);
	setConfiguration(new ValidationEngineConfiguration());
	if(report == null) {
		Model reportModel = JenaUtil.createMemoryModel();
		reportModel.setNsPrefixes(dataset.getDefaultModel());
		reportModel.withDefaultMappings(shapesGraph.getShapesModel());
		this.report = reportModel.createResource(SH.ValidationReport);
	}
	else {
		this.report = report;
	}
}
 
Example 3
Source File: RdfWriterImpl.java    From Server.Java with MIT License 5 votes vote down vote up
@Override
public void writeFragment(ServletOutputStream outputStream, IDataSource datasource, ILinkedDataFragment fragment, ILinkedDataFragmentRequest ldfRequest) throws Exception {
    final Model output = ModelFactory.createDefaultModel();
    output.setNsPrefixes(getPrefixes());
    output.add(fragment.getMetadata());
    output.add(fragment.getTriples());
    output.add(fragment.getControls());
    RDFDataMgr.write(outputStream, output, contentType);
}
 
Example 4
Source File: DB2QueryExecutionImpl.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public Model execConstruct(Model model)
{

if (query.isConstructType())
   {
   QueryPrologue prologue = query.getDB2Query().getPrologue();
   Map<String, IRI> prefixes = prologue.getPrefixes();
   Iterator<String> iter = prefixes.keySet().iterator();
   Map<String, String> namespaces = null;
   while (iter.hasNext())
      {
      namespaces = new HashMap<String, String>();
      String namespaceprefix = (String) iter.next();
      namespaces.put(namespaceprefix, prefixes.get(namespaceprefix).toString());
      }

   if (namespaces != null)
      model.setNsPrefixes(namespaces);
   Iterator<Triple> it = execConstructTriples();
   while(it.hasNext())
      {  
      	Triple t = it.next();
      model.add(model.asStatement(t));
      }
   return model;
   }

throw new IllegalArgumentException("Query was executed as CONSTRUCT query, though it's not one");

}
 
Example 5
Source File: CtlEarlReporter.java    From teamengine with Apache License 2.0 5 votes vote down vote up
private Model initializeModel( String suiteName ) {
    Model model = ModelFactory.createDefaultModel();
    Map<String, String> nsBindings = new HashMap<>();
    nsBindings.put( "earl", EARL.NS_URI );
    nsBindings.put( "dct", DCTerms.NS );
    nsBindings.put( "cite", CITE.NS_URI );
    nsBindings.put( "http", HTTP.NS_URI );
    nsBindings.put( "cnt", CONTENT.NS_URI );
    model.setNsPrefixes( nsBindings );
    this.testRun = model.createResource( CITE.TestRun );
    this.testRun.addProperty( DCTerms.title, suiteName );
    String nowUTC = ZonedDateTime.now( ZoneId.of( "Z" ) ).format( DateTimeFormatter.ISO_INSTANT );
    this.testRun.addProperty( DCTerms.created, nowUTC );
    this.assertor = model.createResource( "https://github.com/opengeospatial/teamengine", EARL.Assertor );
    this.assertor.addProperty( DCTerms.title, "OGC TEAM Engine", this.langCode );
    this.assertor.addProperty( DCTerms.description,
                               "Official test harness of the OGC conformance testing program (CITE).",
                               this.langCode );
    /*
     * Map<String, String> params = suite.getXmlSuite().getAllParameters(); String iut = params.get("iut"); if (null
     * == iut) { // non-default parameter refers to test subject--use first URI value for (Map.Entry<String, String>
     * param : params.entrySet()) { try { URI uri = URI.create(param.getValue()); iut = uri.toString(); } catch
     * (IllegalArgumentException e) { continue; } } } if (null == iut) { throw new
     * NullPointerException("Unable to find URI reference for IUT in test run parameters." ); }
     */

    this.testSubject = model.createResource( "", EARL.TestSubject );
    return model;
}
 
Example 6
Source File: EarlReporter.java    From teamengine with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes the test results graph with basic information about the
 * assertor (earl:Assertor) and test subject (earl:TestSubject).
 * 
 * @param suite
 *            Information about the test suite.
 * @return An RDF Model containing EARL statements.
 */
Model initializeModel(ISuite suite) {
    Model model = ModelFactory.createDefaultModel();
    Map<String, String> nsBindings = new HashMap<>();
    nsBindings.put("earl", EARL.NS_URI);
    nsBindings.put("dct", DCTerms.NS);
    nsBindings.put("cite", CITE.NS_URI);
    nsBindings.put("http", HTTP.NS_URI);
    nsBindings.put("cnt", CONTENT.NS_URI);
    model.setNsPrefixes(nsBindings);
    suiteName = suite.getName();
    this.testRun = model.createResource(CITE.TestRun);
    this.testRun.addProperty(DCTerms.title, suite.getName());
    String nowUTC = ZonedDateTime.now(ZoneId.of("Z")).format(DateTimeFormatter.ISO_INSTANT);
    this.testRun.addProperty(DCTerms.created, nowUTC);
    this.assertor = model.createResource("https://github.com/opengeospatial/teamengine",
            EARL.Assertor);
    this.assertor.addProperty(DCTerms.title, "OGC TEAM Engine", this.langCode);
    this.assertor.addProperty(DCTerms.description,
            "Official test harness of the OGC conformance testing program (CITE).",
            this.langCode);
    Map<String, String> params = suite.getXmlSuite().getAllParameters();
    String iut = params.get("iut");
    if (null == iut) {
        // non-default parameter refers to test subject--use first URI value
        for (Map.Entry<String, String> param : params.entrySet()) {
            try {
                URI uri = URI.create(param.getValue());
                iut = uri.toString();
            } catch (IllegalArgumentException e) {
                continue;
            }
        }
    }
    if (null == iut) {
        throw new NullPointerException(
                "Unable to find URI reference for IUT in test run parameters.");
    }
    this.testSubject = model.createResource(iut, EARL.TestSubject);
    return model;
}
 
Example 7
Source File: TestExecutionReaderTest.java    From RDFUnit with Apache License 2.0 3 votes vote down vote up
@Test
public void test() {

    assertThat(inputModel.isEmpty()).isFalse();
    Model outputModel = ModelFactory.createDefaultModel();
    outputModel.setNsPrefixes(inputModel.getNsPrefixMap());

    for (Resource testExecutionResource: inputModel.listResourcesWithProperty(RDF.type, RDFUNITv.TestExecution).toList()) {
        TestExecution testExecution = TestExecutionReader.create().read(testExecutionResource);

        TestExecutionWriter writer = TestExecutionWriter.create(testExecution) ;
        writer.write(outputModel);
    }

    //new RDFFileWriter(resultTypeName).write(outputModel);

    //Model difference = inputModel.difference(outputModel);
    //new RDFFileWriter("diff-" +resultTypeName).write(difference);

    //Model difference2 = outputModel.difference(inputModel);
    //new RDFFileWriter("diff2-" +resultTypeName).write(difference2);
    assertThat(inputModel.isIsomorphicWith(outputModel)).isTrue();

    //assertThat(difference.isEmpty()).isTrue();
    //assertThat(difference2.isEmpty()).isTrue();






}
 
Example 8
Source File: PrefixNSService.java    From RDFUnit with Apache License 2.0 2 votes vote down vote up
/**
 * Adds the defined prefixes in a give model
 *
 * @param model the model we want to initialize
 */
public static void setNSPrefixesInModel(Model model) {
    model.setNsPrefixes(getPrefixMap());
}