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

[@attribute=value] does not appear to work with regular strings as value #27

Open
bitmage opened this issue Apr 23, 2018 · 2 comments
Open

Comments

@bitmage
Copy link

bitmage commented Apr 23, 2018

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.

@goofballLogic
Copy link
Owner

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.

@goofballLogic
Copy link
Owner

goofballLogic commented May 7, 2018

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants