Парсинг JSON, полученный из stanbol, содержащий отношения

У меня есть JSON, как это:

{
  "@context": {
    "comment": "http://www.w3.org/2000/01/rdf-schema#comment",
    "confidence": {
      "@id": "http://fise.iks-project.eu/ontology/confidence",
      "@type": "http://www.w3.org/2001/XMLSchema#double"
    },
    "created": {
      "@id": "http://purl.org/dc/terms/created",
      "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
    },
    "creator": {
      "@id": "http://purl.org/dc/terms/creator",
      "@type": "http://www.w3.org/2001/XMLSchema#string"
    },
    "depiction": {
      "@id": "http://xmlns.com/foaf/0.1/depiction",
      "@type": "@id"
    },
    "end": {
      "@id": "http://fise.iks-project.eu/ontology/end",
      "@type": "http://www.w3.org/2001/XMLSchema#int"
    },
    "Enhancement": "http://fise.iks-project.eu/ontology/Enhancement",
    "entity-label": "http://fise.iks-project.eu/ontology/entity-label",
    "entity-reference": {
      "@id": "http://fise.iks-project.eu/ontology/entity-reference",
      "@type": "@id"
    },
    "EntityAnnotation": "http://fise.iks-project.eu/ontology/EntityAnnotation",
    "entityRank": {
      "@id": "http://stanbol.apache.org/ontology/entityhub/entityhub#entityRank",
      "@type": "http://www.w3.org/2001/XMLSchema#float"
    },
    "extracted-from": {
      "@id": "http://fise.iks-project.eu/ontology/extracted-from",
      "@type": "@id"
    },
    "label": "http://www.w3.org/2000/01/rdf-schema#label",
    "language": "http://purl.org/dc/terms/language",
    "LinguisticSystem": "http://purl.org/dc/terms/LinguisticSystem",
    "Person": "http://dbpedia.org/ontology/Person",
    "relation": {
      "@id": "http://purl.org/dc/terms/relation",
      "@type": "@id"
    },
    "score": {
      "@id": "http://stanbol.apache.org/ontology/entityhub/query#score",
      "@type": "http://www.w3.org/2001/XMLSchema#float"
    },
    "selected-text": "http://fise.iks-project.eu/ontology/selected-text",
    "selection-context": "http://fise.iks-project.eu/ontology/selection-context",
    "site": "http://stanbol.apache.org/ontology/entityhub/entityhub#site",
    "start": {
      "@id": "http://fise.iks-project.eu/ontology/start",
      "@type": "http://www.w3.org/2001/XMLSchema#int"
    },
    "TextAnnotation": "http://fise.iks-project.eu/ontology/TextAnnotation",
    "type": {
      "@id": "http://purl.org/dc/terms/type",
      "@type": "@id"
    },
    "xsd": "http://www.w3.org/2001/XMLSchema#"
  },
  "@graph": [
    {
      "@id": "http://dbpedia.org/resource/Christian",
      "comment": {
        "@language": "en",
        "@value": "A Christian (is a person who adheres to Christianity, an Abrahamic, monotheistic religion based on the life and teachings of Jesus of Nazareth as recorded in the Canonical gospels and the letters of the New Testament. \"Christian\" derives from the Koine Greek word Christ, a translation of the Biblical Hebrew term Messiah."
      },
      "depiction": [
        "http://upload.wikimedia.org/wikipedia/commons/1/11/Santuário_de_Fátima_modified.jpg",
        "http://upload.wikimedia.org/wikipedia/commons/4/40/Famous_Christians.jpg",
        "http://upload.wikimedia.org/wikipedia/commons/9/95/BegaPrayer.jpg",
        "http://upload.wikimedia.org/wikipedia/commons/9/96/Bloch-SermonOnTheMount.jpg",
        "http://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Santuário_de_Fátima_modified.jpg/200px-Santuário_de_Fátima_modified.jpg",
        "http://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Famous_Christians.jpg/200px-Famous_Christians.jpg",
        "http://upload.wikimedia.org/wikipedia/commons/thumb/9/95/BegaPrayer.jpg/200px-BegaPrayer.jpg",
        "http://upload.wikimedia.org/wikipedia/commons/thumb/9/96/Bloch-SermonOnTheMount.jpg/200px-Bloch-SermonOnTheMount.jpg"
      ],
      "entityRank": 0.71846753,
      "label": {
        "@language": "en",
        "@value": "Christian"
      },
      "score": 17.521954
    },
    {
      "@id": "http://dbpedia.org/resource/Thursday",
      "comment": {
        "@language": "en",
        "@value": "Thursday is the fourth or fifth day of the week. According to the ISO 8601 international standard adopted in most western countries, it is the fourth day of the week. In most of the world, countries use the Sunday-first convention and it is defined as the fifth day of the week. It is the fifth day of the week in the Judeo-Christian calendar as well, and was defined so in the ancient Mesopotamian and biblical calendars. It falls between Wednesday and Friday."
      },
      "depiction": [
        "http://upload.wikimedia.org/wikipedia/commons/2/23/Thor.jpg",
        "http://upload.wikimedia.org/wikipedia/commons/thumb/2/23/Thor.jpg/200px-Thor.jpg"
      ],
      "entityRank": 0.40759254,
      "label": {
        "@language": "en",
        "@value": "Thursday"
      },
      "score": 1.9757141
    },
    {
      "@id": "urn:enhancement-1a2ffccb-5f8c-2743-803b-3581b9af8bf8",
      "@type": [
        "Enhancement",
        "EntityAnnotation"
      ],
      "confidence": 0.80999994,
      "created": "2013-07-11T19:44:44.827Z",
      "creator": "org.apache.stanbol.enhancer.engines.entitylinking.engine.EntityLinkingEngine",
      "entity-label": {
        "@language": "en",
        "@value": "Christians"
      },
      "entity-reference": "http://dbpedia.org/resource/Christian",
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "relation": "urn:enhancement-59dcea1a-0f7d-a7b6-6a38-031e76794ad7",
      "site": "dbpedia"
    },
    {
      "@id": "urn:enhancement-2921ff7f-d1d9-b32d-8624-b8ea01b2ea48",
      "@type": [
        "Enhancement",
        "EntityAnnotation"
      ],
      "confidence": 0.79012346,
      "created": "2013-07-11T19:44:44.827Z",
      "creator": "org.apache.stanbol.enhancer.engines.entitylinking.engine.EntityLinkingEngine",
      "entity-label": {
        "@language": "en",
        "@value": "Thursdays"
      },
      "entity-reference": "http://dbpedia.org/resource/Thursday",
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "relation": "urn:enhancement-f5f80742-e71b-718f-ead9-753aa145b5ff",
      "site": "dbpedia"
    },
    {
      "@id": "urn:enhancement-2fe7fd43-bb49-3667-ab1f-63a0936ede7f",
      "@type": [
        "Enhancement",
        "TextAnnotation"
      ],
      "confidence": 0.999996,
      "created": "2013-07-11T19:44:44.795Z",
      "creator": "org.apache.stanbol.enhancer.engines.langdetect.LanguageDetectionEnhancementEngine",
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "language": "en",
      "type": "LinguisticSystem"
    },
    {
      "@id": "urn:enhancement-59dcea1a-0f7d-a7b6-6a38-031e76794ad7",
      "@type": [
        "Enhancement",
        "TextAnnotation"
      ],
      "confidence": 1.0,
      "created": "2013-07-11T19:44:44.827Z",
      "creator": "org.apache.stanbol.enhancer.engines.entitylinking.engine.EntityLinkingEngine",
      "end": 56,
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "selected-text": {
        "@language": "en",
        "@value": "Christian"
      },
      "selection-context": {
        "@language": "en",
        "@value": "ed a Christian uni"
      },
      "start": 47
    },
    {
      "@id": "urn:enhancement-5f9962d4-cc34-86ed-27cc-2db4c96506f4",
      "@type": [
        "Enhancement",
        "EntityAnnotation"
      ],
      "confidence": 1.0,
      "created": "2013-07-11T19:44:44.826Z",
      "creator": "org.apache.stanbol.enhancer.engines.entitylinking.engine.EntityLinkingEngine",
      "entity-label": {
        "@language": "en",
        "@value": "President Barack Obama"
      },
      "entity-reference": "http://dbpedia.org/resource/Presidency_of_Barack_Obama",
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "relation": "urn:enhancement-837e5beb-6e54-3947-fffa-b619c22845b0",
      "site": "dbpedia"
    },
    {
      "@id": "urn:enhancement-710fe84c-108b-6964-6242-a0379b54c1c3",
      "@type": [
        "Enhancement",
        "EntityAnnotation"
      ],
      "confidence": 1.0,
      "created": "2013-07-11T19:44:44.827Z",
      "creator": "org.apache.stanbol.enhancer.engines.entitylinking.engine.EntityLinkingEngine",
      "entity-label": {
        "@language": "en",
        "@value": "Christian"
      },
      "entity-reference": "http://dbpedia.org/resource/Christian",
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "relation": "urn:enhancement-59dcea1a-0f7d-a7b6-6a38-031e76794ad7",
      "site": "dbpedia"
    },
    {
      "@id": "urn:enhancement-837e5beb-6e54-3947-fffa-b619c22845b0",
      "@type": [
        "Enhancement",
        "TextAnnotation"
      ],
      "confidence": 1.0,
      "created": "2013-07-11T19:44:44.826Z",
      "creator": "org.apache.stanbol.enhancer.engines.entitylinking.engine.EntityLinkingEngine",
      "end": 133,
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "selected-text": {
        "@language": "en",
        "@value": "President Barack Obama"
      },
      "selection-context": {
        "@language": "en",
        "@value": "t of President Barack Obama's 2"
      },
      "start": 111
    },
    {
      "@id": "urn:enhancement-a7618904-adc4-f20c-0942-15b63affa456",
      "@type": [
        "Enhancement",
        "EntityAnnotation"
      ],
      "confidence": 1.0,
      "created": "2013-07-11T19:44:44.827Z",
      "creator": "org.apache.stanbol.enhancer.engines.entitylinking.engine.EntityLinkingEngine",
      "entity-label": {
        "@language": "en",
        "@value": "Thursday"
      },
      "entity-reference": "http://dbpedia.org/resource/Thursday",
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "relation": "urn:enhancement-f5f80742-e71b-718f-ead9-753aa145b5ff",
      "site": "dbpedia"
    },
    {
      "@id": "urn:enhancement-bd5d020c-0685-74d4-a26a-1d504c406bc8",
      "@type": [
        "Enhancement",
        "EntityAnnotation"
      ],
      "confidence": 0.75,
      "created": "2013-07-11T19:44:44.826Z",
      "creator": "org.apache.stanbol.enhancer.engines.entitylinking.engine.EntityLinkingEngine",
      "entity-label": {
        "@language": "en",
        "@value": "President Barack Hussein Obama"
      },
      "entity-reference": "http://dbpedia.org/resource/Barack_Obama",
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "relation": "urn:enhancement-837e5beb-6e54-3947-fffa-b619c22845b0",
      "site": "dbpedia"
    },
    {
      "@id": "urn:enhancement-ca172daa-8c72-810b-07e8-99f123cce395",
      "@type": [
        "Enhancement",
        "TextAnnotation"
      ],
      "confidence": 0.88367766,
      "created": "2013-07-11T19:44:44.815Z",
      "creator": "org.apache.stanbol.enhancer.engines.opennlp.impl.NamedEntityExtractionEnhancementEngine",
      "end": 133,
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "selected-text": {
        "@language": "en",
        "@value": "Barack Obama"
      },
      "selection-context": {
        "@language": "en",
        "@value": "A federal appeals court on Thursday rejected a Christian university's religion-based challenge against part of President Barack Obama's 2010 healthcare overhaul, which the school claimed had forced taxpayers and employers to subsidize abortions and contraception."
      },
      "start": 121,
      "type": "Person"
    },
    {
      "@id": "urn:enhancement-e6aff5ba-1089-2d0e-763c-30a2347663c7",
      "@type": [
        "Enhancement",
        "EntityAnnotation"
      ],
      "confidence": 0.77049375,
      "created": "2013-07-11T19:44:44.826Z",
      "creator": "org.apache.stanbol.enhancer.engines.entitylinking.engine.EntityLinkingEngine",
      "entity-label": {
        "@language": "en",
        "@value": "President barack obama"
      },
      "entity-reference": "http://dbpedia.org/resource/Barack_Obama",
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "relation": "urn:enhancement-837e5beb-6e54-3947-fffa-b619c22845b0",
      "site": "dbpedia"
    },
    {
      "@id": "urn:enhancement-f5f80742-e71b-718f-ead9-753aa145b5ff",
      "@type": [
        "Enhancement",
        "TextAnnotation"
      ],
      "confidence": 1.0,
      "created": "2013-07-11T19:44:44.826Z",
      "creator": "org.apache.stanbol.enhancer.engines.entitylinking.engine.EntityLinkingEngine",
      "end": 35,
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "selected-text": {
        "@language": "en",
        "@value": "Thursday"
      },
      "selection-context": {
        "@language": "en",
        "@value": "t on Thursday rej"
      },
      "start": 27
    }
  ]
}

Мне не нужно использовать @context. Нужен только '@graph'. Теперь внутри '@graph' есть несколько массивов, и мне нужно найти значение 'entity-reference' из массива, который его содержит (не у всех массивов есть). Теперь массив, который будет иметь этот ключ 'entity-reference', также будет иметь ключ 'отношение', используя который я должен искать в массиве, чей ключ '@id' имеет значение, равное 'отношению', тогда из этого массива мне снова нужно найти ключ.

Пример:

Этот массив содержит ключи "сущность-ссылка" и "отношение":

    {
      "@id": "urn:enhancement-e6aff5ba-1089-2d0e-763c-30a2347663c7",
      "@type": [
        "Enhancement",
        "EntityAnnotation"
      ],
      "confidence": 0.77049375,
      "created": "2013-07-11T19:44:44.826Z",
      "creator": "org.apache.stanbol.enhancer.engines.entitylinking.engine.EntityLinkingEngine",
      "entity-label": {
        "@language": "en",
        "@value": "President barack obama"
      },
      "entity-reference": "http://dbpedia.org/resource/Barack_Obama",
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "relation": "urn:enhancement-837e5beb-6e54-3947-fffa-b619c22845b0",
      "site": "dbpedia"
    }

Из этого я извлеку "entity-reference": "http://dbpedia.org/resource/Barack_Obama" а затем будет искать массив, чей '@id' "relation": "urn:enhancement-837e5beb-6e54-3947-fffa-b619c22845b0"

который:

    {
      "@id": "urn:enhancement-837e5beb-6e54-3947-fffa-b619c22845b0",
      "@type": [
        "Enhancement",
        "TextAnnotation"
      ],
      "confidence": 1.0,
      "created": "2013-07-11T19:44:44.826Z",
      "creator": "org.apache.stanbol.enhancer.engines.entitylinking.engine.EntityLinkingEngine",
      "end": 133,
      "extracted-from": "urn:content-item-sha1-8a5c1ec376eec1d1f0ca4567c920100eac62c44e",
      "selected-text": {
        "@language": "en",
        "@value": "President Barack Obama"
      },
      "selection-context": {
        "@language": "en",
        "@value": "t of President Barack Obama's 2"
      },
      "start": 111
    } 

Так есть ли у меня такой вид поиска с JSON?

0 ответов

Другие вопросы по тегам