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

The following examples show how to use org.apache.jena.rdf.model.Model#createResource() . 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: TestRdfModelObject.java    From tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindSetElementsPropertyValue() throws InvalidSPDXAnalysisException {
	final Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	Resource r = model.createResource();
	EmptyRdfModelObject empty = new EmptyRdfModelObject(modelContainer, r.asNode());
	SpdxElement result = empty.findElementPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1);
	assertTrue(result == null);
	String elementName1 = "element name 1";
	String elementComment1 = "element comment 1";
	SpdxElement element1 = new SpdxElement(elementName1, elementComment1, null, null);
	empty.setPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, element1);
	result = empty.findElementPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(element1, result);
	String elementName2 = "element name 2";
	String elementComment2 = "element comment 2";
	SpdxElement element2 = new SpdxElement(elementName2, elementComment2, null, null);
	empty.setPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1, element2);
	result = empty.findElementPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(element2, result);
}
 
Example 2
Source File: TestRdfModelObject.java    From tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddPropertyChecksumValue() throws InvalidSPDXAnalysisException {
	final Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	Resource r = model.createResource();
	EmptyRdfModelObject empty = new EmptyRdfModelObject(modelContainer, r.asNode());
	Checksum c1 = new Checksum(ChecksumAlgorithm.checksumAlgorithm_sha1, 
			"1123456789abcdef0123456789abcdef01234567");
	Checksum c2 = new Checksum(ChecksumAlgorithm.checksumAlgorithm_md5, 
			"2123456789abcdef0123456789abcdef01234567");
	c2.createResource(modelContainer);
	Checksum[] result = empty.findMultipleChecksumPropertyValues(TEST_NAMESPACE, TEST_PROPNAME2);
	assertEquals(0, result.length);
	empty.addPropertyValue(TEST_NAMESPACE, TEST_PROPNAME2, c1);
	result = empty.findMultipleChecksumPropertyValues(TEST_NAMESPACE, TEST_PROPNAME2);
	assertEquals(1, result.length);
	assertEquals(c1, result[0]);
	empty.addPropertyValue(TEST_NAMESPACE, TEST_PROPNAME2, c2);
	result = empty.findMultipleChecksumPropertyValues(TEST_NAMESPACE, TEST_PROPNAME2);
	assertEquals(2, result.length);
	assertTrue(UnitTestHelper.isArraysEquivalent(new Checksum[] {c1, c2}, result));
}
 
Example 3
Source File: JenaUtil.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static RDFNode fromAtom(Model m, Object o, BasicUniverse u, Instance t2) {
	if (o instanceof Pair<?,?>) {
		return fromLiteral(m, (Pair<String,Object>) o, u, t2);
	} else if (o.toString().startsWith("_:")) {
		return m.createResource(new AnonId(o.toString()));
	} else {
		return m.createResource(o.toString());
	}
}
 
Example 4
Source File: ExQuerySelect2.java    From xcurator with Apache License 2.0 5 votes vote down vote up
public static Model createModel()
{
    Model m = ModelFactory.createDefaultModel() ;
    
    Resource r1 = m.createResource("http://example.org/book#1") ;
    Resource r2 = m.createResource("http://example.org/book#2") ;
    
    r1.addProperty(DC.title, "SPARQL - the book")
      .addProperty(DC.description, "A book about SPARQL") ;
    
    r2.addProperty(DC.title, "Advanced techniques for SPARQL") ;
    
    return m ;
}
 
Example 5
Source File: TestRdfModelObject.java    From tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindSetPropertyUriValue() throws InvalidSPDXAnalysisException {
	final Model model = ModelFactory.createDefaultModel();
	IModelContainer modelContainer = new ModelContainerForTest(model, "http://testnamespace.com");
	Resource r = model.createResource();
	EmptyRdfModelObject empty = new EmptyRdfModelObject(modelContainer, r.asNode());
	String uri = "http://this.is.a#uri";
	empty.setPropertyUriValue(TEST_NAMESPACE, TEST_PROPNAME1, uri);
	String result = empty.findUriPropertyValue(TEST_NAMESPACE, TEST_PROPNAME1);
	assertEquals(uri, result);
}
 
Example 6
Source File: SolidContactsImport.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
private String createPersonDirectory(String url, SolidUtilities utilities) throws IOException {
  Model personDirectoryModel = ModelFactory.createDefaultModel();
  personDirectoryModel.createResource("");
  return utilities.postContent(
      url,
      "Person",
      BASIC_CONTAINER_TYPE,
      personDirectoryModel);
}
 
Example 7
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 8
Source File: Catalog.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@Override
public Model addToModel(Model model) {
    addNsPrefix(model);
    Resource catalog = model.createResource(DCAT.Catalog);

    addTitleAndDescription(model, catalog);

    if (getPublisher() != null) {
        getPublisher().addToResource(model, catalog);
    }

    for (Dataset dataset : getDatasets()) {
        dataset.addToResource(model, catalog);
    }

    for (Language language : getLanguages()) {
        language.addToResource(model, catalog);
    }

    if (getHomepage() != null) {
        getHomepage().addToResource(model, catalog);
    }

    if (getIssued() != null) {
        getIssued().addToResource(model, catalog);
    }

    for (ThemeTaxonomy themeTaxonomy : getThemeTaxonomies()) {
        themeTaxonomy.addToResource(model, catalog);
    }

    if (getModified() != null) {
        getModified().addToResource(model, catalog);
    }
    return model;
}
 
Example 9
Source File: CtlEarlReporter.java    From teamengine with Apache License 2.0 5 votes vote down vote up
/**
 * This method is used to add test inputs in to earl report.
 *
 * @param earl
 *            Model object to add the result into it.
 * @param params
 *            The variable is type of Map with all the user input.
 */
private void addTestInputs( Model earl, Map<String, String> params ) {
    Bag inputs = earl.createBag();
    if ( !params.equals( "" ) && params != null ) {
        String value = "";
        for ( String key : params.keySet() ) {
            value = params.get( key );
            Resource testInputs = earl.createResource();
            testInputs.addProperty( DCTerms.title, key );
            testInputs.addProperty( DCTerms.description, value );
            inputs.add( testInputs );
        }
    }
    this.testRun.addProperty( CITE.inputs, inputs );
}
 
Example 10
Source File: Location.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@Override
public Resource createResource(Model model, Resource parent) {
    addNsPrefix(model);
    Resource location = model.createResource(DCTerms.Location);
    for (Geometry geometry : getGeometries()) {
        geometry.addToResource(model, location);
    }
    return location;
}
 
Example 11
Source File: ElementWriter.java    From RDFUnit with Apache License 2.0 5 votes vote down vote up
static Resource copyElementResourceInModel(Element element, Model model) {
    if (!element.getElement().isAnon()) {
        return model.createResource(element.getElement().getURI());
    } else {
        return model.createResource();
    }
}
 
Example 12
Source File: StageAltMain.java    From xcurator with Apache License 2.0 5 votes vote down vote up
private static Model makeData()
{
    Model model = ModelFactory.createDefaultModel() ;
    Resource r = model.createResource(NS+"r") ;
    Property p1 = model.createProperty(NS+"p1") ;
    Property p2 = model.createProperty(NS+"p2") ;
    model.add(r, p1, "xyz") ;
    model.add(r, p2, "abc") ;
    return model ;
}
 
Example 13
Source File: SPDXReview.java    From tools with Apache License 2.0 4 votes vote down vote up
public Resource createResource(Model model) {
	Resource type = model.createResource(SpdxRdfConstants.SPDX_NAMESPACE + SpdxRdfConstants.CLASS_SPDX_REVIEW);
	Resource retval = model.createResource(type);
	populateModel(model, retval);
	return retval;
}
 
Example 14
Source File: SPDXConjunctiveLicenseSet.java    From tools with Apache License 2.0 4 votes vote down vote up
@Override
protected Resource _createResource(Model model) {
	Resource type = model.createResource(SpdxRdfConstants.SPDX_NAMESPACE + SpdxRdfConstants.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET);
	return super._createResource(model, type);
}
 
Example 15
Source File: SpdxDocument.java    From tools with Apache License 2.0 4 votes vote down vote up
@Override
public Resource getType(Model model) {
	return model.createResource(SpdxRdfConstants.SPDX_NAMESPACE + SpdxRdfConstants.CLASS_SPDX_DOCUMENT);
}
 
Example 16
Source File: DisjunctiveLicenseSet.java    From tools with Apache License 2.0 4 votes vote down vote up
@Override
public Resource getType(Model model) {
	return model.createResource(SpdxRdfConstants.SPDX_NAMESPACE + SpdxRdfConstants.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET);
}
 
Example 17
Source File: ReferenceType.java    From tools with Apache License 2.0 4 votes vote down vote up
@Override
public Resource getType(Model model) {
	return model.createResource(SpdxRdfConstants.SPDX_NAMESPACE + SpdxRdfConstants.CLASS_SPDX_REFERENCE_TYPE);
}
 
Example 18
Source File: ByteOffsetPointer.java    From tools with Apache License 2.0 4 votes vote down vote up
@Override
public Resource getType(Model model) {
	return model.createResource(SpdxRdfConstants.RDF_POINTER_NAMESPACE + SpdxRdfConstants.CLASS_POINTER_BYTE_OFFSET_POINTER);
}
 
Example 19
Source File: SolidContactsImport.java    From data-transfer-project with Apache License 2.0 4 votes vote down vote up
private String createContainer(String url, String slug, SolidUtilities utilities) throws Exception {
  Model containerModel = ModelFactory.createDefaultModel();
  Resource containerResource = containerModel.createResource("");
  containerResource.addProperty(DCTerms.title, slug);
  return utilities.postContent(url, slug, BASIC_CONTAINER_TYPE, containerModel);
}
 
Example 20
Source File: SPDXNonStandardLicense.java    From tools with Apache License 2.0 4 votes vote down vote up
@Override
protected Resource _createResource(Model model) {
	Resource type = model.createResource(SpdxRdfConstants.SPDX_NAMESPACE + SpdxRdfConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO);
	return super._createResource(model, type);
}