Cypher

From TEIWiki
Revision as of 20:05, 25 January 2019 by Andreas Kuczera (talk | contribs) (Created page with " // Export TEI-Graph to Standoff-Property-JSON-Format match path=(d:XmlDocument)-[:NE*]->(e:XmlCharacters) where not (e)-[:NE]->() with tail(nodes(path)) as words, d with reduce(...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

// Export TEI-Graph to Standoff-Property-JSON-Format match path=(d:XmlDocument)-[:NE*]->(e:XmlCharacters) where not (e)-[:NE]->() with tail(nodes(path)) as words, d with reduce(s="", x in words| s + x.text ) as allText, d call apoc.path.expandConfig(d,{

  relationshipFilter: '<IS_CHILD_OF',
  labelFilter: 'XmlTag',
  bfs: false,
  minLevel: 1

}) yield path with allText, path, nodes(path)[-1] as this MATCH p=(this)-[:NEXT*]->(x) where (x)-[:LAST_CHILD_OF*]->(this) and any(x in nodes(p) WHERE x:XmlCharacters) with allText, this, collect(p)[-1] as longest with allText, this, [x in nodes(longest) where x:XmlCharacters] as xmlCharacters with allText, this,

 apoc.coll.min([x in xmlCharacters | x.startIndex]) as min, 
 apoc.coll.max([x in xmlCharacters | x.endIndex]) as max, 
 apoc.text.join([x in xmlCharacters | x.text], "") as text

with allText, {

  index:id(this), 
  startIndex: min, 
  endIndex: max,
  text: text,
  type: this._name,
  attributes: apoc.map.fromPairs([x in keys(this) WHERE not x starts with "_" | [x, this[x]] ])

} as standoffProperty return {text: allText, properties: collect(standoffProperty)};