gremlin - 与基于图形的版本相比,传统的 pdf 索引解决方案

标签 gremlin simplegraph

我的意图是索引包含 pdf 文件(以及其他文件类型)的任意目录,其中的关键字存储在列表中。我有一个传统的解决方案,我听说基于图形的解决方案使用例如SimpleGraph 可以更优雅/更高效并且独立于目录结构。

基于图形的解决方案(例如 SimpleGraph)会是什么样子?

传统解决方案

// https://stackoverflow.com/a/14051951/1497139
List<File> pdfFiles = this.explorePath(TestPDFFiles.RFC_DIRECTORY, "pdf");
List<PDFFile> pdfs = this.getPdfsFromFileList(pdfFiles);
…
for (PDFFile pdf:pdfs) {
     // https://stackoverflow.com/a/9560307/1497139
     if (org.apache.commons.lang3.StringUtils.containsIgnoreCase(pdf.getText(), keyWord)) {
          foundList.add(pdf.file.getName()); // here we access by structure (early binding)
          // - in the graph solution by name (late binding)
     }
}

最佳答案

基本上使用 SimpleGraph 你会使用模块的组合

  • 文件系统
  • PDF系统

  • 使用 FileSystem 模块,您可以收集目录中的文件图并过滤它以仅包含扩展名为 pdf 的文件 - 然后使用 PDFSystem 分析 PDF 以获取页面/文本结构 - 已经有一个测试用例simplegraph-bundle 模块展示了它如何使用一些 RFC pdf 作为输入。

    TestPDFFiles.java

    我现在添加了索引测试,见下文。

    核心功能取自旧测试,搜索单个关键字并允许将其作为参数:

    List<Object> founds = pdfSystem.g().V().hasLabel("page")
          .has("text", RegexPredicate.regex(".*" + keyWord + ".*")).in("pages")
          .dedup().values("name").toList();
    

    这是一个 gremlin 查询,只需一次调用即可通过搜索整个 PDF 文件树来完成大部分工作。我认为这更优雅,因为您不必关心输入的结构(树/图形/文件系统/数据库等......)

    JUnit 测试用例

     @Test
      /**
       * test for https://github.com/BITPlan/com.bitplan.simplegraph/issues/12
       */
      public void testPDFIndexing() throws Exception {
        FileSystem fs = getFileSystem(RFC_DIRECTORY);
        int limit = Integer.MAX_VALUE;
        PdfSystem pdfSystem = getPdfSystemForFileSystem(fs, limit);
        Map<String, List<String>> index = this.getIndex(pdfSystem, "ARPA",
            "proposal", "plan");
        // debug=true;
        if (debug) {
          for (Entry<String, List<String>> indexEntry : index.entrySet()) {
            List<String> fileNameList = indexEntry.getValue();
            System.out.println(String.format("%15s=%3d %s", indexEntry.getKey(),
                fileNameList.size(), fileNameList));
          }
        }
        assertEquals(14,index.get("ARPA").size());
        assertEquals(9,index.get("plan").size());
        assertEquals(8,index.get("proposal").size());
      }
    

    关于gremlin - 与基于图形的版本相比,传统的 pdf 索引解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51800068/

    相关文章:

    graph-databases - 从根节点遍历到所有节点并返回 OrientDB 图形数据库时聚合数据

    尽管设置了 mapred.job.tracker 值,Hadoop 1.2.1 仍以本地模式运行

    java - GroupCount 排序依据

    java - Gremlin 文件系统接口(interface)

    gremlin - TinkerPop:组合和过滤多个遍历的通用查询

    elasticsearch - 跨 token 化字段的Titan ES正则表达式查询?

    gremlin - 在 gremlin 中使用 store 和 select 关键字