liveBook · Manning

Co-occurrence

As explained in Knowledge Graphs and LLMs in Action

Co-occurrence is the presence of two or more medical entities within the same sentence or textual context.

Co-occurrence records two or more medical entities mentioned in the same sentence or textual context. In a knowledge graph, it projects Page nodes onto MedicalEntity nodes and makes their textual proximity explicit through COOCCURR relationships. section 7.6.5

Co-occurrence is a starting point rather than a semantic explanation. Traversing ontology paths can validate why entities appear together, interpret their relationship, or discover connections absent from the sentence and biomedical ontology assumptions. section 7.7.3

From co-occurrence to ontology meaning

AIDS and Hepatitis co-occur in blood-donation guidance because both represent infectious-disease risks. SNOMED paths connect them through infectious disease and inflammatory disorder of liver, while additional paths expose liver and immune-system associations. Similar queries retrieve disease entities and surrounding text for Zika virus, or match co-occurring phenotypic features to HPO disease entities.

Listing 7.23 Creating co-occurrence relationships at the sentence level
CALL apoc.periodic.iterate(
  "MATCH (n:Page) WHERE exists( (n)-[:MENTIONS_ENTITY]->(:MedicalEntity) )
  RETURN n", 
  "MATCH (n)-[r:MENTIONS_ENTITY]->(m:MedicalEntity)
  WITH n, r.sentence_index as sentences, m 
  UNWIND sentences as sentence
  WITH n, sentence, collect(distinct m) as entities

  UNWIND range(0, size(entities)-2) as i
  UNWIND range(i+1, size(entities)-1) as j

  WITH n, sentence, entities, i, j
  MATCH (m1) WHERE id(m1) = id(entities[i])
  MATCH (m2) WHERE id(m2) = id(entities[j])

  WITH n, sentence, entities, i, j, m1, m2
  MERGE (m1)-[s:COOCCURR]-(m2)
  ON CREATE SET s.count = 1, 
       s.sentences = [sentence]
  ON MATCH SET s.count = s.count + 1, 
   s.sentences = s.sentences + sentence", 
{batchSize: 50})

Inspect the Cypher and APOC query that groups mentions by sentence, generates entity pairs, and maintains COOCCURR counts and sentence lists. section 7.6.5

How Knowledge Graphs and LLMs in Action covers it

How deep it goes
Explains sentence-level pair generation, relationship aggregation, context retrieval, and ontology traversal, but not entity extraction itself.
Examples
Uses AIDS–Hepatitis, Zika virus–disease, and HPO disease–phenotype pairs with sentence context and ontology paths.
What it assumes
Assumes disambiguated medical entities, sentence-indexed mentions, a knowledge graph, and ontology relationships.
What you can do after
Apply via Cypher and APOC to create, rank, contextualize, validate, and explore medical-entity co-occurrences.
How it connects
Connects named entity disambiguation, knowledge graphs, ontologies, SNOMED, HPO, and medical entity linking.

Also explained in

Compare how 3 books explain co-occurrence →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Knowledge Graphs and LLMs in Action. The section links point to the parts of the book it draws on.