Skip to content

Commit

Permalink
Merge remote-tracking branch 'rdf4j-doc/master' into GH-2333-merge-rd…
Browse files Browse the repository at this point in the history
…f4j-doc-master
  • Loading branch information
abrokenjester committed Jul 25, 2020
2 parents c496774 + 04b4d16 commit c058ae9
Show file tree
Hide file tree
Showing 49,582 changed files with 15,845,405 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "site/themes/hugo-solstice-theme"]
path = site/themes/hugo-solstice-theme
url = https://github.com/EclipseFdn/hugo-solstice-theme.git
3 changes: 3 additions & 0 deletions examples/.settings/org.eclipse.jdt.ui.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
formatter_profile=_examples
formatter_settings_version=12
55 changes: 55 additions & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.eclipse.rdf4j</groupId>
<artifactId>examples</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-bom</artifactId>
<version>2.1.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-queryresultio-text</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.10</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf8</encoding>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2017 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*******************************************************************************/
package org.eclipse.rdf4j.examples.function;

import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.query.algebra.evaluation.ValueExprEvaluationException;
import org.eclipse.rdf4j.query.algebra.evaluation.function.Function;

/**
* An example custom SPARQL function that detects palindromes
*
* @author Jeen Broekstra
*/
public class PalindromeFunction implements Function {

// define a constant for the namespace of our custom function
public static final String NAMESPACE = "http://example.org/custom-function/";

/**
* return the URI 'http://example.org/custom-function/palindrome' as a
* String
*/
public String getURI() {
return NAMESPACE + "palindrome";
}

/**
* Executes the palindrome function.
*
* @return A boolean literal representing true if the input argument is a
* palindrome, false otherwise.
* @throws ValueExprEvaluationException
* if more than one argument is supplied or if the supplied argument
* is not a literal.
*/
public Value evaluate(ValueFactory valueFactory, Value... args)
throws ValueExprEvaluationException
{
// our palindrome function expects only a single argument, so throw an error
// if there's more than one
if (args.length != 1) {
throw new ValueExprEvaluationException(
"palindrome function requires" + "exactly 1 argument, got "
+ args.length);
}
Value arg = args[0];
// check if the argument is a literal, if not, we throw an error
if (!(arg instanceof Literal)) {
throw new ValueExprEvaluationException(
"invalid argument (literal expected): " + arg);
}

// get the actual string value that we want to check for palindrome-ness.
String label = ((Literal)arg).getLabel();
// we invert our string
String inverted = "";
for (int i = label.length() - 1; i >= 0; i--) {
inverted += label.charAt(i);
}
// a string is a palindrome if it is equal to its own inverse
boolean palindrome = inverted.equalsIgnoreCase(label);

// a function is always expected to return a Value object, so we
// return our boolean result as a Literal
return valueFactory.createLiteral(palindrome);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2016 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*******************************************************************************/
package org.eclipse.rdf4j.examples.model;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.model.impl.TreeModel;
import org.eclipse.rdf4j.model.vocabulary.FOAF;
import org.eclipse.rdf4j.model.vocabulary.RDF;

/**
* RDF Tutorial example 01: Building a simple RDF Model using Eclipse RDF4J
*
* @author Jeen Broekstra
*/
public class Example01BuildModel {

public static void main(String[] args) {

// We use a ValueFactory to create the building blocks of our RDF statements: IRIs, blank nodes
// and literals.
ValueFactory vf = SimpleValueFactory.getInstance();

// We want to reuse this namespace when creating several building blocks.
String ex = "http://example.org/";

// Create IRIs for the resources we want to add.
IRI picasso = vf.createIRI(ex, "Picasso");
IRI artist = vf.createIRI(ex, "Artist");

// Create a new, empty Model object.
Model model = new TreeModel();

// add our first statement: Picasso is an Artist
model.add(picasso, RDF.TYPE, artist);

// second statement: Picasso's first name is "Pablo".
model.add(picasso, FOAF.FIRST_NAME, vf.createLiteral("Pablo"));

// to see what's in our model, let's just print it to the screen
for(Statement st: model) {
System.out.println(st);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2016 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*******************************************************************************/
package org.eclipse.rdf4j.examples.model;

import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.util.ModelBuilder;
import org.eclipse.rdf4j.model.vocabulary.FOAF;
import org.eclipse.rdf4j.model.vocabulary.RDF;

/**
* RDF Tutorial example 02: Building a simple RDF Model using the RDF4J ModelBuilder
*
* @author Jeen Broekstra
*/
public class Example02BuildModel {

public static void main(String[] args) {

// Create a new RDF model containing two statements by using a ModelBuilder
ModelBuilder builder = new ModelBuilder();
Model model = builder
.setNamespace("ex", "http://example.org/")
.subject("ex:Picasso")
.add(RDF.TYPE, "ex:Artist") // Picasso is an Artist
.add(FOAF.FIRST_NAME, "Pablo") // his first name is "Pablo"
.build();

// To see what's in our model, let's just print it to the screen
for(Statement st: model) {
System.out.println(st);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2016, 2017 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*******************************************************************************/
package org.eclipse.rdf4j.examples.model;

import java.util.Date;

import javax.xml.datatype.XMLGregorianCalendar;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.model.util.ModelBuilder;
import org.eclipse.rdf4j.model.vocabulary.XMLSchema;

/**
* RDF Tutorial example 03: Datatyped literals
*
* @author Jeen Broekstra
*/
public class Example03LiteralDatatypes {

public static void main(String[] args) {

ValueFactory vf = SimpleValueFactory.getInstance();

// Create a new RDF model containing information about the painting "The Potato Eaters"
ModelBuilder builder = new ModelBuilder();
Model model = builder
.setNamespace("ex", "http://example.org/")
.subject("ex:PotatoEaters")
// this painting was created on April 1, 1885
.add("ex:creationDate", vf.createLiteral("1885-04-01T00:00:00Z", XMLSchema.DATETIME))
// You can also pass in a Java Date object directly:
//.add("ex:creationDate", new GregorianCalendar(1885, Calendar.APRIL, 1).getTime())

// the painting shows 5 people
.add("ex:peopleDepicted", 5)
.build();

// To see what's in our model, let's just print stuff to the screen
for(Statement st: model) {
// we want to see the object values of each property
IRI property = st.getPredicate();
Value value = st.getObject();
if (value instanceof Literal) {
Literal literal = (Literal)value;
System.out.println("datatype: " + literal.getDatatype());

// get the value of the literal directly as a Java primitive.
if (property.getLocalName().equals("peopleDepicted")) {
int peopleDepicted = literal.intValue();
System.out.println(peopleDepicted + " people are depicted in this painting");
}
else if (property.getLocalName().equals("creationDate")) {
XMLGregorianCalendar calendar = literal.calendarValue();
Date date = calendar.toGregorianCalendar().getTime();
System.out.println("The painting was created on " + date);
}

// you can also just get the lexical value (a string) without worrying about the datatype
System.out.println("Lexical value: '" + literal.getLabel() + "'");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2016, 2017 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*******************************************************************************/
package org.eclipse.rdf4j.examples.model;

import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.model.util.ModelBuilder;
import org.eclipse.rdf4j.model.vocabulary.DC;

/**
* RDF Tutorial example 04: Language tags
*
* @author Jeen Broekstra
*/
public class Example04LanguageTags {

public static void main(String[] args) {

ValueFactory vf = SimpleValueFactory.getInstance();

// Create a new RDF model containing some information about the painting "The Potato Eaters"
ModelBuilder builder = new ModelBuilder();
Model model = builder
.setNamespace("ex", "http://example.org/")
.subject("ex:PotatoEaters")
// In English, this painting is called "The Potato Eaters"
.add(DC.TITLE, vf.createLiteral("The Potato Eaters", "en"))
// In Dutch, it's called "De Aardappeleters"
.add(DC.TITLE, vf.createLiteral("De Aardappeleters", "nl"))
.build();

// To see what's in our model, let's just print it to the screen
for(Statement st: model) {
// we want to see the object values of each statement
Value value = st.getObject();
if (value instanceof Literal) {
Literal title = (Literal)value;
System.out.println("language: " + title.getLanguage().orElse("unknown"));
System.out.println(" title: " + title.getLabel());
}
}
}
}
Loading

0 comments on commit c058ae9

Please sign in to comment.