### RDF Basics - **Definition:** Resource Description Framework (RDF) is a standard for describing information about resources on the web. - **Triples:** The fundamental unit in RDF is a "triple" (Subject, Predicate, Object). - Subject: The resource being described (e.g., "Dublin Core"). - Predicate: The property or characteristic (e.g., "has creator"). - Object: The value of the property (e.g., "Stuart Weibel"). - **URNs/URIs:** Resources and predicates are typically identified by Uniform Resource Identifiers (URIs) or Internationalized Resource Identifiers (IRIs). - **Example (Turtle Syntax):** ```turtle @prefix ex: . @prefix foaf: . ex:person1 foaf:name "Alice" ; foaf:age 30 ; ex:hasFriend ex:person2 . ``` ### RDF Schema (RDFS) - **Definition:** RDFS provides a vocabulary for describing properties and classes of RDF resources. It's a layer on top of RDF. - **Key Concepts:** - `rdfs:Class`: Defines a class of resources. - `rdfs:Property`: Defines a property. - `rdfs:subClassOf`: Indicates that one class is a subclass of another. - `rdfs:subPropertyOf`: Indicates that one property is a subproperty of another. - `rdfs:domain`: Specifies the class of the subject of a property. - `rdfs:range`: Specifies the class of the object of a property. - **Example:** ```turtle @prefix rdfs: . @prefix ex: . ex:Person rdfs:Class . ex:Student rdfs:subClassOf ex:Person . ex:hasEmail rdfs:Property ; rdfs:domain ex:Person ; rdfs:range rdfs:Literal . ``` ### OWL Ontology - **Definition:** Web Ontology Language (OWL) is a more expressive language than RDFS for defining ontologies. It allows for richer semantics and reasoning. - **Levels:** OWL comes in three increasingly expressive sublanguages: - **OWL Lite:** Simple class hierarchies and constraints. - **OWL DL (Description Logic):** Maximizes expressiveness while retaining computational completeness and decidability. Most commonly used. - **OWL Full:** Maximum expressiveness, but loses computational guarantees. - **Key Concepts:** - `owl:Class`, `owl:ObjectProperty`, `owl:DatatypeProperty` - **Class Axioms:** `owl:equivalentClass`, `owl:disjointWith`, `owl:intersectionOf`, `owl:unionOf`, `owl:complementOf`. - **Property Axioms:** `owl:inverseOf`, `owl:TransitiveProperty`, `owl:SymmetricProperty`, `owl:FunctionalProperty`, `owl:InverseFunctionalProperty`. - **Cardinality Restrictions:** `owl:minCardinality`, `owl:maxCardinality`, `owl:cardinality`. - **Example:** ```turtle @prefix owl: . @prefix ex: . ex:Human owl:Class . ex:Parent owl:Class ; owl:equivalentClass [ owl:intersectionOf ( ex:Human [ a owl:Restriction ; owl:onProperty ex:hasChild ; owl:minCardinality "1"^^xsd:nonNegativeInteger ] ) ] . ``` ### Knowledge Graphs - **Definition:** A Knowledge Graph (KG) is a structured representation of information that describes real-world entities and their relationships, typically using an RDF-like graph model. - **Components:** - **Nodes (Entities):** Represent real-world objects, concepts, or events (e.g., "Albert Einstein", "E=mc^2"). - **Edges (Relationships):** Represent the connections or predicates between entities (e.g., "was born in", "discovered"). - **Characteristics:** - **Semantic:** Uses ontologies (RDFS/OWL) to define schema and relationships, providing meaning to data. - **Interconnected:** Data is linked through relationships, forming a graph structure. - **Contextual:** Provides context for data, enabling better understanding and reasoning. - **Queryable:** Can be queried using languages like SPARQL. - **Benefits:** - Enhanced search and recommendation systems. - Improved data integration and interoperability. - Facilitates AI and machine learning applications by providing structured, contextual data. - Supports complex reasoning and inference. - **Popular KGs:** DBpedia, Wikidata, Google's Knowledge Graph. ### SPARQL Query Language - **Definition:** SPARQL (SPARQL Protocol and RDF Query Language) is a W3C standard query language for RDF graphs. - **Basic Structure:** - `SELECT`: Specifies the variables to be returned. - `WHERE`: Specifies the graph pattern to match. - **Example:** Find names of all people aged 30. ```sparql PREFIX foaf: PREFIX ex: SELECT ?name WHERE { ?person foaf:age 30 ; foaf:name ?name . } ``` - **Other Keywords:** - `FILTER`: Constrains results based on conditions. - `OPTIONAL`: Matches patterns if possible, but doesn't fail if not found. - `UNION`: Combines results from multiple graph patterns. - `ORDER BY`, `LIMIT`, `OFFSET`: For result manipulation.