# RDFtk: Core
 This crate provides an implementation of the RDF abstract syntax along with
a `Resource` type that provides a builder-like experience for models.
[](https://crates.io/crates/rdftk_core)
[](https://docs.rs/rdftk_core)
From [RDF 1.1 Concepts and Abstract Syntax](https://www.w3.org/TR/rdf11-concepts/);
> The core structure of the abstract syntax is a set of triples, each consisting
> of a subject, a predicate and an object. A set of such triples is called an
> RDF graph. An RDF graph can be visualized as a node and directed-arc diagram,
> in which each triple is represented as a node-arc-node link.
>
> 
>
> There can be three kinds of nodes in an RDF graph: IRIs, literals, and blank
> nodes.
In this library the triple, or statement, as well as subject, predicate, and
object types are in the module [`statement`](statement/index.html). Literal's as objects are supported in
the [`literal`](literal/index.html) module. Traits that describe graphs are provided by the [`graph`](graph/index.html)
module.
Additional features are provided such as support for data sets (module
[`model.data_set`](data_set/index.html)) as well as support for extensions to the core RDF abstract model
such as [RDF-star](https://w3c.github.io/rdf-star/cg-spec/editors_draft.html).
## Example
```rust
use rdftk_core::{Literal, Statement, StatementList, SubjectNode};
use rdftk_iri::IRI;
use std::rc::Rc;
use std::str::FromStr;
pub fn make_statements() -> StatementList {
let mut statements: StatementList = Default::default();
statements.push(Statement::new(
SubjectNode::named(
IRI::from_str("http://en.wikipedia.org/wiki/Tony_Benn").unwrap()
),
IRI::from_str("http://purl.org/dc/elements/1.1/title").unwrap(),
Literal::new("Tony Benn").into(),
).into());
// ...
statements
}
```
## Changes
### Version 0.5.6
Feature: this release adds the variant `Collection` to `ObjectNode` as well as a
corresponding `Collection` type. This models the RDF 1.1 collection concept as per
RDF 1.1 Semantics [D.3 RDF collections](https://www.w3.org/TR/rdf11-mt/#rdf-collections). Currently collections are not supported
for subject nodes.
* A Collection is a wrapper around a vector of object nodes.
* Collections are immutable.
* Collections may contain object nodes that are themselves collections.
* Collections have a `reify` method to convert to a set of collection triples.
* A new feature has been added `FEATURE_STMT_OBJECT_COLLECTIONS` that is now
supported by both `ObjectNode` and `Statement`.
### Version 0.5.5
* Fix: remove spaces from `xsd:hexBinary` string.
### Version 0.5.4
* Feature: better implementation of `Display` for `Literal`.
### Version 0.5.3
* Feature: add SKOS to PrefixMapping commons.
### Version 0.5.2
* Fix: bug in `hex_encode` for binary literals.
### Version 0.5.1
* Feature: added more `From` implementations for statement nodes.
### Version 0.5.0
This is a radical refactor as the complexity of traits was adding more cost than
value.
* Removed all traits and moved implementations from the `simple` module into
`model`.
* Removed all factory interfaces to simplify the user experience.
* Added `From` and `PartialEq` implementations for the supported literal value
types.
### Version 0.4.5
* Refactor: Remove all `Ref` wrapper types.
* Refactor: Make `SubjectNode` and `ObjectNode` into concrete enums.
* Refactor: Remove `Equiv` trait and rely on `PartialEq` instead.
* Refactor: Create new `Implementation` trait and `simple::Implementation` to hold
the set of factories.
### Version 0.4.4
* Refactor: re-wrote `Error` type and removed `error_chain` dependency.
### Version 0.4.3
* Feature: added `From<&BlankNode>` for both `Name` and `String`.
### Version 0.4.2
* Feature: changed some methods to use `Name` instead of strings
* Feature: added new `NamedGraph` trait.
* Feature: updated `DataSet` to use `NamedGraph` instead of separate name/graph
pairs.
* Build: updated dependency `rdftk_iri`.
* Build: updated dependency `rdftk_names`.
### Version 0.4.1
* Build: cargo audit/outdated/udeps
### Version 0.4.0
* Feature: moved to new `rdftk_iri` package which uses the `url::Url` and is more
efficient.
* Feature: moved to new `rdftk_names` package.
* Feature: replaced own implementation of `LanguageTag` with that from the package
`language_tags`.
* Refactor: made the trait `ObjectNode` inherit from `SubjectNode`.
* Refactor: move `SimpleSubjectNode` to be a tuple type, and implement `From<>` for
all `Subject` variants.
* Build: updated Rust edition from 2018 to 2021.
* Docs: added API docs as much as possible.
* Docs: run markuplint on `README.md`.
### Version 0.3.0
* The abstract RDF API, described in module 'model', is now entirely trait
based.
* An implementation, in module 'simple', provides concrete in-memory types.
* Added a new type LanguageTag to model these values more completely.
* Added notion of features which denote capabilities supported by data sets,
graphs, and statements implementations.
### Version 0.2.4
* Created new Featured trait implemented by a number of types that allow client
query of various optional capabilities. This also subsumes the
has_index/has_all_indices capability as all index queries are now feature
queries.
### Version 0.2.3
* Copied some errors from rdftk_io.
* Renamed the Io variant to ReadWrite.
### Version 0.2.2
* Reworked APIs to take <name>Ref types and to be consistent in use of trait
objects and types throughout.
* Added factory type for data sets.
* Made PrefixMappings a concrete type in the core::graph::mapping module.
* Added InvalidMatch and Io variants to ErrorKind.
* Added mutators to Statement.
### Version 0.2.1
* Changed API, removed mutable traits for Graph and DataSet, moved methods into
their base traits.
* Added factory types for graphs.
* Added Skolemization function for graphs.
### Version 0.2.0
* A change to the API, all `Statement`, and statement components are now passed as
`Rc` references.
* Added additional *_ref* constructors to allow cleaner client code.
* A change to the API, `Graph` and `DataSet` now use type parameters to describe
iterators returned by *query* methods.
* A change to the API, `QName` constructors now return errors instead of panic on
invalid values.
* Added more constructors for literal values.
* Added support for `chrono::Duration` in literals as well as the std version as
chrono supports the correct output form.
* Added `eq_` methods on `SubjectNode` and `ObjectNode` for simple testing of inner
values.
* Added documentation and examples throughout.
### Version 0.1.15
* Fixed Clippy suggestions.
* Removed Context from statements.
* Added value_factory method to Graph.
* Placed all unit tests in tests folder.
### Version 0.1.14
* Removed stand-alone named graph.
* Added DataSet as a way to associate names to graphs.
* Renamed CachingGraph to ValueFactory and made stand-alone.
### Version 0.1.13
* Bug: fixed Literal constructors to produce an escape-safe literal form for
strings.
### Version 0.1.12
* Fixed: cargo fmt error.
### Version 0.1.11
* Added: public types `StatementRef` and `StatementList` rather than having `Rc`
obviously in all APIs.
### Version 0.1.10
* **DEPRECATED** Support for [Datasets](https://www.w3.org/TR/rdf11-concepts/#section-dataset) and Quads by adding a context
(type `ContextNode`) to `Statement`.
### Version 0.1.9
* Support for [RDF*](https://w3c.github.io/rdf-star/) in `Statement`.
* Added additional constructors to `Statement`.
* Renamed Resource method `rdf_type` to `instance_of` for compatibility with RDF
schema usage.
* Added `is_valid` associated function to `QName`.
### Version 0.1.8
* Explicit exports over `pub use *`.
### Version 0.1.7
* Split `Graph` into `Graph` and `MutableGraph`.
* Split `NamedGraph` into `NamedGraph` and `MutableNamedGraph`.
* Added `get_default_namespace` to the `PrefixMappings` trait as a helper function.
* Altered `PrefixMappings::compress` and `PrefixMappings::expand` to take
references.
### Version 0.1.6
* Explicit version management.
### Version 0.1.5
* Updates for rdftk_memgraph to build.
### Version 0.1.4
* Made all local dependencies only major/minor valued.
### Version 0.1.3
* Moved all `IRI` to `IRIRef` on interfaces.
* Moved `Graph` and associated types into core and deprecated `rdftk_graph`.
### Version 0.1.2
* Clean-up changes.
### Version 0.1.1
* Added `From` to allow direct construction of a `SubjectNode` from an `IRI`.
* Fixed a bug in `QName` that dropped the ":" for non-prefixed values.
### Version 0.1.0
* First release.
[](http://www.w3.org/2001/sw/wiki/RDF)