最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - rdflib removes duplicate values for a jsonld property which is an array of values - Stack Overflow

programmeradmin4浏览0评论

I have a jsonld representation of triples :

{"@id": "some-id",
    "@type": "Row",
    "attendance": 74439,
    "average_cards_per_match_pre_match": 0,
    "average_corners_per_match_pre_match": 0,
    "average_goals_per_match_pre_match": 0,
    "my_field" : [-0.0368623323738575, 0.06313438713550568,
 -0.05376605689525604, -0.0368623323738575, 0.06313438713550568, -0.05376605689525604]
}

When parsing using rdflib :

g = Graph()
    g.parse(
        data=json.dumps(jsonld_response),
        format="json-ld",
        context={
            "@vocab": "/",
            "@language": "en",
            "rdfs": ";,
        },
    )
g.serialize(format="xml")

The duplicate values of the my_field are removed and only three triples are created in the resultant rdfxml.

<my_field rdf:datatype=";>-0.0368623323738575</my_field>
    <my_field rdf:datatype=";>0.06313438713550568</my_field>
    <my_field rdf:datatype=";>-0.05376605689525604</my_field>

Is there a way to make sure duplicate values are not truncated?

I have a jsonld representation of triples :

{"@id": "some-id",
    "@type": "Row",
    "attendance": 74439,
    "average_cards_per_match_pre_match": 0,
    "average_corners_per_match_pre_match": 0,
    "average_goals_per_match_pre_match": 0,
    "my_field" : [-0.0368623323738575, 0.06313438713550568,
 -0.05376605689525604, -0.0368623323738575, 0.06313438713550568, -0.05376605689525604]
}

When parsing using rdflib :

g = Graph()
    g.parse(
        data=json.dumps(jsonld_response),
        format="json-ld",
        context={
            "@vocab": "http://example/test/",
            "@language": "en",
            "rdfs": "http://www.w3./2000/01/rdf-schema#",
        },
    )
g.serialize(format="xml")

The duplicate values of the my_field are removed and only three triples are created in the resultant rdfxml.

<my_field rdf:datatype="http://www.w3./2001/XMLSchema#double">-0.0368623323738575</my_field>
    <my_field rdf:datatype="http://www.w3./2001/XMLSchema#double">0.06313438713550568</my_field>
    <my_field rdf:datatype="http://www.w3./2001/XMLSchema#double">-0.05376605689525604</my_field>

Is there a way to make sure duplicate values are not truncated?

Share Improve this question asked Mar 19 at 13:02 RishabhgRishabhg 1189 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

In RDF a statement is either stated or not stated and there is no order of statements. It does not make a difference, whether you state a statement once, twice, … and in which order you state them. If repetition or order of values matters, you can e.g. use an rdf:List. To state an rdf:List in JSON-LD, you can extend the context in your case by:

"my_field": {
  "@container": "@list"
}

This should cause the parser to consider the array values as members of an rdf:List.

发布评论

评论列表(0)

  1. 暂无评论