# tests/cypher/corpus/library.jsonl, method list_model_classes_in_use
query: "CALL () { MATCH (mi:ModelInstance) WHERE EXISTS { MATCH (mi)<-[hr*1..12]-(:ExtractionResult)<-[:HAS_EXTRACTION]-(:StructureNode)<-[:HAS_STRUCTURE|HAS_CHILD*1..]-(:Document {path: $doc_path}) WHERE all(r IN hr WHERE type(r) STARTS WITH 'HAS_') } RETURN mi.model_class AS model_class, count(*) AS model_instances, 0 AS extraction_results UNION ALL MATCH (er:ExtractionResult) WHERE EXISTS { MATCH (er)<-[:HAS_EXTRACTION]-(:StructureNode)<-[:HAS_STRUCTURE|HAS_CHILD*1..]-(:Document {path: $doc_path}) } RETURN er.model_class AS model_class, 0 AS model_instances, count(*) AS extraction_results } WITH model_class, sum(model_instances) AS model_instances, sum(extraction_results) AS extraction_results WHERE model_class IS NOT NULL RETURN model_class, model_instances, extraction_results, model_instances + extraction_results AS count ORDER BY count DESC, model_class"
---
CallSubquery imports=()
  Union all=True
    Query
      Match optional=False
        Path var=None selector=None
          Node var=mi labels=(ModelInstance) props={} where=None
        where=(Exists #0)
          #0 Exists
            Match optional=False
              Path var=None selector=None
                Node var=mi labels=* props={} where=None
                Quantified min=1 max=12
                  Node var=__a0 labels=* props={} where=None
                  Rel var=hr types=* dir=in props={} where=None
                  Node var=__a1 labels=* props={} where=None
                Node var=__a2 labels=(ExtractionResult) props={} where=None
                Rel var=__r0 types=(HAS_EXTRACTION) dir=in props={} where=None
                Node var=__a3 labels=(StructureNode) props={} where=None
                Quantified min=1 max=None
                  Node var=__a4 labels=* props={} where=None
                  Rel var=__r1 types=(HAS_STRUCTURE|HAS_CHILD) dir=in props={} where=None
                  Node var=__a5 labels=* props={} where=None
                Node var=__a6 labels=(Document) props={path: (Param doc_path)} where=None
              where=(all r (Var hr) where=(STARTS WITH (Func type (Var r)) (Lit "HAS_")))
      Return distinct=False order=() skip=None limit=None
        model_class = (Prop (Var mi) model_class)
        model_instances = (CountStar)
        extraction_results = (Lit 0)
    Query
      Match optional=False
        Path var=None selector=None
          Node var=er labels=(ExtractionResult) props={} where=None
        where=(Exists #1)
          #1 Exists
            Match optional=False
              Path var=None selector=None
                Node var=er labels=* props={} where=None
                Rel var=__r2 types=(HAS_EXTRACTION) dir=in props={} where=None
                Node var=__a7 labels=(StructureNode) props={} where=None
                Quantified min=1 max=None
                  Node var=__a8 labels=* props={} where=None
                  Rel var=__r3 types=(HAS_STRUCTURE|HAS_CHILD) dir=in props={} where=None
                  Node var=__a9 labels=* props={} where=None
                Node var=__a10 labels=(Document) props={path: (Param doc_path)} where=None
              where=None
      Return distinct=False order=() skip=None limit=None
        model_class = (Prop (Var er) model_class)
        model_instances = (Lit 0)
        extraction_results = (CountStar)
With distinct=False order=() skip=None limit=None
  model_class = (Var model_class)
  model_instances = (Func sum (Var model_instances))
  extraction_results = (Func sum (Var extraction_results))
  where=(IS NOT NULL (Var model_class))
Return distinct=False order=((Var count) DESC, (Var model_class) ASC) skip=None limit=None
  model_class = (Var model_class)
  model_instances = (Var model_instances)
  extraction_results = (Var extraction_results)
  count = (+ (Var model_instances) (Var extraction_results))
