ld-query
ld-query copied to clipboard
[@attribute=value] does not appear to work with regular strings as value
The document I'm querying is Example 2 from http://schema.org/Book. Here's a relevant snippet:
{
"@context": "http://schema.org",
"@graph": [
{
"@id": "#author",
"@type": "Person",
"birthDate": "1892",
"deathDate": "1973",
"name": "Tolkien, J. R. R. (John Ronald Reuel)",
"sameAs": "http://viaf.org/viaf/95218067"
}]
}
Here is my query:
const doc = LD({
"@vocab": "http://schema.org/",
})(expanded)
expect(doc.query("[name=Tolkien, J. R. R. (John Ronald Reuel)]")).to.exist
This returns null, whereas I expect it to return the author's node.
Am I misunderstanding how the [@attribute=value] code is supposed to work? I'd like to be able to query on matching values within the document, not just on document structure. Is this supported?
Internally, I see your extractStep function is calling expand on step.value because it doesn't match the nonExpandableValuePropNamePattern. We end up with the value http://schema.org/Return of the King.
If I comment out the call to expand the query still fails to match, so there's something else going on as well.
Hmm. It's been a while since i looked at this code base (although it's being used). I'll try to have a look this week.
Sorry it's been so long getting back to you @bitmage
I believe the code doesn't cover the case you are describing, although it would be very useful.
The only current support is for testing @id, @type (?) and @index values. General find-by-attribute functionality isn't included. Use cases I have seen usually involve doing a .queryAll to collect @type=author nodes, and then a plain-old javascript .filter or .find to pick out the one with the required attributes.
I'm considering a major overhaul of the library, in combination with a server-side version in C#, so I'm not sure whether to update the library in its current form with this functionality, or just add it to the feature list for the next version. Thoughts?