Notation3
Notation3 (N3) is a human-readable syntax and logic language for the Semantic Web, designed as a superset of RDF that offers a compact alternative to RDF/XML while incorporating advanced features such as logical implications, rules, and quantification to enable reasoning over data.[1] Developed primarily by Tim Berners-Lee starting around 2000, N3 emerged from efforts within the W3C RDF and Semantic Web communities to create a more expressive and practical format for representing and processing knowledge on the web.[2] Its core purpose is to facilitate declarative programming and decision-making in open web environments by extending RDF's triple-based model with constructs like graph terms for metadata attachment, lists as first-class objects, and built-in functions for accessing online resources.[3] Key subsets of N3 include N-Triples for simple RDF serialization, Turtle for abbreviated RDF graphs, and full N3 for logic and rules, allowing progressive adoption from basic data representation to complex inference systems.[1] The language supports directives like@base and @prefix for namespace management, blank nodes for anonymous resources, and scoped negation-as-failure for controlled reasoning, all encoded in UTF-8.[3] Unlike RDF/XML, which prioritizes machine readability, N3 emphasizes symmetry and readability, making it suitable for both authoring and debugging semantic data.[2]
Historically, N3 was formalized in a 2008 W3C Team Submission and has since been maintained by the N3 Community Group, with updates as recent as 2023 incorporating refinements like inverted property syntax (<-) and removal of obsolete keywords.[3] While not an official W3C standard, its logical foundation—detailed in publications like the 2008 Theory and Practice of Logic Programming paper—underpins tools for RDF processing, provenance tracking, and web-scale inference.[2] N3's extensions beyond RDF enable applications in knowledge graphs, rule-based systems, and decentralized web architectures, influencing modern Semantic Web implementations.[1]
Overview
Definition and Purpose
Notation3 (N3) is a compact, human-readable syntax for expressing RDF graphs, triples, and logical rules, serving as a superset of the RDF data model. It provides a textual alternative to the more verbose RDF/XML serialization, enabling the representation of knowledge in a format that is both machine-processable and accessible to humans.[1] The primary purpose of N3 is to simplify RDF authoring while enabling rule-based reasoning and supporting decentralized Semantic Web applications. By extending RDF's capabilities, N3 allows for the integration of data assertions with logical inferences, facilitating sharable knowledge that can be reused across diverse contexts without altering established facts.[4][1] Key features of N3 include support for variables, implications, and quantifiers, which go beyond basic RDF triples to enhance expressiveness in knowledge representation. These elements enable the formulation of complex logical statements directly in plain text.[1] This notation was motivated by Tim Berners-Lee's goal of creating a unified plain-text format that combines data and logic, allowing for efficient sharing and reasoning over Semantic Web resources.[4]Relationship to RDF and Semantic Web
Notation3 (N3) serves as a serialization format for RDF, extending the RDF data model to include logical formulas, variables, implications, and functional predicates, which go beyond the basic triple structure of plain RDF.[1] While RDF is primarily designed for describing data through subject-predicate-object triples, N3 allows these triples to be embedded within broader logical expressions, enabling more expressive representations within the Semantic Web ecosystem.[5] N3 maintains strong compatibility with RDF standards, as N3 documents can be parsed directly into RDF graphs, with subsets such as N-Triples and Turtle ensuring adherence to RDF 1.1 specifications.[1] However, N3 introduces extensions like existential quantification through variables, universal scoping via implications, and implication operators (e.g.,=>), which are not native to core RDF and require additional logical layers for interpretation.[6][3] This interoperability allows N3 to function as a bridge, where RDF-compliant portions are seamlessly integrated into Semantic Web applications, while the extras support advanced reasoning without breaking RDF parsers.[1]
N3 is actively maintained by the W3C N3 Community Group, with the latest specification refinements published in 2023, enhancing compatibility and readability.[3]
In the broader Semantic Web framework, N3 plays a key role in enabling rule-based inference through N3 Rules, which leverage RDF's graph model for declarative logic and forward-chaining reasoning, effectively connecting data description in RDF with the kind of ontological reasoning found in OWL.[6] This extension facilitates the creation of knowledge bases that combine factual assertions with derivable conclusions, supporting applications in distributed reasoning across the web.[5] N3 thus bridges the gap between RDF's data-centric approach and the logical expressivity needed for Semantic Web inference engines.[5]
Compared to RDF/XML, another standard RDF serialization, N3 offers a more concise and human-readable syntax akin to Turtle, using shorthands, prefixes, and linear notation to reduce verbosity while preserving full RDF semantics.[1] This brevity makes N3 particularly suitable for authoring and debugging Semantic Web content, contrasting with RDF/XML's XML-based structure that prioritizes machine processability over readability.[1]
History
Origins and Development
Notation3 (N3) was created by Tim Berners-Lee in 2000 as part of the World Wide Web Consortium's (W3C) initiatives to develop the Semantic Web. Initially intended for internal use at the W3C, it emerged from experimental efforts to create a compact, readable syntax that extended the Resource Description Framework (RDF) while incorporating logical constructs for reasoning over web data. This foundational work addressed the need for a format that could handle both assertions and implications in a way that was more accessible than RDF's XML-based syntax.[1] The design of N3 drew inspiration from RDF's graph-based model for representing structured data and Prolog's logic programming paradigm for rule-based inference. Berners-Lee aimed to unify these approaches into a single, human-readable language that allowed seamless expression of data, variables, and logical rules, thereby enabling developers to prototype Semantic Web applications more intuitively. This merger was particularly suited for the open, distributed nature of the web, where combining declarative knowledge with procedural logic could support automated inference without requiring complex tooling.[7] Early public exposure of N3 occurred through Berners-Lee's writings on the Semantic Web in 2000 and 2001, including a tutorial that demonstrated its practical application. The first implementation materialized as CWM (Closed World Machine), a Python-based RDF inference engine developed by Berners-Lee starting in 2000, which processed N3 syntax for querying, transforming, and reasoning over RDF data. CWM's capabilities, such as forward-chaining inference, marked it as the inaugural tool for N3, facilitating hands-on experimentation within the W3C community.[7][8] Principal contributors to N3's inception included Tim Berners-Lee, who led the conceptual and technical design, and Dan Connolly, who collaborated on CWM's implementation and early refinements. Additional input from the broader W3C team, including members like Sandro Hawke, helped shape its initial features through iterative testing and feedback in Semantic Web working groups.[1]Evolution and Standards
Following its initial development in the early 2000s, Notation3 underwent significant refinement between 2004 and 2008 through a series of W3C notes and submissions that clarified its syntax and logical extensions.[9] In 2008, Tim Berners-Lee and Dan Connolly published a key W3C Team Submission detailing Notation3 as a superset of RDF, with formal semantics outlined in the accompanying paper "N3Logic: A logical framework for the World Wide Web," which provided a model-theoretic foundation for its rules and nested graphs.[10][11] This period also saw the release of an informal primer by Berners-Lee, emphasizing practical use of Notation3 for RDF and Semantic Web applications.[12] Notation3's syntax integrates closely with Turtle, the compact RDF serialization standardized as part of RDF 1.1 in 2014, positioning Notation3 as a superset that incorporates all valid Turtle constructs while adding support for formulas, implications, and variables.[13][14] However, Notation3's rule-based extensions, such as implications and quantified expressions, were not included in the RDF 1.1 recommendations, limiting their formal status within the broader RDF ecosystem. As of 2023, Notation3 continues to evolve through community-driven efforts, including updates to its specification by the W3C Notation3 Community Group, which published a draft report refining compatibility with Turtle and addressing edge cases in logical constructs.[3] Projects like RDFLib in Python have incorporated Notation3 parsing and serialization, enabling extensions for rule inference in open-source Semantic Web tools, though these remain implementation-specific. Despite these advancements, Notation3 lacks full W3C Recommendation status, functioning instead as a Community Group draft.[14] This absence of official standardization has resulted in challenges, including variant implementations across parsers that may differ in handling advanced features like nested formulas or blank node scoping, potentially affecting interoperability in distributed Semantic Web applications.[14][15]Syntax
Core Elements
Notation3's core syntax revolves around the representation of RDF triples, which form the foundational units for expressing relationships between resources. A triple consists of a subject, predicate, and object, denoted in shorthand as<subject> <predicate> <object> ., where angle brackets enclose URIs and the statement is terminated by a period. This structure allows for concise serialization of RDF graphs, with predicates shared across multiple objects using semicolons (e.g., <subject> <pred1> <obj1> ; <pred2> <obj2> .) and objects sharing the same subject and predicate using commas (e.g., <subject> <pred> <obj1> , <obj2> .). Inverted properties can be expressed using <- to reverse the direction (e.g., ?x <- :hasFather ?y . equivalent to ?y :hasFather ?x .).[1][16][17]
URIs in Notation3 are referenced either fully within angle brackets (e.g., <http://example.org/resource>) or via qualified names (qnames) defined through prefix declarations. Prefixes are introduced using the @prefix directive, such as @prefix ex: <http://example.org/> ., enabling abbreviated forms like ex:resource for the full URI. Literals represent values like strings or numbers, enclosed in double quotes (e.g., "value"), with optional language tags (e.g., "value"@en) or explicit datatypes using the ^^ operator (e.g., "42"^^<http://www.w3.org/2001/XMLSchema#integer>), defaulting to xsd:string otherwise. Multi-line strings are supported with triple quotes (e.g., """multi\nline"""), and escape sequences like \n or \u0041 handle special characters.[1][18]
Lists and collections provide ways to group resources without explicit URIs. Square brackets [] denote anonymous collections or blank nodes with attached properties, allowing inline definition of structured data (e.g., [] <property> <value> .), while parentheses () represent ordered sequences interpreted as RDF lists via rdf:first and rdf:rest chains, such as ( <item1> <item2> ) for a sequence terminating in rdf:nil. These constructs facilitate compact representation of aggregates in RDF data.[1][19]
Blank nodes serve as existential variables or temporary identifiers for resources without a global URI, using the syntax _:label (e.g., _:alice) for named blanks within a document or [] for unlabeled ones. They enable the description of interconnected entities without committing to specific identifiers, ensuring uniqueness scoped to the document or formula. Notation3's handling of these elements maintains full compatibility with RDF's triple model.[1][20]
Logical Constructs and Keywords
Notation3 (N3) extends RDF syntax with logical constructs that enable expressive rule-based reasoning, incorporating variables for pattern matching, implication symbols, and directives for namespace management and modularization. These elements allow N3 documents to represent not just data but also logical relationships and inferences in a human-readable format.[14][1] Variables in N3 are denoted by names prefixed with?, serving as placeholders for matching arbitrary resources during pattern matching in rules. For instance, ?x can bind to any IRI or literal that fits the context of a triple or formula. This notation facilitates generalization, where a variable implicitly assumes universal quantification, enabling rules to apply broadly across datasets. Blank nodes (e.g., _:z) provide existential quantification for asserting existence without naming.[21][4]
Implications are expressed using => for unidirectional logical implication (equivalent to log:implies) and =>> for bidirectional equivalence (equivalent to log:equivalentTo). The => operator connects an antecedent formula to a consequent, as in { ?x a :SuperHero } => { ?x a :Imaginary }, triggering inference when the antecedent matches. Similarly, =>> ensures mutual entailment, providing a concise way to define symmetric rules.[22]
Additional keywords support document structure and modularity: @prefix binds a shorthand prefix to a full namespace IRI, like @prefix : <http://example.org/> ., simplifying IRI references; @base establishes a default base URI for relative paths, such as @base <http://example.org/> .; and log:includes enables importing or checking inclusion of external formulas, as in { :doc log:includes { :fact a :True. } }. These directives must appear at the document's start and are essential for maintaining readability in complex N3 files.[23][4][24]
Formulas and Rules
In Notation3, formulas are constructed using curly braces to enclose a set of triple patterns, creating scoped statements that represent graph terms or conjunctions of assertions. This syntax allows for the grouping of related RDF triples within a delimited context, such as{ subject [predicate](/page/Predicate) object . anotherSubject anotherPredicate anotherObject . }, where the period separates individual statements within the formula.[25]
Rules in Notation3 extend this formula structure to express implications, following the form { antecedent } => { consequent } ., where the antecedent is a formula containing premises and the consequent is a formula specifying derived triples. The implication operator => serves as syntactic shorthand for the log:implies predicate from the N3 logical namespace, enabling the definition of conditional relationships between sets of statements.[22]
Rule chaining occurs through multiple implications where the consequent of one rule can serve as the antecedent for another, with variables facilitating binding across clauses to propagate information consistently. For instance, universal variables (prefixed with ?) in the antecedent bind to resources that instantiate the consequent, and these bindings carry over in chained rules, allowing sequential derivations without explicit redefinition.[22]
Embedding supports nesting formulas within triples, permitting a formula to act as the subject, predicate, or object of an outer statement, as in outerSubject outerPredicate { nestedFormula } .. This hierarchical construction enables complex scoped expressions, such as metadata attached to inner graphs, while maintaining the overall document's readability and logical structure.[25]
Semantics
Logical Interpretation
Notation3 (N3) can be viewed as a fragment of first-order logic (FOL), where RDF triples serve as atomic formulas represented by a three-place predicate such asholds(subject, predicate, object), enabling the expression of basic assertions in a logical form.[2] Implications in N3 are formulated using the log:implies predicate, which corresponds to Horn clauses by connecting an antecedent graph (body) to a consequent graph (head), restricting expressivity to monotonic rules without general negation to avoid paradoxes.[2] This design limits N3 to a decidable subset of FOL, supporting universal and existential quantification via @forAll and @forSome constructs, while embedding variables and nested graphs within RDF structures.[26]
In terms of model theory, RDF graphs form the foundational interpretations in N3, where a graph is a set of triples over a vocabulary, and an interpretation maps terms to a domain with extensions defining truth for predicates. N3 extends this by incorporating rules and quantified graphs, leading to Herbrand-like models derived through inference steps such as universal instantiation and existential generalization, ensuring entailment preserves truth across models.[2] The semantics treat N3 documents as sets of formulae, with entailment defined model-theoretically via mappings that satisfy all triples and implications in the domain.[26]
Unlike OWL's global open world assumption (OWA), which treats absence of information as inconclusive, N3 employs scoped negation as failure through the log:notIncludes predicate, enabling local closed world assumption (CWA) within specific formulae or documents without introducing global non-monotonicity.[4] This scoped approach allows rules to infer negation based on the absence of evidence in a delimited context, contrasting OWL's monotonic OWA by permitting practical defaults in bounded reasoning scenarios.[27]
Basic subsets of N3, consisting solely of RDF triples without rules or negation, align directly with RDF entailment regimes as defined in the RDF Semantics specification, ensuring that N3 graphs entail the same conclusions as corresponding RDF graphs under simple, RDF, or RDFS interpretations. This compatibility preserves the foundational semantics of RDF while allowing N3 to extend it logically without conflict.[2]
Inference Mechanisms
Notation3 (N3) inference mechanisms leverage its rule-based syntax to perform automated reasoning over RDF graphs, deriving new triples and answering queries by applying logical implications. Rules in N3, expressed using the implication operator=> (equivalent to log:implies), allow for the generation of conclusions from premises, enabling the expansion of knowledge bases through deductive processes. This reasoning capability extends RDF's declarative nature by incorporating Horn-like rules with variables for pattern matching and generalization.[14]
Forward chaining in N3 operates in a bottom-up manner, starting from existing facts in the knowledge graph and iteratively applying rules to infer and add new triples until a fixed point is reached, where no further inferences are possible. For instance, a rule such as { :weather a :Raining. } => { :weather a :Cloudy. } would trigger upon detecting a raining condition, deriving the cloudy state as a new assertion. This mechanism is particularly efficient for materializing entailments in large datasets, as implemented in reasoners like the original CWM processor developed by Tim Berners-Lee.[22]
In contrast, backward chaining employs a top-down approach, beginning with a query or goal and working backwards to verify supporting premises through rule unification, akin to resolution in logic programming languages like Prolog. N3 supports this via the inverse implication <= (equivalent to log:impliedBy), as in { ?slinger :locomotion :flying. } <= { ?slinger a :WebSlinger. }, which resolves whether a subject is a web slinger by checking for flying locomotion. This method is goal-directed and avoids unnecessary derivations, making it suitable for query answering in interactive systems.[22]
N3 enhances pure logical inference with built-in predicates that provide procedural attachments for computations beyond simple triple derivation, such as arithmetic and string operations. Examples include math:sum for adding numbers, as in (1 2) math:sum ?result. yielding 3, and string:concat for joining strings, enabling dynamic value generation during rule application. These builtins, defined in the N3 specification, integrate external functions seamlessly into the reasoning process without requiring external code.[28]
Entailment regimes in N3 encompass simple entailment (basic RDF triple matching), RDFS entailment (incorporating schema inferences like subclass relationships), and custom regimes driven by N3 rules for comprehensive closure. The predicate log:conclusion facilitates computing the deductive closure of a graph by applying all relevant rules, yielding a complete set of entailed statements; for example, { :g log:conclusion ?closure. } produces the inferred graph from :g. This supports layered reasoning, where RDFS provides lightweight ontology support, while N3 rules enable expressive, user-defined inferences.[29]
Implementations and Tools
Parsers and Processors
The first dedicated processor for Notation3 (N3) was CWM, developed by Tim Berners-Lee starting in 2000 as part of the W3C's Semantic Web efforts.[30] Written in Python, CWM functions as a forward-chaining reasoner that parses N3 syntax, applies rules for inference, and supports querying, transforming, and filtering RDF data expressed in N3 or RDF/XML formats.[30] It handles N3's logical constructs, such as implications and quantifiers, to derive new triples from input graphs, making it a foundational tool for early Semantic Web applications.[31] Another prominent N3 processor is EYE (formerly known as EulerSharp), an RDF rule engine that provides comprehensive support for N3 syntax and semantics.[32] Developed as an evolution of the original Euler proof engine, EYE performs both forward and backward chaining using N3's implication operators (=> for forward and <= for backward), enabling efficient reasoning over large RDF graphs.[32] It interoperates with other N3 tools like CWM and implements the Euler Abstract Machine for path-based proof generation, ensuring non-repetitive inference steps inspired by graph theory.[32]
For programmatic parsing of N3 in Python, the Notation3.py library offers a lightweight solution to convert N3 documents into RDF graphs.[33] Originating from the W3C's Semantic Web Authoring and Processing (SWAP) toolkit, this module implements a recursive-descent parser that handles N3's core elements, including prefixes, lists, and formulas, while producing N-Triples output for further processing.[33] It serves as a building block for integrating N3 parsing into custom applications without full reasoning capabilities.
Validation of N3 syntax, particularly its compatibility with the RDF subset (akin to Turtle), is facilitated by tools like rapper from the Raptor RDF parser toolkit.[34] Rapper parses input files in Turtle format (which covers much of N3's RDF-compatible syntax) and emits validated triples in formats such as N-Triples, allowing users to check for syntactic errors, count statements, and ensure conformance to RDF standards.[34] By specifying the Turtle input mode, it effectively verifies N3 documents that adhere to Turtle constraints, ignoring non-RDF extensions like rules during basic checks.[34]
Integrated Systems and Libraries
RDFLib, a popular Python library for working with RDF, integrates Notation3 parsing to enable graph manipulation. It supports loading and saving RDF data in N3 format, treating N3 as a superset of Turtle while handling additional features like quoted graphs for formulae and implications. This integration allows developers to process N3 documents directly into RDF graphs. For inference and rule execution, integration with external reasoners such as EYE or CWM is required. The library's store API persists N3 terms such as variables and blank nodes.[35] Apache Jena, a Java framework for Semantic Web applications, provides partial support for Notation3 via extensions to its Turtle parser and rule engines. While Jena serializes RDF graphs to N3 format, it primarily interprets N3 as synonymous with Turtle, limiting full handling of N3-specific constructs like implications and builtins unless augmented by external tools.[36] For advanced N3 reasoning, projects like jen3 build on Jena to offer comprehensive Notation3 capabilities, including rule processing within larger RDF ecosystems.[37] In JavaScript, the N3.js library provides parsing, serialization, and basic manipulation of N3 documents, supporting web-based applications. It handles N3's RDF subset and extensions like prefixes and lists, with ongoing development as of 2025.[24] Notation3 finds application in SPARQL environments for constructing service descriptions and rule datasets, leveraging its RDF compatibility to represent query patterns and inferences. SPARQL endpoints can output RDF results in N3 syntax, enabling seamless integration with rule-based extensions, as seen in translations like SiN3, which converts SPARQL CONSTRUCT queries into N3 rules for scalable inferencing.[38] This approach supports embedding N3 logic within SPARQL workflows to enhance data querying and transformation. In decentralized applications, such as the Solid project, Notation3 is utilized for defining access rules and performing reasoning over linked data in personal pods. Solid implementations employ N3 reasoners to crawl and infer from RDF resources, enforcing authorization policies through rule-based traversal while respecting Web Access Control specifications.[39] This integration promotes privacy-preserving data sharing by allowing N3 formulae to dynamically evaluate access permissions across distributed graphs.Examples
Basic RDF Representation
Notation3 (N3) provides a compact and human-readable syntax for serializing RDF graphs, focusing on basic triples without invoking logical extensions. At its core, N3 represents RDF data through subject-predicate-object statements, using angle brackets for URIs, prefixes for shorthand, and periods to terminate statements. This structure allows straightforward expression of simple knowledge graphs, such as relationships between resources.[40] Prefix declarations in N3 use the@prefix directive to map a shorthand namespace to a full URI, reducing verbosity in triple notation. For instance, the declaration @prefix ex: <http://example.org/> . enables abbreviated references like ex:Alice instead of the full <http://example.org/Alice>. This feature streamlines authoring while preserving RDF's URI-based identifiers. Multiple prefixes can be declared sequentially, and the syntax supports case-insensitive variants like PREFIX.[41]
Basic triples in N3 follow the pattern subject predicate object ., where subjects and predicates are typically IRIs (in angle brackets or prefixed), and objects can be IRIs or literals. A simple example serializes a social relationship as:
This asserts that the resource@prefix ex: <http://example.org/> . ex:Alice ex:knows ex:Bob .@prefix ex: <http://example.org/> . ex:Alice ex:knows ex:Bob .
ex:Alice has the property ex:knows pointing to ex:Bob, forming a directed edge in the RDF graph. Additional triples can chain using semicolons for shared subjects (e.g., ex:Alice ex:knows ex:Bob ; ex:age 30 .) or commas for repeated predicates (e.g., ex:Alice ex:knows ex:Bob, ex:Charlie .).[40]
Literals in N3 serve as object values for properties, supporting strings, numbers, booleans, and datatyped values like dates. Plain strings appear in double quotes (e.g., ex:Alice ex:name "Alice Smith" .), while numbers are unquoted (e.g., ex:Bob ex:age 25 . for an integer). For precision, datatypes use the ^^ operator (e.g., ex:Event ex:startDate "2025-11-13"^^xsd:date .), and language-tagged strings use @ (e.g., ex:Book ex:title "Hello"@en .). These directly correspond to RDF literal nodes, ensuring compatibility with typed data in RDF models.[42]
Blank nodes in N3 denote anonymous resources within a graph, useful for describing complex structures without assigning global identifiers. They are introduced with _:label (e.g., _:temp ex:name "Temporary Node" .) or inline via property lists in square brackets (e.g., ex:Person ex:address [ ex:street "123 Main St." ; ex:city "Anytown" ] .). The bracketed form implicitly creates a blank node as the subject of nested triples, representing, for example, an unnamed address resource linked to a person. Unlike named resources, blank nodes are local to their graph and do not merge across documents.[43]
N3's basic RDF serialization maps directly to other formats like Turtle (a subset of N3) or RDF/XML, where prefixes, triples, literals, and blank nodes translate one-to-one without loss of information, facilitating interoperability in RDF ecosystems.[14]
Advanced Rule Usage
Notation3 supports advanced rule constructs that enable complex inference patterns beyond basic implications, allowing for universal quantification, nested logical structures, and the treatment of rules as first-class RDF terms. These features facilitate the expression of sophisticated knowledge representations, such as relational inferences in family ontologies or policy definitions.[14] A simple yet illustrative rule in Notation3 inverts a parent-child relationship using implication syntax. For instance, the rule{ ?x family:parent ?y } => { ?y family:child ?x } . states that if an individual ?x is the parent of ?y, then ?y is the child of ?x. This bidirectional inference is a core capability of N3 rules, enabling the derivation of inverse relations from existing triples.[44]
Quantification extends rule generality through variables, which are implicitly universally quantified in implications. Consider the example { :thermostat :temp ?x } => { :cooling :power ?x } ., where ?x represents any temperature value; if the thermostat reads that value, the cooling system matches it in power output. This construct ensures the rule applies to all possible bindings of the quantified variable, supporting parametric reasoning in dynamic scenarios.[22]
Nested formulas allow rules to be embedded as RDF objects, treating logical implications as reifiable terms. An example is :policy { :access => :granted } a :Rule ., which asserts a policy as an instance of a rule class, where the nested implication grants access unconditionally. Such nesting integrates rules into broader RDF graphs, enabling meta-level descriptions like policy catalogs or rule repositories.[14][4]
To demonstrate inference outcomes, consider a sample dataset combining facts and rules: :John family:parent :Mary . :Mary family:brother :Tom . paired with the nested rule { ?x family:parent ?y . ?y family:brother ?z } => { ?x family:uncle ?z } .. Applying the rule derives the new triple :John family:uncle :Tom ., illustrating how N3 engines like CWM perform forward chaining to expand the knowledge base with inferred relationships. This outcome highlights the practical utility of rules in generating transitive or composite relations from atomic data.[22]
Comparisons
With Turtle
Notation3 (N3) and Turtle share a common syntactic foundation, both employing a human-readable format for representing RDF graphs through concise notations such as prefixed names (qnames), prefix declarations with@prefix, and shorthand for triples using semicolons (;) for multiple predicates, commas (,) for multiple objects, and periods (.) to terminate statements.[13][14] Additionally, both support the keyword a as shorthand for rdf:type and blank node labels starting with _:, enabling compact expression of RDF data without verbose full URIs.[13][1] This overlap stems from Turtle's design as a subset of N3, ensuring that N3 is largely backward-compatible with Turtle, where any valid Turtle document parses correctly as N3.[14][1]
Despite these similarities, N3 extends Turtle with features absent in the latter, particularly for logical reasoning and rules. Turtle does not support implication operators like => for expressing rules, existential or universal variables (e.g., ?x or @forSome/@forAll), or additional keywords such as is .. of, =, or <= for equivalence and deduction.[45][14] Furthermore, Turtle lacks N3's graph terms (enclosed in {}) for embedding subgraphs or metadata, and it omits path syntax (e.g., :a.:b) and predicate inversion (e.g., <-).[1][45] Turtle holds official status as a W3C Recommendation within the RDF 1.1 suite, standardized for RDF graph serialization, whereas N3 remains a W3C Team Submission without formal recommendation status, prioritizing expressiveness over strict RDF conformance.[13][1]
In practice, Turtle suits use cases focused on pure RDF data serialization and exchange, such as publishing linked data or querying via SPARQL, where its simplicity aligns with RDF 1.1's graph model without needing logical extensions.[13][46] N3, by contrast, excels in scenarios requiring rules and inference, such as knowledge base construction or automated reasoning; for instance, Turtle cannot express a rule like { ?s ?p ?o } => { ?s a :Something } ., which N3 handles natively to derive new triples from patterns.[22][1]
Parsing behaviors reflect these distinctions: most Turtle parsers successfully process core N3 elements like triples, prefixes, and collections, due to the shared grammar, but they typically fail on N3-specific constructs such as implications, variables, or graph terms, requiring dedicated N3 processors for full support.[47][45] This partial compatibility allows incremental adoption but underscores the need for N3-aware tools in rule-based applications.[48]
With N-Triples and Other RDF Serializations
Notation3 (N3) offers a more compact notation compared to N-Triples, which serializes RDF data in a verbose, line-per-triple format without support for prefixes or shorthand symbols.[49][1] In N-Triples, each triple requires a full URI expansion on every line, such as<http://example.org/subject> <http://example.org/[predicate](/page/Predicate)> <http://example.org/object> ., whereas N3 allows abbreviations like @prefix ex: <http://example.org/> . ex:subject ex:[predicate](/page/Predicate) ex:object ., reducing redundancy and improving conciseness.[49][1] Additionally, N3 extends beyond basic triple serialization by incorporating rules and logical implications, features absent in N-Triples, which is strictly limited to RDF graph representation without inference capabilities.[1][49]
Relative to RDF/XML, N3 provides a plain-text brevity that contrasts with the structured verbosity of XML tags and namespaces required in RDF/XML.[1] For instance, RDF/XML might represent a simple triple with elements like <rdf:Description rdf:about="http://example.org/subject"><ex:predicate rdf:resource="http://example.org/object"/></rdf:Description>, embedding data within a hierarchical XML framework, while N3 uses a linear, declarative style that is easier for humans to author and read.[1] N3's syntax facilitates the inclusion of rules, such as { ?x ex:parent ?y . ?y ex:sister ?z } => { ?x ex:aunt ?z } ., which integrate seamlessly into documents, whereas RDF/XML lacks native support for such logical extensions and is better suited for integration with XML processing tools.[4]
In terms of expressiveness, N3 introduces logic layers, including implications via log:implies, quantifiers like @forAll and @forSome, and nested formulae, which are not present in standard RDF serializations such as N-Triples or RDF/XML unless augmented by separate extensions.[4][1] These features enable N3 to represent and reason over rules directly within the syntax, treating RDF statements as part of a broader logical framework, in contrast to the purely declarative nature of other formats.[4]
The primary trade-offs involve N3's emphasis on human-readability for authoring and rule-based knowledge representation versus the machine-optimized, unambiguous parsing of formats like N-Quads, which extend N-Triples to handle RDF datasets with one quad per line for streamlined processing in tools and storage systems.[1] While N3's added expressiveness can increase parsing complexity, it prioritizes usability for semantic web development over the strict simplicity of quad-based serializations.[1]