What is the Semantic Web?
The Semantic Web is an extension of the World Wide Web that allows data to be shared and reused across applications, enterprises, and communities. It uses standardized formats (RDF, OWL) to represent knowledge in a machine-readable way.Key Benefits for This System
Natural Language Queries
Search shipments using plain language instead of complex database queries
Relationship Inference
Automatically infer relationships between clients, shipments, and branches
Flexible Schema
Add new properties without breaking existing queries or data
Semantic Reasoning
Query by meaning, not just keywords (e.g., “heavy packages” understands weight > 20kg)
RDF Triples: The Foundation
RDF (Resource Description Framework) represents data as triples: Subject - Predicate - ObjectExample from Our System
When you create a shipment, it’s stored as RDF triples:Breaking Down a Triple
Each line is a triple:| Subject | Predicate | Object |
|---|---|---|
<...cliente/12345678> | enc:tieneNombre | "Juan Pérez" |
<...cliente/12345678> | enc:realizaEnvio | <...envio/ENV-123...> |
<...envio/ENV-123...> | enc:tieneEstado | "PENDIENTE" |
<...envio/ENV-123...> | enc:tienePesoKg | "2.5"^^xsd:decimal |
URIs uniquely identify resources globally. Literals are values (strings, numbers, dates).
OWL Ontologies: Defining Structure
OWL (Web Ontology Language) extends RDF to define vocabularies and relationships with formal semantics. Our system usesencomiendas.ttl ontology (svc-web-semantica/src/main/resources/encomiendas.ttl) to define:
1. Classes
Classes represent types of things:2. Subclasses (Inheritance)
Specialized types inherit from parent classes:Future enhancement: Automatically classify shipments as
EnvioPesado when weight > 20kg using reasoning.3. Object Properties (Relationships)
Connect resources to other resources:- If
Cliente1 realizaEnvio Envio1 - Then automatically:
Envio1 esRealizadoPor Cliente1
4. Datatype Properties (Attributes)
Connect resources to literal values:owl:FunctionalProperty means a resource can have at most one value for this property (e.g., one DNI per client).5. Disjoint Classes
Enforce that classes don’t overlap:SPARQL: Querying the Graph
SPARQL is the query language for RDF data, similar to SQL but for graphs.Example: Find Pending Shipments
Example: Weight Range Query
Apache Jena TDB: Storage Engine
Apache Jena TDB is a native RDF database used in this system.Why TDB?
- High Performance: Optimized for SPARQL queries
- File-Based: No separate database server needed
- ACID Transactions: Data integrity guaranteed
- Scalable: Handles millions of triples
Storage Location
tdb_data/ directory contains binary-encoded RDF triples optimized for fast querying.
Natural Language to SPARQL Translation
TheBusquedaSemanticaService (svc-web-semantica/src/main/java/org/jchilon3mas/springcloud/svc/web/semantica/svc_web_semantica/services/BusquedaSemanticaService.java:18) translates natural language to SPARQL:
Example: “envios pendientes entre 2 y 5 kg”
Step 1: Extract parameters- Estado:
PENDIENTE - Peso min:
2 - Peso max:
5
Why Use Semantic Web Here?
Traditional SQL Approach
- Rigid schema
- Complex JOINs for relationships
- Difficult to add new query patterns
- No natural language support
Semantic Web Approach
Flexible Querying
Query by meaning, not table structure. Ask “heavy packages” without knowing weight thresholds.
Relationship Navigation
Follow relationships naturally: “clients who sent fragile packages to Lima”
Schema Evolution
Add new properties (e.g.,
enc:esFragil) without altering database schema.Reasoning Potential
Future: Infer
EnvioPesado automatically, recommend routes, detect anomalies.Namespaces and Prefixes
Namespaces prevent naming conflicts:- enc: Our custom ontology
- owl: OWL vocabulary
- rdf/rdfs: RDF core vocabulary
- xsd: XML Schema datatypes (string, decimal, date)
Data Types in RDF
Common XSD datatypes used:| Type | Example | Usage |
|---|---|---|
xsd:string | "Juan Pérez" | Names, descriptions |
xsd:decimal | "2.5"^^xsd:decimal | Weight, precise numbers |
xsd:dateTime | "2026-03-09T10:30:00" | Timestamps |
xsd:integer | "10"^^xsd:integer | Counts |
Limitations and Trade-offs
Current Implementation
| Aspect | Current State | Improvement Opportunity |
|---|---|---|
| Reasoning | Not enabled | Add OWL reasoner for automatic classification |
| Performance | File-based TDB | Use Jena Fuseki for distributed queries |
| Validation | Manual in code | Use SHACL shapes for data validation |
| Federation | Single graph | Query multiple remote endpoints |
When NOT to Use Semantic Web
- Simple CRUD applications with fixed schemas
- High-frequency transactional writes (stick to SQL for writes, sync to RDF for reads)
- When natural language search isn’t needed
Next Steps
Explore the Ontology
Deep dive into the encomiendas.ttl structure
Write SPARQL Queries
Learn to write custom SPARQL queries
Semantic Search Guide
Master natural language querying
Architecture Overview
Understand how it all fits together