@ -1,29 +1,27 @@
#[ macro_use ]
extern crate lazy_static ;
extern crate reqwest ;
extern crate rudf ;
extern crate url ;
use reqwest ::Client ;
use rudf ::model ::data ::* ;
use rudf ::model ::vocab ::rdf ;
use rudf ::rio ::RioError ;
use rudf ::rio ::RioResult ;
use rudf ::rio ::ntriples ::read_ntriples ;
use rudf ::rio ::turtle ::read_turtle ;
use std ::collections ::HashSet ;
use std ::iter ::FromIterator ;
use std ::str ::FromStr ;
use url ::Url ;
struct RDFClient {
client : Client ,
data_factory : DataFactory ,
}
impl Default for RDFClient {
fn default ( ) -> Self {
Self {
client : Client ::new ( ) ,
data_factory : DataFactory ::default ( ) ,
}
}
}
@ -31,18 +29,14 @@ impl Default for RDFClient {
impl RDFClient {
fn load_turtle ( & self , uri : Url ) -> RioResult < HashSet < Triple > > {
match self . client . get ( uri . clone ( ) ) . send ( ) {
Ok ( response ) = > Ok ( HashSet ::from_iter ( read_turtle (
response ,
& self . data_factory ,
Some ( uri ) ,
) ? ) ) ,
Ok ( response ) = > Ok ( HashSet ::from_iter ( read_turtle ( response , Some ( uri ) ) ? ) ) ,
Err ( error ) = > Err ( RioError ::new ( error ) ) ,
}
}
fn load_ntriples ( & self , uri : Url ) -> RioResult < HashSet < Triple > > {
match self . client . get ( uri ) . send ( ) {
Ok ( response ) = > read_ntriples ( response , & self . data_factory ) . collect ( ) ,
Ok ( response ) = > read_ntriples ( response ) . collect ( ) ,
Err ( error ) = > Err ( RioError ::new ( error ) ) ,
}
}
@ -89,27 +83,21 @@ fn subject_for_predicate_object<'a>(
#[ test ]
fn turtle_w3c_testsuite ( ) {
let client = RDFClient ::default ( ) ;
let data_factory = & client . data_factory ;
let manifest = client
. load_turtle ( Url ::parse ( "https://www.w3.org/2013/TurtleTests/manifest.ttl" ) . unwrap ( ) )
. unwrap ( ) ;
let rdf_type = data_factory
. named_node ( Url ::parse ( "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" ) . unwrap ( ) ) ;
let mf_action = data_factory . named_node (
Url ::parse ( "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action" ) . unwrap ( ) ,
let mf_action = NamedNode ::from_str (
"http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action" ,
) . unwrap ( ) ;
let rdfs_comment = NamedNode ::from_str ( "http://www.w3.org/2000/01/rdf-schema#comment" ) . unwrap ( ) ;
let rdft_test_turtle_positive_syntax = Term ::from (
NamedNode ::from_str ( "http://www.w3.org/ns/rdftest#TestTurtlePositiveSyntax" ) . unwrap ( ) ,
) ;
let rdft_test_turtle_negative_syntax = Term ::from (
NamedNode ::from_str ( "http://www.w3.org/ns/rdftest#TestTurtleNegativeSyntax" ) . unwrap ( ) ,
) ;
let rdfs_comment = data_factory
. named_node ( Url ::parse ( "http://www.w3.org/2000/01/rdf-schema#comment" ) . unwrap ( ) ) ;
let rdft_test_turtle_positive_syntax =
Term ::from ( data_factory . named_node (
Url ::parse ( "http://www.w3.org/ns/rdftest#TestTurtlePositiveSyntax" ) . unwrap ( ) ,
) ) ;
let rdft_test_turtle_negative_syntax =
Term ::from ( data_factory . named_node (
Url ::parse ( "http://www.w3.org/ns/rdftest#TestTurtleNegativeSyntax" ) . unwrap ( ) ,
) ) ;
subjects_for_predicate_object ( & manifest , & rdf_type , & rdft_test_turtle_positive_syntax )
subjects_for_predicate_object ( & manifest , & rdf ::TYPE , & rdft_test_turtle_positive_syntax )
. for_each ( | test | {
let comment = object_for_subject_predicate ( & manifest , test , & rdfs_comment ) . unwrap ( ) ;
if let Some ( Term ::NamedNode ( file ) ) =
@ -124,7 +112,7 @@ fn turtle_w3c_testsuite() {
}
}
} ) ;
subjects_for_predicate_object ( & manifest , & rdf_type , & rdft_test_turtle_negative_syntax )
subjects_for_predicate_object ( & manifest , & rdf ::TYPE , & rdft_test_turtle_negative_syntax )
. for_each ( | test | {
let comment = object_for_subject_predicate ( & manifest , test , & rdfs_comment ) . unwrap ( ) ;
if let Some ( Term ::NamedNode ( file ) ) =
@ -143,25 +131,21 @@ fn turtle_w3c_testsuite() {
#[ test ]
fn ntriples_w3c_testsuite ( ) {
let client = RDFClient ::default ( ) ;
let data_factory = & client . data_factory ;
let manifest = client
. load_turtle ( Url ::parse ( "https://www.w3.org/2013/N-TriplesTests/manifest.ttl" ) . unwrap ( ) )
. unwrap ( ) ;
let rdf_type = data_factory
. named_node ( Url ::parse ( "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" ) . unwrap ( ) ) ;
let mf_action = data_factory . named_node (
Url ::parse ( "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action" ) . unwrap ( ) ,
let mf_action = NamedNode ::from_str (
"http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#action" ,
) . unwrap ( ) ;
let rdfs_comment = NamedNode ::from_str ( "http://www.w3.org/2000/01/rdf-schema#comment" ) . unwrap ( ) ;
let rdft_test_ntriples_positive_syntax = Term ::from (
NamedNode ::from_str ( "http://www.w3.org/ns/rdftest#TestNTriplesPositiveSyntax" ) . unwrap ( ) ,
) ;
let rdft_test_ntriples_negative_syntax = Term ::from (
NamedNode ::from_str ( "http://www.w3.org/ns/rdftest#TestNTriplesNegativeSyntax" ) . unwrap ( ) ,
) ;
let rdfs_comment = data_factory
. named_node ( Url ::parse ( "http://www.w3.org/2000/01/rdf-schema#comment" ) . unwrap ( ) ) ;
let rdft_test_turtle_positive_syntax = Term ::from ( data_factory . named_node (
Url ::parse ( "http://www.w3.org/ns/rdftest#TestNTriplesPositiveSyntax" ) . unwrap ( ) ,
) ) ;
let rdft_test_turtle_negative_syntax = Term ::from ( data_factory . named_node (
Url ::parse ( "http://www.w3.org/ns/rdftest#TestNTriplesNegativeSyntax" ) . unwrap ( ) ,
) ) ;
subjects_for_predicate_object ( & manifest , & rdf_type , & rdft_test_turtle _positive_syntax )
subjects_for_predicate_object ( & manifest , & rdf ::TYPE , & rdft_test_ntriples_positive_syntax )
. for_each ( | test | {
let comment = object_for_subject_predicate ( & manifest , test , & rdfs_comment ) . unwrap ( ) ;
if let Some ( Term ::NamedNode ( file ) ) =
@ -176,7 +160,7 @@ fn ntriples_w3c_testsuite() {
}
}
} ) ;
subjects_for_predicate_object ( & manifest , & rdf_type , & rdft_test_turtle _negative_syntax )
subjects_for_predicate_object ( & manifest , & rdf ::TYPE , & rdft_test_ntriples _negative_syntax )
. for_each ( | test | {
let comment = object_for_subject_predicate ( & manifest , test , & rdfs_comment ) . unwrap ( ) ;
if let Some ( Term ::NamedNode ( file ) ) =