<commit_before>include::../shared-settings.adoc[]
include::../header.adoc[]
:javadoc: http://docs.rdf4j.org/javadoc/latest?org/eclipse/rdf4j/
:examples: https://github.com/eclipse/rdf4j-doc/tree/master/examples/src/main/java/org/eclipse/rdf4j/examples/

:numbered!:
== How to use RDF and the RDF4J Framework

Getting started with RDF is not hard! In this tutorial, we go through the basics of what RDF is and how you can use it, and we show how you can use the Eclipse RDF4J framework to create, process, store, and query RDF data. We assume that you know a little about programming in Java, but no prior knowledge on RDF is assumed.

TIP: The code examples in this tutorial are available for download from the https://github.com/eclipse/rdf4j-doc/tree/master/examples[examples directory in the rdf4j-doc GitHub repository]. We encourage you to download these examples and play around with them. The easiest way to do this is to download the GitHub repository in your favorite Java IDE as an Apache Maven project. 

:numbered:
== Introducing RDF

The https://www.w3.org/TR/rdf11-primer/[Resource Description Framework (RDF)] is a standard (or more accurately, a "recommendation") formulated by the https://www.w3.org/[World Wide Web Consortium (W3C)]. The purpose of RDF is to provide a framework for expressing information about resources in a machine-processable, interoperable fashion.

A _resource_ can be anything that we can stick an identifier on: a web page, an image, but also more abstract/real-world things like you, me, the concept of "world peace", the number 42, and that library book you never returned. 

RDF is intended for modeling information that needs to processed by applications, rather than just being shown to people. 

In this tutorial, we will be modeling information about artists . Let's start with a simple fact: "Picasso's first name is Pablo". In RDF, this could be expressed as follows:

image:rdf-graph-1.png[]

So what exactly are we looking at here? Well, we have a _resource_ "Picasso", denoted by an IRI (Internationalized _Resource Identifier_): `http://example.org/Picasso`. In RDF, resources have _properties_. Here we are using the `foaf:firstName` property to denote the relation between the resource "Picasso" and the value "Pablo". `foaf:firstName` is also an IRI, though to make things easier to read we use an abbreviated syntax, called _prefixed names_ (more about this later). Finally, the property value, "Pablo", is a _literal_ value: it is not represented using a resource identifier, but simply as a string of characters.

As you may have noticed, we have depicted our fact about Picasso as a simple *graph*: two nodes, connected by an edge. It is very helpful to think about RDF models as graphs, and a lot of the tools we will be using to create and query RDF data make a lot more sense if you do.

In RDF, each fact is called a *statement*. Each statement consists of three parts (for this reason, it is also often called a _triple_):

* the _subject_ is the starting node of the statement, representing the resource that the fact is "about";
* the _predicate_ is the property that denotes the edge between two nodes;
* the _object_ is the end node of the statement, representing the resource or literal that is the _property value_.

Let's expand our example slightly: we don't just have a single statement about Picasso, we know another fact as well: "Picasso is an artist". We can extend our RDF model as follows:

image:rdf-graph-2.png[]

Notice how the second statement was added to our graph depiction by simply adding a second edge to an already existing node , labeled with the `rdf:type` property, and the value `ex:Artist`. As you continue to add new facts to your data model, nodes and edges continue to be added to the graph.

=== IRIs, namespaces, and prefixed names

IRIs are at the core of what makes RDF powerful. They provide a mechanism that allows global identification of any resource: no matter who authors a dataset or where that data is physically stored, if that data shares an identical IRI with another dataset you know that both datasets are talking about the same thing. 

In many RDF data sets, you will see IRIs that start with 'http://...'. This does not necessarily mean that you can open this link in your browser and get anything meaningful, though. Quite often, IRIs are merely used as unique identifiers, and not as actual addresses. Some RDF sources _do_ make sure that their IRIs can be looked up on the Web, and that you actually get back data (in RDF) that describes the resource identified by the IRI. This is known as a http://linkeddata.org/[Linked Data] architecture. The ins and outs of Linked Data are beyond the scope of this tutorial, but it's worth exploring once you understand the basics of RDF.

You will often see IRIs in abbreviated form whenever you encounter examples of RDF data: `<prefix>:<name>` This abbreviated form, known as "prefixed names", has no impact on the meaning of the data, but it makes it easier for people to read the data. 

Prefixed names work by defining a _prefix_ that is a replacement for a _namespace_. A namespace is the first part of an IRI that is shared by several resources. For example, the IRIs `http://example.org/Picasso`, `http://example.org/Rodin`, and `http://example.org/Rembrandt` all share the the namespace `http://example.org/`. By defining a new prefix `ex` as the abbreviation for this namespace, we can use the string `ex:Picasso` instead of its full IRI.<commit_msg>added clarifying note about use of foaf property<commit_after>include::../shared-settings.adoc[]
include::../header.adoc[]
:javadoc: http://docs.rdf4j.org/javadoc/latest?org/eclipse/rdf4j/
:examples: https://github.com/eclipse/rdf4j-doc/tree/master/examples/src/main/java/org/eclipse/rdf4j/examples/

:numbered!:
== How to use RDF and the RDF4J Framework

Getting started with RDF is not hard! In this tutorial, we go through the basics of what RDF is and how you can use it, and we show how you can use the Eclipse RDF4J framework to create, process, store, and query RDF data. We assume that you know a little about programming in Java, but no prior knowledge on RDF is assumed.

TIP: The code examples in this tutorial are available for download from the https://github.com/eclipse/rdf4j-doc/tree/master/examples[examples directory in the rdf4j-doc GitHub repository]. We encourage you to download these examples and play around with them. The easiest way to do this is to download the GitHub repository in your favorite Java IDE as an Apache Maven project. 

:numbered:
== Introducing RDF

The https://www.w3.org/TR/rdf11-primer/[Resource Description Framework (RDF)] is a standard (or more accurately, a "recommendation") formulated by the https://www.w3.org/[World Wide Web Consortium (W3C)]. The purpose of RDF is to provide a framework for expressing information about resources in a machine-processable, interoperable fashion.

A _resource_ can be anything that we can stick an identifier on: a web page, an image, but also more abstract/real-world things like you, me, the concept of "world peace", the number 42, and that library book you never returned. 

RDF is intended for modeling information that needs to processed by applications, rather than just being shown to people. 

In this tutorial, we will be modeling information about artists . Let's start with a simple fact: "Picasso's first name is Pablo". In RDF, this could be expressed as follows:

image:rdf-graph-1.png[]

So what exactly are we looking at here? Well, we have a _resource_ "Picasso", denoted by an IRI (Internationalized _Resource Identifier_): `http://example.org/Picasso`. In RDF, resources have _properties_. Here we are using the `foaf:firstName` property to denote the relation between the resource "Picasso" and the value "Pablo". `foaf:firstName` is also an IRI, though to make things easier to read we use an abbreviated syntax, called _prefixed names_ (more about this later). Finally, the property value, "Pablo", is a _literal_ value: it is not represented using a resource identifier, but simply as a string of characters.

NOTE: the `foaf:firstName` property is part of the FOAF (Friend-of-a-Friend) vocabulary. This is an example of reusing an existing vocabuary to describe our own data. After all, if someone else already defined a property for describing people's first names, why not use it? More about this later.

As you may have noticed, we have depicted our fact about Picasso as a simple *graph*: two nodes, connected by an edge. It is very helpful to think about RDF models as graphs, and a lot of the tools we will be using to create and query RDF data make a lot more sense if you do.

In RDF, each fact is called a *statement*. Each statement consists of three parts (for this reason, it is also often called a _triple_):

* the _subject_ is the starting node of the statement, representing the resource that the fact is "about";
* the _predicate_ is the property that denotes the edge between two nodes;
* the _object_ is the end node of the statement, representing the resource or literal that is the _property value_.

Let's expand our example slightly: we don't just have a single statement about Picasso, we know another fact as well: "Picasso is an artist". We can extend our RDF model as follows:

image:rdf-graph-2.png[]

Notice how the second statement was added to our graph depiction by simply adding a second edge to an already existing node , labeled with the `rdf:type` property, and the value `ex:Artist`. As you continue to add new facts to your data model, nodes and edges continue to be added to the graph.

=== IRIs, namespaces, and prefixed names

IRIs are at the core of what makes RDF powerful. They provide a mechanism that allows global identification of any resource: no matter who authors a dataset or where that data is physically stored, if that data shares an identical IRI with another dataset you know that both datasets are talking about the same thing. 

In many RDF data sets, you will see IRIs that start with 'http://...'. This does not necessarily mean that you can open this link in your browser and get anything meaningful, though. Quite often, IRIs are merely used as unique identifiers, and not as actual addresses. Some RDF sources _do_ make sure that their IRIs can be looked up on the Web, and that you actually get back data (in RDF) that describes the resource identified by the IRI. This is known as a http://linkeddata.org/[Linked Data] architecture. The ins and outs of Linked Data are beyond the scope of this tutorial, but it's worth exploring once you understand the basics of RDF.

You will often see IRIs in abbreviated form whenever you encounter examples of RDF data: `<prefix>:<name>` This abbreviated form, known as "prefixed names", has no impact on the meaning of the data, but it makes it easier for people to read the data. 

Prefixed names work by defining a _prefix_ that is a replacement for a _namespace_. A namespace is the first part of an IRI that is shared by several resources. For example, the IRIs `http://example.org/Picasso`, `http://example.org/Rodin`, and `http://example.org/Rembrandt` all share the the namespace `http://example.org/`. By defining a new prefix `ex` as the abbreviation for this namespace, we can use the string `ex:Picasso` instead of its full IRI.
{'fraction_non_alphanumeric': 0.060792409733813585, 'fraction_numerical': 0.002986910304840552, 'mean_word_length': 4.426120114394662, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6583327', 'n_tokens_mistral': 3011, 'n_tokens_neox': 2867, 'n_words': 1759}