Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Eq iml for Store (and made Namespace a struct)

  • Loading branch information...
commit 59e03646955f20402e25d0ea8ca8c1eee1af1233 1 parent 4fb8b14
@jesse99 authored
View
2  src/object.rs
@@ -30,7 +30,7 @@ enum Object // TODO: once we support serialization we'll need to add somethin
impl Object
{
- fn to_friendly_str(namespaces: &[{prefix: ~str, path: ~str}]) -> ~str
+ fn to_friendly_str(namespaces: &[store::Namespace]) -> ~str
{
match self
{
View
28 src/solution.rs
@@ -5,7 +5,7 @@ use object::*;
/// Name of a namespace plus the IRI it expands to.
///
/// This is a sendable type.
-type Namespace = {prefix: ~str, path: ~str};
+struct Namespace {prefix: ~str, path: ~str}
/// Result of matching a triple with a SPARQL query.
///
@@ -120,6 +120,32 @@ impl &Solution : ToStr
}
}
+impl Namespace : cmp::Eq
+{
+ pure fn eq(&&other: Namespace) -> bool
+ {
+ self.prefix == other.prefix && self.path == other.path
+ }
+
+ pure fn ne(&&other: Namespace) -> bool
+ {
+ !self.eq(other)
+ }
+}
+
+impl Solution : cmp::Eq
+{
+ pure fn eq(&&other: Solution) -> bool
+ {
+ self.namespaces == other.namespaces && self.rows == other.rows
+ }
+
+ pure fn ne(&&other: Solution) -> bool
+ {
+ !self.eq(other)
+ }
+}
+
impl SolutionRow : SolutionRowMethods
{
pure fn get(name: ~str) -> Object
View
2  src/sparql.rs
@@ -1082,7 +1082,7 @@ priv fn make_parser() -> Parser<Selector>
// [6] PrefixDecl ::= 'PREFIX' PNAME_NS IRI_REF
let PrefixDecl = do seq3("PREFIX".liti().ws(), PNAME_NS.ws(), IRI_REF)
- |_p, ns, r| {result::Ok({prefix: str::slice(*ns, 0u, str::len(*ns)-1u), path: copy *r})};
+ |_p, ns, r| {result::Ok(solution::Namespace {prefix: str::slice(*ns, 0u, str::len(*ns)-1u), path: copy *r})};
// [4] Prologue ::= (BaseDecl | PrefixDecl)*
let Prologue = PrefixDecl.r0();
View
12 src/store.rs
@@ -83,7 +83,7 @@ pub fn get_blank_name(store: &Store, prefix: ~str) -> ~str
}
/// Returns either the iri or the prefixed version of the iri.
-pub fn contract_uri(namespaces: &[{prefix: ~str, path: ~str}], iri: &str) -> ~str
+pub fn contract_uri(namespaces: &[solution::Namespace], iri: &str) -> ~str
{
match vec::find(namespaces, |n| {str::starts_with(iri, n.path)})
{
@@ -421,11 +421,11 @@ impl Triple : ToStr
priv fn default_namespaces() -> ~[Namespace]
{
~[
- {prefix: ~"_", path: ~"_:"},
- {prefix: ~"xsd", path: ~"http://www.w3.org/2001/XMLSchema#"},
- {prefix: ~"rdf", path: ~"http://www.w3.org/1999/02/22-rdf-syntax-ns#"},
- {prefix: ~"rdfs", path: ~"http://www.w3.org/2000/01/rdf-schema#"},
- {prefix: ~"owl", path: ~"http://www.w3.org/2002/07/owl#"}
+ solution::Namespace {prefix: ~"_", path: ~"_:"},
+ solution::Namespace {prefix: ~"xsd", path: ~"http://www.w3.org/2001/XMLSchema#"},
+ solution::Namespace {prefix: ~"rdf", path: ~"http://www.w3.org/1999/02/22-rdf-syntax-ns#"},
+ solution::Namespace {prefix: ~"rdfs", path: ~"http://www.w3.org/2000/01/rdf-schema#"},
+ solution::Namespace {prefix: ~"owl", path: ~"http://www.w3.org/2002/07/owl#"}
]
}
View
10 src/tests/test_data.rs
@@ -9,8 +9,8 @@ use store::*;
fn got_cast1() -> Store
{
let store = Store(~[
- {prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"},
- {prefix: ~"v", path: ~"http://www.w3.org/2006/vcard/ns#"}
+ solution::Namespace {prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"},
+ solution::Namespace {prefix: ~"v", path: ~"http://www.w3.org/2006/vcard/ns#"}
], @std::map::HashMap());
store.add(~"got:Eddard_Stark", ~[
(~"v:fn", StringValue(~"Eddard Stark", ~"")),
@@ -22,8 +22,8 @@ fn got_cast1() -> Store
fn got_cast3() -> Store
{
let store = Store(~[
- {prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"},
- {prefix: ~"v", path: ~"http://www.w3.org/2006/vcard/ns#"}
+ solution::Namespace {prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"},
+ solution::Namespace {prefix: ~"v", path: ~"http://www.w3.org/2006/vcard/ns#"}
], @std::map::HashMap());
store.add(~"got:Eddard_Stark", ~[
@@ -55,7 +55,7 @@ fn got_cast3() -> Store
fn animals() -> Store
{
- let store = Store(~[{prefix: ~"wiki", path: ~"http://en.wikipedia.org/wiki/"}], @std::map::HashMap());
+ let store = Store(~[solution::Namespace {prefix: ~"wiki", path: ~"http://en.wikipedia.org/wiki/"}], @std::map::HashMap());
store.add(~"wiki:aardvark", ~[
(~"wiki:phylum", StringValue(~"chordata", ~"")),
View
2  src/tests/test_example.rs
@@ -11,7 +11,7 @@ fn monsters() -> Store
{
// Namespaces allow subjects and predicates to be added to the
// store using a prefixed name instead of a full URL.
- let namespaces = ~[{prefix: ~"game", path: ~"http://game/ns#"}];
+ let namespaces = ~[solution::Namespace {prefix: ~"game", path: ~"http://game/ns#"}];
// Vector of function name and function pointer tuples. These
// represent user defined functions that may be called from
View
2  src/tests/test_sparql.rs
@@ -154,7 +154,7 @@ fn unmatched_path()
?subject wiki:class \"arachnid\"
}";
- let store = Store(~[{prefix: ~"wiki", path: ~"http://en.wikipedia.org/wiki/"}], &std::map::HashMap());
+ let store = Store(~[solution::Namespace {prefix: ~"wiki", path: ~"http://en.wikipedia.org/wiki/"}], &std::map::HashMap());
store.add(~"wiki:giraffe", ~[
(~"wiki:phylum", StringValue(~"chordata", ~"")),
(~"wiki:class", StringValue(~"mammalia", ~"")),
View
4 src/tests/test_sparql_literals.rs
@@ -73,8 +73,8 @@ fn long_string2_match()
fn fancy_types() -> Store
{
let store = Store(~[
- {prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"},
- {prefix: ~"x", path: ~"http://blah#"}
+ solution::Namespace {prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"},
+ solution::Namespace {prefix: ~"x", path: ~"http://blah#"}
], &std::map::HashMap());
store.add(~"x:Hans", ~[(~"x:greeting", StringValue(~"guten tag", ~"de"))]);
View
12 src/tests/test_store.rs
@@ -44,9 +44,9 @@ fn iteration()
fn references()
{
let store = Store(~[
- {prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"},
- {prefix: ~"v", path: ~"http://www.w3.org/2006/vcard/ns#"},
- {prefix: ~"foo", path: ~"http://www.whatever.org/"}
+ solution::Namespace {prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"},
+ solution::Namespace {prefix: ~"v", path: ~"http://www.w3.org/2006/vcard/ns#"},
+ solution::Namespace {prefix: ~"foo", path: ~"http://www.whatever.org/"}
], &std::map::HashMap());
store.add(~"got:Eddard_Stark", ~[
@@ -114,7 +114,7 @@ fn blank_nodes()
#[test]
fn container()
{
- let store = Store(~[{prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"}], &std::map::HashMap());
+ let store = Store(~[solution::Namespace {prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"}], &std::map::HashMap());
store.add_alt(~"got:places", ~[IriValue(~"got:The_Wall"), IriValue(~"got:Winterfell")]);
let mut actual = ~[];
@@ -136,7 +136,7 @@ fn container()
#[test]
fn list0()
{
- let store = Store(~[{prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"}], &std::map::HashMap());
+ let store = Store(~[solution::Namespace {prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"}], &std::map::HashMap());
store.add_list(~"got:westeros", ~"got:cities", ~[]);
let mut actual = ~[];
@@ -157,7 +157,7 @@ fn list0()
#[test]
fn list1()
{
- let store = Store(~[{prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"}], &std::map::HashMap());
+ let store = Store(~[solution::Namespace {prefix: ~"got", path: ~"http://awoiaf.westeros.org/index.php/"}], &std::map::HashMap());
store.add_list(~"got:westeros", ~"got:cities", ~[StringValue(~"Lanisport", ~"")]);
let mut actual = ~[];
Please sign in to comment.
Something went wrong with that request. Please try again.