org.apache.jena.sparql.vocabulary.FOAF Java Examples

The following examples show how to use org.apache.jena.sparql.vocabulary.FOAF. 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: SkolemizerTest.java    From Processor with Apache License 2.0 6 votes vote down vote up
/**
 * Test of build method, of class Skolemizer.
 */
@Test
public void testBuild_Model()
{
    Model expected = ModelFactory.createDefaultModel();
    Resource expAbsolute = expected.createResource(baseUriBuilder.clone().path(absoluteId).build().toString()).
            addProperty(RDF.type, absolutePathClass).
            addLiteral(DCTerms.identifier, absoluteId);
    Resource expRelative = expected.createResource(absolutePathBuilder.clone().path(relativeId).build().toString()).
            addProperty(RDF.type, relativePathClass).
            addLiteral(DCTerms.identifier, relativeId);
    Resource expThing = expected.createResource(absolutePathBuilder.clone().path(thingTitle).fragment(thingFragment).build().toString()).
            addProperty(RDF.type, thingClass).
            addLiteral(DCTerms.title, thingTitle);
    Resource expImported = expected.createResource(absolutePathBuilder.clone().path(thingTitle).fragment(thingFragment).build().toString()).
            addProperty(RDF.type, importedClass).
            addLiteral(DCTerms.title, thingTitle);
    Resource expRestricted = expected.createResource(UriBuilder.fromUri(restrictionValue).clone().path(restrictedId).build().toString()).
            addProperty(RDF.type, restrictedClass).
            addLiteral(DCTerms.identifier, restrictedId);        
    expRelative.addProperty(FOAF.primaryTopic, expThing);
    expThing.addProperty(FOAF.isPrimaryTopicOf, expRelative);
    
    Model result = skolemizer.build(input);
    assertTrue(result.isIsomorphicWith(expected));
}
 
Example #2
Source File: SkolemizerTest.java    From Processor with Apache License 2.0 6 votes vote down vote up
/**
 * Test of getNameValueMap method, of class Skolemizer.
 */
@Test
public void testGetNameValueMap()
{
    UriTemplateParser parser = new UriTemplateParser("{name}/{title}|{smth}|{primaryTopic.title}");
    Model model = ModelFactory.createDefaultModel();
    Literal secondTitle = model.createLiteral("Second");
    Literal firstTitle = model.createLiteral("First");

    Resource second = model.createResource().
            addLiteral(DCTerms.title, secondTitle);
    Resource first = model.createResource().
            addLiteral(DCTerms.title, firstTitle).
            addProperty(FOAF.primaryTopic, second);
    
    Map<String, String> expected = new HashMap<>();
    expected.put("title", firstTitle.getString());
    expected.put("primaryTopic.title", secondTitle.getString());
    
    Map<String, String> result = skolemizer.getNameValueMap(first, parser);
    assertEquals(expected, result);
}
 
Example #3
Source File: SkolemizerTest.java    From Processor with Apache License 2.0 6 votes vote down vote up
/**
 * Test of getLiteral method, of class Skolemizer.
 */
@Test
public void testGetLiteral()
{
    Model model = ModelFactory.createDefaultModel();
    Literal secondTitle = model.createLiteral("Second");
    Literal firstTitle = model.createLiteral("First");

    Resource second = model.createResource().
            addLiteral(DCTerms.title, secondTitle);
    Resource first = model.createResource().
            addLiteral(DCTerms.title, firstTitle).
            addProperty(FOAF.primaryTopic, second);
    
    Literal firstResult = skolemizer.getLiteral(first, "title");
    assertEquals(firstTitle, firstResult);
    Literal secondResult = skolemizer.getLiteral(first, "primaryTopic.title");
    assertEquals(secondTitle, secondResult);
    Literal resultFail1 = skolemizer.getLiteral(first, "primaryTopic");
    assertNull(resultFail1); // primaryTopic is a resource, not a literal
    Literal resultFail2 = skolemizer.getLiteral(first, "whatever");
    assertNull(resultFail2); // no such property
}
 
Example #4
Source File: SkolemizerTest.java    From Processor with Apache License 2.0 6 votes vote down vote up
/**
 * Test of getResource method, of class Skolemizer.
 */
@Test
public void testGetResource()
{
    Model model = ModelFactory.createDefaultModel();

    Resource second = model.createResource().
            addLiteral(DCTerms.title, "Second");
    Resource first = model.createResource().
            addLiteral(DCTerms.title, "First").
            addProperty(FOAF.primaryTopic, second);
    
    Resource secondResult = skolemizer.getResource(first, "primaryTopic");
    assertEquals(second, secondResult);
    Resource resultFail1 = skolemizer.getResource(first, "title");
    assertNull(resultFail1); // title is a literal, not a resource
    Resource resultFail2 = skolemizer.getResource(first, "primaryTopic.title");
    assertNull(resultFail2); // title is a literal, not a resource
    Resource resultFail3 = skolemizer.getResource(first, "whatever");
    assertNull(resultFail3); // no such property
}
 
Example #5
Source File: Organization.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@Override
public Model addToModel(Model model) {
    addNsPrefix(model);
    Resource organization = model.createResource(FOAF.NS);
    organization.addProperty(RDF.type, FOAF.Organization);

    if (getmBox() != null) {
        getmBox().addToResource(model, organization);
    }

    if (getName() != null) {
        getName().addToResource(model, organization);
    }
    return model;
}
 
Example #6
Source File: DatasetGenerator.java    From NLIWOD with GNU Affero General Public License v3.0 5 votes vote down vote up
public DatasetGenerator(QueryExecutionFactory qef) {

		this.disambiguator = new AGDISTIS();
		this.recognizer = new Spotlight();

		this.qef=qef;
		// CBD generator
		cbdGen = new ConciseBoundedDescriptionGeneratorImpl(qef);
		cbdGen = new SymmetricConciseBoundedDescriptionGeneratorImpl(qef);

		evaluation=new ArrayList<>();
		correct=0;
		f1sum=0;
		accsum=0;
		// query tree factory
		qtf = new QueryTreeFactoryBaseInv();
		// filters
		ArrayList<Predicate<Statement>> treeFilters = Lists.newArrayList(new PredicateDropStatementFilter(StopURIsDBpedia.get()), new ObjectDropStatementFilter(StopURIsDBpedia.get()),
		        new PredicateDropStatementFilter(Sets.union(StopURIsRDFS.get(), Sets.newHashSet(RDFS.seeAlso.getURI()))), new PredicateDropStatementFilter(StopURIsOWL.get()),
		        new ObjectDropStatementFilter(StopURIsOWL.get()), new PredicateDropStatementFilter(StopURIsSKOS.get()), new ObjectDropStatementFilter(StopURIsSKOS.get()),
		        new NamespaceDropStatementFilter(Sets.newHashSet(
		                // "http://dbpedia.org/property/",
		                "http://purl.org/dc/terms/", "http://dbpedia.org/class/yago/", FOAF.getURI())),
		        new PredicateDropStatementFilter(Sets.newHashSet("http://www.w3.org/2002/07/owl#equivalentClass", "http://www.w3.org/2002/07/owl#disjointWith")));
		qtf.addDropFilters((Predicate<Statement>[]) treeFilters.toArray(new Predicate[treeFilters.size()]));

		// LGG generator
		lggGen = new LGGGeneratorSimple();
	}
 
Example #7
Source File: ExRIOT_4.java    From xcurator with Apache License 2.0 5 votes vote down vote up
public static void main(String...argv)
{
    String filename = "data.ttl" ;

    // This is the heart of N-triples printing ... outoput is heavily buffered
    // so the FilterSinkRDF called flush at the end of parsing.
    Sink<Triple> output = new SinkTripleOutput(System.out, null, SyntaxLabels.createNodeToLabel()) ;
    StreamRDF filtered = new FilterSinkRDF(output, FOAF.name, FOAF.knows) ;
    
    // Call the parsing process. 
    RDFDataMgr.parse(filtered, filename) ;
}
 
Example #8
Source File: RDFStar2RDFTest.java    From RDFstarTools with Apache License 2.0 4 votes vote down vote up
@Test
public void doubleNestedSubject()
{
	final String filename = "doubleNestedSubject.ttls";
       final Graph g = convertAndLoadIntoGraph(filename);

       assertEquals( 11, g.size() );

       verifyNoNesting(g);

       int cntTypeStmt = 0;
       int cntSubjectStmt = 0;
       int cntPredicateStmt1 = 0;
       int cntPredicateStmt2 = 0;
       int cntObjectStmt = 0;
       int cntReifiedStmt1 = 0;
       int cntReifiedStmt2 = 0;
       int cntMetaStmt = 0;

       final Iterator<Triple> it = g.find();
       while ( it.hasNext() )
       {
       	final Triple t = it.next();
       	final Node p = t.getPredicate();
       	final Node o = t.getObject();

       	if ( p.equals(RDF.type.asNode()) && o.equals(RDF.Statement.asNode()) )
       		cntTypeStmt++;
       	else if ( p.equals(RDF.subject.asNode()) )
       		cntSubjectStmt++;
       	else if ( p.equals(RDF.predicate.asNode()) && o.equals(FOAF.knows.asNode()) )
       		cntPredicateStmt1++;
       	else if ( p.equals(RDF.predicate.asNode()) && o.equals(DCTerms.created.asNode()) )
       		cntPredicateStmt2++;
       	else if ( p.equals(RDF.object.asNode()) )
       		cntObjectStmt++;
       	else if ( p.equals(FOAF.knows.asNode()) )
       		cntReifiedStmt1++;
       	else if ( p.equals(DCTerms.created.asNode()) )
       		cntReifiedStmt2++;
       	else if ( p.equals(DCTerms.source.asNode()) )
       		cntMetaStmt++;
       }

       assertEquals( 2, cntTypeStmt );
       assertEquals( 2, cntSubjectStmt );
       assertEquals( 1, cntPredicateStmt1 );
       assertEquals( 1, cntPredicateStmt2 );
       assertEquals( 2, cntObjectStmt );
       assertEquals( 1, cntReifiedStmt1 );
       assertEquals( 1, cntReifiedStmt2 );
       assertEquals( 1, cntMetaStmt );
}
 
Example #9
Source File: RDFStar2RDFTest.java    From RDFstarTools with Apache License 2.0 4 votes vote down vote up
@Test
public void doubleNestedObject()
{
	final String filename = "doubleNestedObject.ttls";
       final Graph g = convertAndLoadIntoGraph(filename);

       assertEquals( 11, g.size() );

       verifyNoNesting(g);

       int cntTypeStmt = 0;
       int cntSubjectStmt = 0;
       int cntPredicateStmt1 = 0;
       int cntPredicateStmt2 = 0;
       int cntObjectStmt = 0;
       int cntReifiedStmt1 = 0;
       int cntReifiedStmt2 = 0;
       int cntMetaStmt = 0;

       final Iterator<Triple> it = g.find();
       while ( it.hasNext() )
       {
       	final Triple t = it.next();
       	final Node s = t.getSubject();
       	final Node p = t.getPredicate();
       	final Node o = t.getObject();

       	if ( p.equals(RDF.type.asNode()) && o.equals(RDF.Statement.asNode()) )
       		cntTypeStmt++;
       	else if ( p.equals(RDF.subject.asNode()) )
       		cntSubjectStmt++;
       	else if ( p.equals(RDF.predicate.asNode()) && o.equals(FOAF.knows.asNode()) )
       		cntPredicateStmt1++;
       	else if ( p.equals(RDF.predicate.asNode()) && o.equals(DCTerms.created.asNode()) )
       		cntPredicateStmt2++;
       	else if ( p.equals(RDF.object.asNode()) )
       		cntObjectStmt++;
       	else if ( p.equals(FOAF.knows.asNode()) && s.getURI().contains("alice") )
       		cntReifiedStmt1++;
       	else if ( p.equals(DCTerms.created.asNode()) )
       		cntReifiedStmt2++;
       	else if ( p.equals(FOAF.knows.asNode()) )
       		cntMetaStmt++;
       }

       assertEquals( 2, cntTypeStmt );
       assertEquals( 2, cntSubjectStmt );
       assertEquals( 1, cntPredicateStmt1 );
       assertEquals( 1, cntPredicateStmt2 );
       assertEquals( 2, cntObjectStmt );
       assertEquals( 1, cntReifiedStmt1 );
       assertEquals( 1, cntReifiedStmt2 );
       assertEquals( 1, cntMetaStmt );
}
 
Example #10
Source File: MBox.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
@Override
public Property getProperty() {
    return FOAF.mbox;
}
 
Example #11
Source File: Homepage.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
@Override
public Property getProperty() {
    return FOAF.homepage;
}
 
Example #12
Source File: FoafRdfPrefix.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
@Override
default String getNamespace() {
    return FOAF.NS;
}
 
Example #13
Source File: Name.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
@Override
public Property getProperty() {
    return FOAF.name;
}
 
Example #14
Source File: SkolemizerTest.java    From Processor with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp()
{
    baseUriBuilder = UriBuilder.fromUri("http://base/");
    absolutePathBuilder = UriBuilder.fromUri("http://base/absolute/path");
    ontology = ModelFactory.createOntologyModel().createOntology("http://test/ontology");
    importedOntology = ontology.getOntModel().createOntology("http://test/ontology/import");
    ontology.addImport(importedOntology);
    skolemizer = new Skolemizer(ontology, baseUriBuilder, absolutePathBuilder);
    
    relativePathClass = ontology.getOntModel().createClass("http://test/ontology/relative-path-class");
    relativePathClass.addLiteral(LDT.path, "{identifier}").
            addProperty(RDFS.isDefinedBy, ontology);
    absolutePathClass = ontology.getOntModel().createClass("http://test/ontology/absolute-path-class");
    absolutePathClass.addLiteral(LDT.path, "/{identifier}").
            addProperty(RDFS.isDefinedBy, ontology);
    thingClass = ontology.getOntModel().createClass("http://test/ontology/thing-class");
    thingClass.addLiteral(LDT.path, "{title}").
            addProperty(LDT.fragment, "something").
            addProperty(RDFS.isDefinedBy, ontology);
    importedClass = importedOntology.getOntModel().createClass("http://test/ontology/import/thing-class");
    importedClass.addLiteral(LDT.path, "{title}").
            addProperty(LDT.fragment, "something").
            addProperty(RDFS.isDefinedBy, importedOntology);
    restrictedClass = ontology.getOntModel().createClass("http://test/ontology/restricted-class");
    restrictedClass.addLiteral(LDT.path, "{identifier}").
            addProperty(RDFS.isDefinedBy, ontology).
            addProperty(RDFS.subClassOf, restrictedClass.getOntModel().createHasValueRestriction(null, SIOC.HAS_CONTAINER, restrictedClass.getOntModel().createResource(restrictionValue)));
    restrictedClass.getOntModel().createResource(SIOC.HAS_CONTAINER.getURI()).
            addProperty(RDF.type, OWL.ObjectProperty);
    undefinedClass = ontology.getOntModel().createClass("http://test/ontology/undefined-class");
    undefinedClass.addLiteral(LDT.path, "{whateverest}"); // does not have rdfs:isDefinedBy
            
    input = ModelFactory.createDefaultModel();
    absolute = input.createResource().
            addProperty(RDF.type, absolutePathClass).
            addLiteral(DCTerms.identifier, absoluteId);
    relative = input.createResource().
            addProperty(RDF.type, relativePathClass).
            addLiteral(DCTerms.identifier, relativeId);
    thing = input.createResource().
            addProperty(RDF.type, thingClass).
            addLiteral(DCTerms.title, thingTitle);
    imported = input.createResource().
            addProperty(RDF.type, importedClass).
            addLiteral(DCTerms.title, thingTitle);
    restricted = input.createResource().
            addProperty(RDF.type, restrictedClass).
            addLiteral(DCTerms.identifier, restrictedId);
    relative.addProperty(FOAF.primaryTopic, thing);
    thing.addProperty(FOAF.isPrimaryTopicOf, relative);
}