Commits

Konstantin Baierer committed c076721

Basic round-tripping of RDF data using class rdf_store backend possible (buggy classatribute resolution though)

Comments (0)

Files changed (5)

 MYMETA.yml
 MANIFEST.SKIP
 MANIFEST.SKIP.bak
+**/*.sqlite

lib/MooseX/Semantic/Role/RdfBackend.pm

 with (
     # Class role
     'MooseX::Semantic::Role::WithRdfType',
-    'MooseX::Semantic::Role::RdfImport',
-    'MooseX::Semantic::Role::RdfImportAll',
-    # Instance role
-    'MooseX::Semantic::Role::Resource',
-    'MooseX::Semantic::Role::RdfExport',
+    # 'MooseX::Semantic::Role::RdfImport',
+    # 'MooseX::Semantic::Role::RdfImportAll',
+    # # Instance role
+    # 'MooseX::Semantic::Role::Resource',
+    # 'MooseX::Semantic::Role::RdfExport',
 );
 
 our %RDF_TRINE_STORE_OPTS = (
 
 sub new_from_store {
     my ($cls, $uri) = @_;
-    return $cls->new_from_model( $cls->rdf_store, $uri );
+    my $model = RDF::Trine::Model->new( $cls->rdf_store );
+    return $cls->new_from_model( $model, $uri );
 }
 
 sub store {
     my ($inst) = @_;
-    warn Dumper $inst->meta->get_attribute_list;
-    $inst->export_to_model( $inst->rdf_store );
+    # warn Dumper $inst->meta->get_attribute_list;
+    my $model = RDF::Trine::Model->new( $inst->rdf_store );
+    $inst->export_to_model( $model );
+    # warn Dumper $model->size;
 }
 
 1;

lib/MooseX/Semantic/Role/WithRdfType.pm

     default => sub { [] },
 );
 
+no MooseX::ClassAttribute;
+no Moose;
 1;

lib/MooseX/Semantic/Test/BackendPerson.pm

 package MooseX::Semantic::Test::BackendPerson;
 use Moose;
+with (
+    'MooseX::Semantic::Role::RdfBackend',
+    'MooseX::Semantic::Role::RdfImport',
+    'MooseX::Semantic::Role::RdfExport',
+    # 'MooseX::Semantic::Role::WithRdfType',
+    'MooseX::Semantic::Role::Resource',
+);
 
 extends 'MooseX::Semantic::Test::Person';
 
-with (
-    'MooseX::Semantic::Role::RdfBackend',
+__PACKAGE__->rdf_type('http://xmlns.com/foaf/0.1/Person');
+
+has name => (
+    traits => ['Semantic'],
+    is => 'rw',
+    isa => 'Str',
+    uri => 'http://xmlns.com/foaf/0.1/name',
 );
+has topic_interest => (
+    traits => ['MooseX::Semantic::Meta::Attribute::Trait'],
+    is => 'rw',
+    isa => 'ArrayRef',
+    uri => 'http://xmlns.com/foaf/0.1/topic-interest',
+);
+has country => (
+    traits => ['MooseX::Semantic::Meta::Attribute::Trait'],
+    is => 'rw',
+    isa => 'Str',
+    uri => 'http://ogp.me/ns#country-name',
+);
+has subjects => (
+    traits => ['MooseX::Semantic::Meta::Attribute::Trait'],
+    is => 'rw',
+    rdf_lang => 'en',
+    isa => 'ArrayRef[Str]',
+    uri => 'http://purl.org/dc/terms/subject',
+);
+has friends => (
+    traits => ['Semantic', 'Array'],
+    is => 'rw',
+    isa => 'ArrayRef[MooseX::Semantic::Test::Person]',
+    uri => 'http://xmlns.com/foaf/0.1/knows',
+    default => sub { [] },
+    predicate => 'has_friends',
+    handles => {
+        'add_friend' => 'push',
+        'get_friend' => 'get',
+        'find_friend' => 'first',
+    },
+);
+has favorite_numer => (
+    traits => ['Semantic'],
+    is => 'rw',
+    isa => 'Int',
+    uri => 'http://xmlns.com/foaf/0.1/favorite_number',
+);
+has generic_one_to_one_relation => (
+    traits => ['Semantic'],
+    is => 'rw',
+    isa => 'MooseX::Semantic::Test::Person',
+    uri => 'http://xmlns.com/foaf/0.1/generic_one_to_one_relation',
+);
+
+
+1;

t/role_rdfbackend.t

 MooseX::Semantic::Test::BackendPerson->_trine_store_opts(
     storetype => 'DBI',
     name => 'semantic_moose',
-    dsn => 'dbi:SQLite:dbname=/media/DB/semantic_moose.sqlite',
+    dsn => 'dbi:SQLite:dbname=t/data/semantic_moose.sqlite',
     username => 'FAKE',
     password => 'FAKE',
 );
 isa_ok( MooseX::Semantic::Test::BackendPerson->rdf_store, 'RDF::Trine::Store');
 is( MooseX::Semantic::Test::BackendPerson->rdf_store->model_name, 'semantic_moose');
 my $store = MooseX::Semantic::Test::BackendPerson->rdf_store;
+# warn Dumper $store;
 
 my $rdf_about_uri = 'http://example/#me';
 my $p = MooseX::Semantic::Test::BackendPerson->new(rdf_about => $rdf_about_uri, name => 'kb', favorite_numer => 3);
-warn Dumper $p;
+# warn Dumper $p->name;
+# warn Dumper $p->meta->get_attribute('name');
+# warn Dumper [$p->meta->get_attribute_list];
+# warn Dumper [$p->meta->get_class_attribute_list];
+# warn Dumper $p;
 $p->store;
 my $p2 = MooseX::Semantic::Test::BackendPerson->new_from_store( $rdf_about_uri );
-warn Dumper $p2;
+# warn Dumper $p2;
+is($p->name, $p2->name, 'Backend Person can be round-tripped');
 
-
-
+done_testing;