Semantic Web Ontology Lec 6 Week 3
Semantic Web Ontology Lec 6 Week 3
Spring Semester
Introduction to the
Semantic Web
Dr. Yasmine Mahmoud
Turtle
• foaf (Friend of a Friend)
• foaf is a popular namespace in the RDF world,
used to describe people and the relationships
between them.
• The namespace for foaf is:
http://xmlns.com/foaf/0.1/.
• foaf provides a set of properties and types
ready to represent data about people, such as
name, friendships, photos, and more.
2
Turtle
Examples of foaf properties:
• foaf:Person: A type that indicates that the
resource is a person.
• foaf:name: A property that specifies the name
of the person.
• foaf:knows: A property that specifies that a
person knows another person.
3
Turtle
• Example 7: Using Multiple Prefixes
4
Turtle
• a is a shorthand for rdf:type,
o so ex:John a foaf:Person means John is of
type foaf:Person.
• foaf:name and foaf:knows are properties from
the FOAF (Friend of a Friend) vocabulary.
5
Turtle
• Example 8: Typed Literals and Language
Tags
6
Turtle
• "30"^^xsd:integer is a typed literal for age.
• "John Doe"@en and "A software
engineer"@en are language-tagged literals in
English.
7
Turtle
• Reading (as a human) RDF in Turtle format is
much easier as you can define prefixes at the
beginning of the .ttl file, shortening each triple.
• Another feature of turtle is that multiple triples
with the same subject are grouped into blocks
(so the URI for Bob Marley for example is not
repeatedly listed), for example:
8
Turtle
9
Turtle
• This represents the exact same knowledge
graph as the previous N-Triples.
• In the top section, prefixes are defined so that
the long repeated sections of the URIs can be
written in their short form.
• For example the line.
• @prefix foaf: <http://xmlns.com/foaf/0.1/> .
10
Turtle
• lets the string foaf represent
http://xmlns.com/foaf/0.1/.
• This allows the subject
<http://xmlns.com/foaf/0.1/Person> to be
shortened to foaf:Person.
11
Turtle
• One unique shortening is the predicate
<http://www.w3.org/1999/02/22-rdf-syntax-
ns#type> which is so common, it is
represented simply with the letter a.
• Hence the N-Triple.
<http://dbpedia.org/resource/Bob_Marley>
<http://www.w3.org/1999/02/22-rdf-syntax-
ns#type>
<http://xmlns.com/foaf/0.1/Person> .
12
Turtle
• It can be shortened in Turtle to:
dbr:Bob_Marley a foaf:Person
which is a lot clearer.
13
Turtle
• You can see that the data about Bob Marley
and Jamaica is separated into separate blocks.
• This grouping along with defined prefixes,
makes Turtle format a lot easier to understand
than N-Triples.
• If you notice, related information to the subject
is separated with a semi-colon and finished
with a full-stop and a newline to indicate a
new subject.
14
What is JSON?
• JSON (JavaScript Object Notation):
o It is a lightweight data format used to store and
exchange data.
o It’s easy for humans to read and write, and easy for
machines to parse and generate.
o JSON is widely used in web applications and APIs.
15
Structure of JSON:
• JSON data is written as key-value pairs.
• Keys are always strings, and values can be:
o Strings (e.g., "name": "Ahmed")
o Numbers (e.g., "age": 30)
o Booleans (e.g., "isStudent": true)
o Arrays (e.g., "hobbies": ["reading", "swimming"])
o Objects (e.g., "address": { "city": "New York",
"zip": "10001" })
16
Example of JSON:
17
What is JSON-LD?
• JSON-LD (JSON for Linked Data):
o It is a way to represent RDF (Resource Description
Framework) data in JSON format.
o It allows you to embed structured data in JSON.
18
Structure of JSON-LD:
• Context (@context): Defines the vocabulary
and mappings for the JSON data.
• Types (@type): Specifies the type of a
resource (e.g., Person, Place).
• IDs (@id): Provides a unique identifier for a
resource.
• Language Support: Allows you to specify the
language of text values (e.g., "name": {
"@value": "John", "@language": "en" }).
19
Structure of JSON-LD:
20
Structure of JSON-LD:
• @context: Defines the vocabulary:
o name maps to http://xmlns.com/foaf/0.1/name.
o age maps to http://example.org/age.
o Person maps to http://xmlns.com/foaf/0.1/Person.
• @id: The unique identifier for John
is http://example.org/John.
• @type: John is of type Person.
• name and age are properties of John.
21