本文介绍了neo4j:使用HEADER调用APOC.LOAD.HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下表

<table>
    <tr>
        <th> header 1</th>
        <th> header 2</th>
        <th> header 3</th>
    <tr>
        <td> keyword1 </td>
        <td> value1.2 </td>
        <td>
            <p> paragraph 1 </p>
        </td>
    </tr>
    <tr>
        <td> keyword2 </td>
        <td> value2.2 </td>
        <td>
            <p> paragraph 2 </p>
            <p> paragraph 3 </p>
        </td>
    </tr>
    <tr>
        <td> keyword3 </td>
        <td> value3.2</td>
        <td>
            <p> paragraph 1 </p>
            <p> paragraph 3 </p>
            <p> </p>
        </td>
    </tr>
</table>

您建议使用哪种方法通过apoc.load.html加载它和apoc.node.create或apoc.node.merge以便将标头动态用作节点属性名称?

What method you suggest to use to load it via apoc.load.htmland apoc.node.create or apoc.node.mergeso that headers are used dynamically as node properties names?

它应该创建与以下静态代码等效的动态代码:

It should create dynamic equivalent to the below static code:

MERGE(:node {name:keyword1, header2:value1.2})-[:R]->(:header3 {name:paragrap1})

MERGE(:node {name:keyword2, header2:value2.2})-[:R]->(:header3 {name:paragrap2})
MERGE(:node {name:keyword2, header2:value2.2})-[:R]->(:header3 {name:paragrap3})

MERGE(:node {name:keyword3, header2:value3.2})-[:R]->(:header3 {name:paragrap1})
MERGE(:node {name:keyword3, header2:value3.2})-[:R]->(:header3 {name:paragrap3})

我写了下面的代码...

I wrote the code below ...

// 999. SAMPLE CODE
CALL apoc.load.html("file:///C:/Users/sesa407003/Desktop/CURRENT%20PROJECTS/NEO4J/doc_start.html",{line: "table tr"}) yield value as lineList

CALL apoc.load.html("file:///doc_start.html",{header: "table tr th"}) yield value as headersList

UNWIND range(1, length(lineList.line) -1) as j
//with j,i,source
CALL apoc.load.html("file:///doc_start.html",{value: "table tr:eq("+j+") td"}) yield value as valueList
CALL apoc.merge.node(["node"], {name:valueList.value[2].text}) yield node as source
UNWIND range(0,length(headersList.header)-2) as i
CALL apoc.create.setProperties(source,[headersList.header[i].text],[valueList.value[i].text]) yield node
CALL apoc.load.html("file:///doc_start.html",{paragraphs: "table tr:eq("+j+") td:eq(2) p"}) yield value as paragraphsList
UNWIND paragraphsList.paragraphs as paragraph
MERGE(target:dashboard {name:paragraph.text})
MERGE(source)-[:R]->(target)
return *

这似乎可行...但是当我尝试删除空的段落时,例如关键字3的最后一个……我找不到WHERE或CASE WHEN或apoc.case.when的正确语法

It seems to work ... but when I try to remove empty paragraphs, like the last on keyword3 ... I don't find the right syntax for WHERE or CASE WHEN or apoc.case.when

推荐答案

我查看了您的密码并进行了一些更改.我希望它可以使您更接近最终状态.

I took a look at your cypher and made a few changes. I expect it gets you closer to your end state.

要删除空的段落,我添加了这个小的WITH

To remove the empty paragraph I added this little WITH block

WITH source, paragraph.text AS para
WHERE trim(para) <> ""

我还更改了一些数组索引以从表中获取正确的数据.

I also changed a few of the array indexes to get the right data from the table.

CALL apoc.load.html("file:///table.html",{line: "table tr"}) yield value as lineList
CALL apoc.load.html("file:///table.html",{header: "table tr th"}) yield value as headersList
UNWIND range(1, size(lineList.line) - 1) as j
CALL apoc.load.html("file:///table.html",{value: "table tr:eq("+j+") td"}) yield value as valueList
CALL apoc.merge.node(["node"], {name:valueList.value[0].text}) yield node as source
UNWIND range(0,size(headersList.header)-2) as i
CALL apoc.create.setProperties(source,[headersList.header[i].text],[valueList.value[i].text]) yield node
CALL apoc.load.html("file:///table.html",{paragraphs: "table tr:eq("+j+") td:eq(2) p"}) yield value as paragraphsList
UNWIND paragraphsList.paragraphs as paragraph
WITH source, paragraph.text AS para
WHERE trim(para) <> ""
MERGE(target:dashboard {name:para})
MERGE(source)-[:R]->(target)
RETURN *

这篇关于neo4j:使用HEADER调用APOC.LOAD.HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-19 15:21