Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

property defined with classname does not fully resume with resource #194

Closed
elrayle opened this issue Feb 17, 2016 · 6 comments
Closed

property defined with classname does not fully resume with resource #194

elrayle opened this issue Feb 17, 2016 · 6 comments
Labels

Comments

@elrayle
Copy link
Member

elrayle commented Feb 17, 2016

Branch: blank_node_test
TestFile: spec/active_triples/upgrade_from_6_to_8_spec.rb
Test:

  upgrade_from_6_to_8 -> 
  persisting body with parent strategy -> 
  and resuming -> 
    populates DummyCommentAnnotation properly -- PASSES
    populates DummyCommentBody properly -- FAILS

There are commented out puts statements that can be used for debugging to confirm that all triples are correctly in the repository and that the resumed comment annotation does not have all the triples for the body.

================================================
Triples in Repository (context: parent strategy)
------------------------------------------------

<http://my_oa_store/COMMENT_ANNO> a <http://www.w3.org/ns/oa#Annotation>;
   <http://www.w3.org/ns/oa#hasBody> <http://my_oa_store/COMMENT_BODY>;
   <http://www.w3.org/ns/oa#hasTarget> <http://searchworks.stanford.edu/view/665>;
   <http://www.w3.org/ns/oa#motivatedBy> <http://www.w3.org/ns/oa#commenting> .

<http://my_oa_store/COMMENT_BODY> a <http://www.w3.org/2011/content#ContentAsText>;
   <http://purl.org/dc/terms/format> "text/plain";
   <http://www.w3.org/2011/content#chars> "This is a comment." .

----------------------------------
Triples resumed into @comment_anno
----------------------------------

<http://my_oa_store/COMMENT_ANNO> a <http://www.w3.org/ns/oa#Annotation>;
   <http://www.w3.org/ns/oa#hasBody> <http://my_oa_store/COMMENT_BODY>;
   <http://www.w3.org/ns/oa#hasTarget> <http://searchworks.stanford.edu/view/665>;
   <http://www.w3.org/ns/oa#motivatedBy> <http://www.w3.org/ns/oa#commenting> .

----------------------------------
Triples resumed into @comment_anno.hasBody
----------------------------------

<http://my_oa_store/COMMENT_BODY> a <http://www.w3.org/2011/content#ContentAsText> .

----------------------------------
Triples resumed into @comment_body
----------------------------------

<http://my_oa_store/COMMENT_BODY> a <http://www.w3.org/2011/content#ContentAsText>;
   <http://purl.org/dc/terms/format> "text/plain";
   <http://www.w3.org/2011/content#chars> "This is a comment." .

NOTE: Test fails because hasBody, which should be an instance of DummyCommentBody and should hold all triples for the body, has only the type.

@elrayle elrayle added the bug label Feb 17, 2016
@elrayle elrayle changed the title child does not fully resume with parent when using parent strategy property defined with classname does not fully resume with resource Feb 23, 2016
@elrayle
Copy link
Member Author

elrayle commented Feb 23, 2016

This isn't really about parent_strategy. This is a change in behavior for all resources that have class_name defined.

Branch: blank_node_test
TestFile: spec/active_triples/upgrade_from_6_to_8_spec.rb
Test:

  upgrade_from_6_to_8 -> 
  persisting resource that has property with class_name defined -> 
  and resuming -> 
    populates DummyBook (resumed resoruce) properly -- PASSES
    populates DummyChapter (property resoruce) properly -- FAILS at 0.8, but passes at 0.6
    populates populates DummyChapter (directly from repository) properly -- PASSES

There are commented out puts statements that can be used for debugging to confirm that all triples are correctly in the repository and that the resumed chapter does not have all the triples for the body.

================================================
Triples in Repository (context: after persist of bk1 and ch1)
------------------------------------------------
<http://www.example.com/book1> a <http://www.example.com/type/Book>;
   <http://www.example.com/ontology/hasChapter> <http://www.example.com/book1/chapter1>;
   <http://www.example.com/ontology/title> "Learning about Explicit Links in ActiveTriples" .

<http://www.example.com/book1/chapter1> a <http://www.example.com/type/Chapter>;
   <http://www.example.com/ontology/title> "Defining a source with an Explicit Link" .

================================================
Triples in Resumed Resource (context: bk1 which should include ch1)
------------------------------------------------
<http://www.example.com/book1> a <http://www.example.com/type/Book>;
   <http://www.example.com/ontology/hasChapter> <http://www.example.com/book1/chapter1>;
   <http://www.example.com/ontology/title> "Learning about Explicit Links in ActiveTriples" .

================================================
Triples in property with class_name defined (context: ch1 coming from bk1.has_chapter)
------------------------------------------------
<http://www.example.com/book1/chapter1> a <http://www.example.com/type/Chapter> .

================================================
Triples when property resource resumed directly (context: ch1 coming new)
------------------------------------------------
<http://www.example.com/book1/chapter1> a <http://www.example.com/type/Chapter>;
   <http://www.example.com/ontology/title> "Defining a source with an Explicit Link" .

@elrayle
Copy link
Member Author

elrayle commented Feb 23, 2016

Not sure why this isn't working. Still digging. But here is where it appears to be falling over.

These are the lines in #reload where before reload ch1 isn't populated, but after reload it is (for 0.6)

self << repository.query(subject: rdf_subject)       # 0.6 Resource #reload  -- loads ch1 with all attributes
obj << repository.query(subject: obj)                # 0.8 RepositoryStrategy #reload  -- FAILs to load all attributes of ch1
obj << final_parent.query(subject: obj.rdf_subject)  # 0.8 ParentStrategy #reload   -- not used by either test

The 0.8 query fails to load all attributes of ch1. The query is slight different in that 0.6 sets the subject to rdf_subject and 0.8 sets it to obj. I don't have time to test this further today. I'll jump back in tomorrow, but wanted to indicate where I left off in case someone else explores it.

@elrayle
Copy link
Member Author

elrayle commented Feb 25, 2016

I'm not sure the difference is happening at load time through path new -> reload -> query. The triples in self are the same at 0.6 and 0.8. When you attempt to access the property with class_name (e.g. bk1.has_chapter), it goes through get_values -> get_term (0.6) and get_values -> get_relation (0.8). The object that is returned is of the correct class in both cases. But for 0.8, the object only has the type triple. For 0.6, it has all triples for the rdf_subject of the object.

@elrayle
Copy link
Member Author

elrayle commented Mar 2, 2016

Define class (DummyBook) for a resource that has a property (has_chapter) defined with class_name (DummyChapter).

class DummyChapter < ActiveTriples::Resource
  configure repository: :default, type: RDF::URI('http://www.example.com/type/Chapter')
  property :title, predicate: RDF::URI('http://www.example.com/ontology/title')
end

class DummyBook < ActiveTriples::Resource
  configure repository: :default, type: RDF::URI('http://www.example.com/type/Book')
  property :title, predicate: RDF::URI('http://www.example.com/ontology/title')
  property :has_chapter, predicate: RDF::URI('http://www.example.com/ontology/hasChapter'), class_name: DummyChapter  # Explicit Link
end

Create instance of both and persist. NOTE: Not using parent_strategy for property resource.

bk1 = DummyBook.new('http://www.example.com/book1')
bk1.title = 'Learning about Explicit Links in ActiveTriples'
bk1.persist!

ch1 = DummyChapter.new('http://www.example.com/book1/chapter1')
ch1.title = 'Defining a source with an Explicit Link'
ch1.persist!

bk1.has_chapter = ch1
bk1.persist!

Read resource that has a property defined with class_name from the repository.

bk1r = DummyBook.new('http://www.example.com/book1')

Get resource from property.

ch1r = bk1r.has_chapter.first

Get title from property resource.

ch1r.title   # => []

What happens is that ch1r has parent persistence strategy, so all requests for properties go through the final_parent which is bk1r. AND when bk1r was read from the repository, it only pulled in a single triple defining type of ch1r. At the point title is requested, it does not go to the repository and get the rest of the triples related to ch1r.

I am assuming that this is (or could be) a lazy load situation where we don't want to explode the graph until that part is requested. A solution could involve a flag (e.g. loaded=TRUE | FALSE). The value of loaded could be used as follows...

bk1r = DummyBook.new('http://www.example.com/book1')   # bk1r.loaded => TRUE
ch1r = bk1r.has_chapter.first                          #ch1r.loaded => FALSE
ch1r.title                                             # reload see loaded == FALSE and loads all triples for ch1r and sets loaded=TRUE

The change of loaded from FALSE to TRUE could either happen at the first request of anything from has_chapter, or at the first request of a property from that resource.

If DummyChapter also has a property with class_name, that instance would continue to have loaded => FALSE until it is directly requested.

@elrayle
Copy link
Member Author

elrayle commented Mar 2, 2016

@no-reply @tpendragon Please review the last comment which summarizes how to reproduce, what is happening, and a proposed solution.

@elrayle
Copy link
Member Author

elrayle commented Mar 7, 2016

I am looking for the right place to put a loaded=true|false flag.

Currently, when you read the book from the repository, the following happens...

  • The book is initialized as an RDFSource with RepositoryStrategy
  • Each property for book is created as a Relation
  • Creating a Relation for has_chapter property b/c it has class_name defined
    • Calls Relation.make_node to create an RDFSource of the specified class with ParentingStrategy
    • The node is reloaded using ParentingStrategy from the book (final_parent) and is empty since it isn't there yet
    • As part of RDFSource initialization, it adds the type triple to the node
    • The node is shifted into the Relation for has_chapter property on book
      • which calls set
      • which calls set_value
      • and persists to book using ParentStrategy

At this point, has_chapter has its type triple set in book.

no-reply pushed a commit that referenced this issue Mar 15, 2016
FIXES #194 - add loaded flag to lazy load property sources with parent_strategy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant