digitalbazaar / pyld

JSON-LD processor written in Python
https://json-ld.org/
Other
611 stars 131 forks source link

does pyld support content negotiation? #105

Open sanuann opened 4 years ago

sanuann commented 4 years ago

I am trying to run pyld functions (expand, normalize) on the document below but it doesn't seem to get the context urls linked.

    doc = {
                "@context": [
                    "https://schema.repronim.org/rl/contexts/generic",
                    "https://schema.repronim.org/rl/activities/PHQ-9/phq9_context"
                ],
                "@type": "reproschema:Activity",
                "@id": "phq9_schema",
                "skos:prefLabel": "PHQ-9 Assessment",
                "schema:description": "PHQ-9 assessment schema",
                "schema:citation": "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1495268/",
                "preamble": {
                    "en": "Over the last 2 weeks, how often have you been bothered by any of the following problems?",
                    "es": "Durante las últimas 2 semanas, ¿con qué frecuencia le han molestado los siguintes problemas?"
                }
    }
    normalized_file = jsonld.normalize(doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})

This doesn't work on the JSON-LD playground either. how can I make this work? Does pyld support content negotiation/Is there a way to force accept-header?

umang0202 commented 4 years ago

Seems like this is a problem with schema.org contexts as well (https://github.com/schemaorg/schemaorg/issues/2578#issuecomment-632227864)

I was stuck in the same problem. Ended up using requests to get the context JSON separately and assign it to @context key at runtime. Then the pyld functions work!

Hope this helps

davidlehn commented 4 years ago

"https://schema.repronim.org/rl/activities/PHQ-9/phq9_context" is returning 405 as of today. Removing that URL and playground or pyld can expand things. If you want the normalize call to work the "@id": "phq9_schema" needs to be a valid URI. If you change that to "@id": "urn:phq9_schema", you'll get output.