Struct rdf::graph::Graph [−] [src]

`pub struct Graph { /* fields omitted */ }`

Representation of an RDF graph.

Methods

`impl Graph`[src]

`pub fn new(base_uri: Option<&Uri>) -> Graph`[src]

Constructor for the RDF graph.

Examples

```use rdf::graph::Graph;

let graph = Graph::new(None);```

`pub fn is_empty(&self) -> bool`[src]

Returns `true` if the graph does not contain any triples.

Examples

```use rdf::graph::Graph;

let graph = Graph::new(None);

assert_eq!(graph.is_empty(), true);```

`pub fn count(&self) -> usize`[src]

Returns the number of triples that are stored in the graph.

Examples

```use rdf::graph::Graph;

let graph = Graph::new(None);

assert_eq!(graph.count(), 0);```

`pub fn base_uri(&self) -> &Option<Uri>`[src]

Returns the base URI of the graph.

Examples

```use rdf::uri::Uri;
use rdf::graph::Graph;

let base_uri = Uri::new("http://example.org/".to_string());
let graph = Graph::new(Some(&base_uri));

assert_eq!(graph.base_uri(), &Some(base_uri));```

`pub fn set_base_uri(&mut self, uri: &Uri)`[src]

Sets the base URI of the graph.

Examples

```use rdf::uri::Uri;
use rdf::graph::Graph;

let base_uri = Uri::new("http://base.example.org/".to_string());
let mut graph = Graph::new(None);

graph.set_base_uri(&base_uri);

assert_eq!(graph.base_uri(), &Some(base_uri));```

`pub fn namespaces(&self) -> &HashMap<String, Uri>`[src]

Returns a hash map of namespaces and prefixes.

`pub fn add_namespace(&mut self, ns: &Namespace)`[src]

Adds a new namespace with a specific prefix to the graph.

Examples

```use rdf::uri::Uri;
use rdf::graph::Graph;
use rdf::namespace::Namespace;

let mut graph = Graph::new(None);
Uri::new("http://example.org/".to_string())));

assert_eq!(graph.namespaces().len(), 1);```

`pub fn get_namespace_uri_by_prefix(&self, prefix: String) -> Result<&Uri>`[src]

Returns the URI of a namespace with the provided prefix.

Examples

```use rdf::uri::Uri;
use rdf::graph::Graph;
use rdf::namespace::Namespace;

let mut graph = Graph::new(None);
let uri = Uri::new("http://example.org/".to_string());

assert_eq!(graph.get_namespace_uri_by_prefix("example".to_string()).unwrap(), &uri);```

Failures

• No namespace with the provided prefix exists

`pub fn create_literal_node(&self, literal: String) -> Node`[src]

Returns a literal node of the specified namespace.

Examples

```use rdf::graph::Graph;
use rdf::node::Node;

let graph = Graph::new(None);
let literal_node = graph.create_literal_node("literal".to_string());

assert_eq!(literal_node, Node::LiteralNode {
literal: "literal".to_string(),
data_type: None,
language: None
});```

`pub fn create_literal_node_with_data_type(    &self,     literal: String,     data_type: &Uri) -> Node`[src]

Returns a literal node with a specified data type.

Examples

```use rdf::graph::Graph;
use rdf::node::Node;
use rdf::uri::Uri;

let graph = Graph::new(None);
let literal_node = graph.create_literal_node_with_data_type("literal".to_string(), &Uri::new("http://example.org/show/localName".to_string()));

assert_eq!(literal_node, Node::LiteralNode {
literal: "literal".to_string(),
data_type: Some(Uri::new("http://example.org/show/localName".to_string())),
language: None
});```

`pub fn create_literal_node_with_language(    &self,     literal: String,     language: String) -> Node`[src]

Returns a literal node with a specified language.

Examples

```use rdf::graph::Graph;
use rdf::node::Node;

let graph = Graph::new(None);
let literal_node = graph.create_literal_node_with_language("literal".to_string(), "en".to_string());

assert_eq!(literal_node, Node::LiteralNode {
literal: "literal".to_string(),
data_type: None,
language: Some("en".to_string())
});```

`pub fn create_blank_node(&mut self) -> Node`[src]

Creates a blank node with a unique ID.

Examples

```use rdf::graph::Graph;
use rdf::node::Node;

let mut graph = Graph::new(None);
let blank_node = graph.create_blank_node();

assert_eq!(blank_node, Node::BlankNode {
id: "auto0".to_string()
});```

`pub fn create_blank_node_with_id(&self, id: String) -> Node`[src]

Creates a blank node with the specified ID.

Examples

```use rdf::graph::Graph;
use rdf::node::Node;

let graph = Graph::new(None);
let blank_node = graph.create_blank_node_with_id("foobar".to_string());

assert_eq!(blank_node, Node::BlankNode {
id: "foobar".to_string()
});```

`pub fn create_uri_node(&self, uri: &Uri) -> Node`[src]

Creates a new URI node.

Examples

```use rdf::graph::Graph;
use rdf::node::Node;
use rdf::uri::Uri;

let graph = Graph::new(None);
let uri_node = graph.create_uri_node(&Uri::new("http://example.org/show/localName".to_string()));

assert_eq!(uri_node, Node::UriNode {
uri: Uri::new("http://example.org/show/localName".to_string())
});```

`pub fn add_triple(&mut self, triple: &Triple)`[src]

Adds a triple to the graph.

Examples

```use rdf::graph::Graph;
use rdf::uri::Uri;
use rdf::triple::Triple;

let mut graph = Graph::new(None);

let subject = graph.create_blank_node();
let predicate = graph.create_uri_node(&Uri::new("http://example.org/show/localName".to_string()));
let object = graph.create_blank_node();
let triple = Triple::new(&subject, &predicate, &object);

assert_eq!(graph.count(), 1);```

Examples

```use rdf::graph::Graph;
use rdf::uri::Uri;
use rdf::triple::Triple;

let mut graph = Graph::new(None);

let subject = graph.create_blank_node();
let predicate = graph.create_uri_node(&Uri::new("http://example.org/show/localName".to_string()));
let object = graph.create_blank_node();

let triple1 = Triple::new(&subject, &predicate, &object);
let triple2 = Triple::new(&subject, &predicate, &object);

assert_eq!(graph.count(), 2);```

`pub fn remove_triple(&mut self, triple: &Triple)`[src]

Deletes the triple from the graph.

Examples

```use rdf::graph::Graph;
use rdf::uri::Uri;
use rdf::triple::Triple;

let mut graph = Graph::new(None);

let subject = graph.create_blank_node();
let predicate = graph.create_uri_node(&Uri::new("http://example.org/show/localName".to_string()));
let object = graph.create_blank_node();
let triple = Triple::new(&subject, &predicate, &object);

graph.remove_triple(&triple);

assert_eq!(graph.count(), 0);```

`pub fn get_triples_with_subject(&self, node: &Node) -> Vec<&Triple>`[src]

Returns all triples from the store that have the specified subject node.

Examples

```use rdf::graph::Graph;
use rdf::uri::Uri;
use rdf::triple::Triple;

let mut graph = Graph::new(None);

let subject1 = graph.create_blank_node();
let subject2 = graph.create_blank_node();
let predicate = graph.create_uri_node(&Uri::new("http://example.org/show/localName".to_string()));
let object = graph.create_blank_node();

let triple1 = Triple::new(&subject1, &predicate, &object);
let triple2 = Triple::new(&subject2, &predicate, &object);

assert_eq!(graph.get_triples_with_subject(&subject1), vec![&triple1]);```

`pub fn get_triples_with_predicate(&self, node: &Node) -> Vec<&Triple>`[src]

Returns all triples from the store that have the specified predicate node.

Examples

```use rdf::graph::Graph;
use rdf::uri::Uri;
use rdf::triple::Triple;

let mut graph = Graph::new(None);

let subject1 = graph.create_blank_node();
let subject2 = graph.create_blank_node();
let predicate = graph.create_uri_node(&Uri::new("http://example.org/show/localName".to_string()));
let object = graph.create_blank_node();

let triple1 = Triple::new(&subject1, &predicate, &object);
let triple2 = Triple::new(&subject2, &predicate, &object);

assert_eq!(graph.get_triples_with_predicate(&predicate), vec![&triple1, &triple2]);```

`pub fn get_triples_with_object(&self, node: &Node) -> Vec<&Triple>`[src]

Returns all triples from the store that have the specified object node.

Examples

```use rdf::graph::Graph;
use rdf::uri::Uri;
use rdf::triple::Triple;

let mut graph = Graph::new(None);

let subject1 = graph.create_blank_node();
let subject2 = graph.create_blank_node();
let predicate = graph.create_uri_node(&Uri::new("http://example.org/show/localName".to_string()));
let object = graph.create_blank_node();

let triple1 = Triple::new(&subject1, &predicate, &object);
let triple2 = Triple::new(&subject2, &predicate, &object);

assert_eq!(graph.get_triples_with_object(&object), vec![&triple1, &triple2]);```

`pub fn get_triples_with_subject_and_object(    &self,     subject_node: &Node,     object_node: &Node) -> Vec<&Triple>`[src]

Returns all triples from the triple store where the subject and object nodes match the provided nodes.

Examples

```use rdf::graph::Graph;
use rdf::uri::Uri;
use rdf::triple::Triple;

let mut graph = Graph::new(None);

let subject1 = graph.create_blank_node();
let subject2 = graph.create_blank_node();
let predicate = graph.create_uri_node(&Uri::new("http://example.org/show/localName".to_string()));
let object = graph.create_blank_node();

let triple1 = Triple::new(&subject1, &predicate, &object);
let triple2 = Triple::new(&subject2, &predicate, &object);

assert_eq!(graph.get_triples_with_subject_and_object(&subject1, &object), vec![&triple1]);```

`pub fn get_triples_with_subject_and_predicate(    &self,     subject_node: &Node,     predicate_node: &Node) -> Vec<&Triple>`[src]

Returns all triples from the triple store where the subject and predicate nodes match the provided nodes.

Examples

```use rdf::graph::Graph;
use rdf::uri::Uri;
use rdf::triple::Triple;

let mut graph = Graph::new(None);

let subject1 = graph.create_blank_node();
let subject2 = graph.create_blank_node();
let predicate = graph.create_uri_node(&Uri::new("http://example.org/show/localName".to_string()));
let object = graph.create_blank_node();

let triple1 = Triple::new(&subject1, &predicate, &object);
let triple2 = Triple::new(&subject2, &predicate, &object);

assert_eq!(graph.get_triples_with_subject_and_predicate(&subject1, &predicate), vec![&triple1]);```

`pub fn get_triples_with_predicate_and_object(    &self,     predicate_node: &Node,     object_node: &Node) -> Vec<&Triple>`[src]

Returns all triples from the triple store where the predicate and object nodes match the provided nodes.

Examples

```use rdf::graph::Graph;
use rdf::uri::Uri;
use rdf::triple::Triple;

let mut graph = Graph::new(None);

let subject1 = graph.create_blank_node();
let subject2 = graph.create_blank_node();
let predicate = graph.create_uri_node(&Uri::new("http://example.org/show/localName".to_string()));
let object = graph.create_blank_node();

let triple1 = Triple::new(&subject1, &predicate, &object);
let triple2 = Triple::new(&subject2, &predicate, &object);

assert_eq!(graph.get_triples_with_predicate_and_object(&predicate, &object), vec![&triple1, &triple2]);```

`pub fn triples_iter(&self) -> Iter<Triple>`[src]

Returns an iterator over the triples of the graph.

Trait Implementations

`impl Debug for Graph`[src]

`fn fmt(&self, __arg_0: &mut Formatter) -> Result`[src]

Formats the value using the given formatter. Read more