A semantic network represents knowledge as a web of connected concepts, so an AI system can look at how things relate to each other, not just what they are on their own.
What Is a Semantic Network?
A semantic network is a graph-based way to represent knowledge. Concepts are drawn as nodes, and the relationships between them are drawn as labeled links. Following the links lets a system answer questions and infer things that were never stated directly.
Nodes and Relationships
Every semantic network is built from just two building blocks.
- Nodes — the concepts or objects, like Car or Vehicle.
- Links (edges) — labeled relationships between two nodes, such as is-a, has-part, has-property, or capable-of.
The most common link is is-a, since it lets a node inherit whatever is true of the node it points to.
Example Semantic Network
Here's a small semantic network about vehicles, using is-a, has-part, and has-property links.
Example: Building and Querying a Network
edges = [
("Car", "is-a", "Vehicle"),
("Truck", "is-a", "Vehicle"),
("Vehicle", "has-property", "can-move"),
("Car", "has-part", "Engine"),
("Car", "has-part", "Wheel"),
("Engine", "has-property", "burns-fuel"),
("ElectricCar","is-a", "Car"),
("ElectricCar","has-property","zero-emissions"),
]
def relationships_of(node):
return [(rel, obj) for subj, rel, obj in edges if subj == node]
def all_ancestors(node):
ancestors = []
current = node
while True:
parent = next((obj for subj, rel, obj in edges if subj == current and rel == "is-a"), None)
if not parent:
break
ancestors.append(parent)
current = parent
return ancestors
print("Relationships of 'Car':", relationships_of("Car"))
print("Relationships of 'ElectricCar':", relationships_of("ElectricCar"))
print("'ElectricCar' is-a chain:", all_ancestors("ElectricCar"))Output
Relationships of 'Car': [('is-a', 'Vehicle'), ('has-part', 'Engine'), ('has-part', 'Wheel')]
Relationships of 'ElectricCar': [('is-a', 'Car'), ('has-property', 'zero-emissions')]
'ElectricCar' is-a chain: ['Car', 'Vehicle']Explanation:
ElectricCar only directly states one property (zero-emissions), but its is-a chain shows it's also a Car and a Vehicle — so it inherits has-part Engine and has-property can-move too, without those facts being repeated on ElectricCar itself.
Ontologies and Knowledge Graphs
Semantic networks scale into two related ideas once a domain gets bigger or more formal.
What Is an Ontology?
An ontology is a formal, agreed-upon set of concepts, categories, and relationships for a specific domain — it defines exactly what kinds of nodes and links are allowed, so different systems can share knowledge without ambiguity.
Knowledge Graphs
A knowledge graph is a semantic network built at a much larger scale, often powered by an ontology's rules, and often pulling in real-world data. Search engines use knowledge graphs to connect facts about people, places, and things across the web.
Quick Comparison
| Concept | Scale | Formality |
|---|---|---|
| Semantic Network | Small, single domain | Informal, flexible |
| Ontology | A defined domain's vocabulary | Formal, strict rules |
| Knowledge Graph | Large, often web-scale | Follows an ontology's structure |