文件系统的 Gremlin 接口
Gremlin Interface for Filesystem
文件系统具有树形或图形结构(取决于您是否允许硬链接或符号链接)。
我正在寻找一种方法来使用 Gremlin 查询来遍历文件系统。
我试着用一些软件来包装文件系统见
https://github.com/BITPlan/com.bitplan.simplegraph
有一个 JUnit 测试表明一切正常。
例如。像
这样的遍历
GraphTraversal<Vertex, Vertex> javaFiles = start.g().V().has("ext", "java");
long javaFileCount=javaFiles.count().next().longValue();
有效。
我不喜欢这个实现的地方是它在某些部分看起来像 Gremlin,例如有 recursiveOut 函数作为解决方法,而不是使用适当的 repeat() 可用。递归也有缺陷,因为它处理中间 ArrayLists 的效率很低。
更糟糕的是,在使用 gremlin 方法开始遍历之前,包装必须访问所有文件以获得正确的图形。我宁愿有一个实现,其中遍历步骤将导致在进行遍历时访问文件系统中的相应文件或目录。
code/approach如何改进才能更接近上述目标?
或者 - 如果有一些 better/comparable 实现已经可以完成我所描述的,那么改进可能不值得。
您知道哪些基于 Apache Tinkerpop/Gremlin 的文件系统遍历 API?
JUnit测试展示原理
package com.bitplan.simplegraph;
import static org.junit.Assert.assertEquals;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Test;
import com.bitplan.filesystem.FileNode;
import com.bitplan.filesystem.FileSystem;
import com.bitplan.simplegraph.SimpleSystem;
/**
* test navigating the Filesystem with SimpleGraph approaches
* @author wf
*
*/
public class TestFileSystem {
boolean debug=true;
@Test
public void testFileSystem() throws Exception {
SimpleSystem fs=new FileSystem();
FileNode start = (FileNode) fs.moveTo("src");
if (debug)
start.printNameValues(System.out);
start.recursiveOut("files",Integer.MAX_VALUE).forEach(childFile->{
if (debug)
childFile.printNameValues(System.out);
});
long filecount = start.g().V().count().next().longValue();
if (debug)
System.out.println(filecount);
assertEquals(25,filecount);
GraphTraversal<Vertex, Vertex> javaFiles = start.g().V().has("ext", "java");
long javaFileCount=javaFiles.count().next().longValue();
assertEquals(10,javaFileCount);
javaFiles.forEachRemaining(javaFile-> {
for (String key:javaFile.keys()) {
if (debug)
System.out.println(String.format("%s = %s", key, javaFile.property(key).value()));
}
//Map<String, Object> javaFileMap =javaFile.valueMap().next();
//javaFileMap.forEach((k, v) -> System.out.println(String.format("%s = %s", k, v)));
});
}
}
具有所需的能力。
// create a new FileSystem access supplying the result as a SimpleSystem API
SimpleSystem fs=new FileSystem();
// connect to this system with no extra information (e.g. no credentials) and move to the "src" node
SimpleNode start = fs.connect("").moveTo("src");
// do gremlin style out traversals recusively to any depth
start.recursiveOut("files",Integer.MAX_VALUE);
文件系统具有树形或图形结构(取决于您是否允许硬链接或符号链接)。
我正在寻找一种方法来使用 Gremlin 查询来遍历文件系统。 我试着用一些软件来包装文件系统见
https://github.com/BITPlan/com.bitplan.simplegraph
有一个 JUnit 测试表明一切正常。 例如。像
这样的遍历GraphTraversal<Vertex, Vertex> javaFiles = start.g().V().has("ext", "java");
long javaFileCount=javaFiles.count().next().longValue();
有效。
我不喜欢这个实现的地方是它在某些部分看起来像 Gremlin,例如有 recursiveOut 函数作为解决方法,而不是使用适当的 repeat() 可用。递归也有缺陷,因为它处理中间 ArrayLists 的效率很低。
更糟糕的是,在使用 gremlin 方法开始遍历之前,包装必须访问所有文件以获得正确的图形。我宁愿有一个实现,其中遍历步骤将导致在进行遍历时访问文件系统中的相应文件或目录。
code/approach如何改进才能更接近上述目标?
或者 - 如果有一些 better/comparable 实现已经可以完成我所描述的,那么改进可能不值得。
您知道哪些基于 Apache Tinkerpop/Gremlin 的文件系统遍历 API?
JUnit测试展示原理
package com.bitplan.simplegraph;
import static org.junit.Assert.assertEquals;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Test;
import com.bitplan.filesystem.FileNode;
import com.bitplan.filesystem.FileSystem;
import com.bitplan.simplegraph.SimpleSystem;
/**
* test navigating the Filesystem with SimpleGraph approaches
* @author wf
*
*/
public class TestFileSystem {
boolean debug=true;
@Test
public void testFileSystem() throws Exception {
SimpleSystem fs=new FileSystem();
FileNode start = (FileNode) fs.moveTo("src");
if (debug)
start.printNameValues(System.out);
start.recursiveOut("files",Integer.MAX_VALUE).forEach(childFile->{
if (debug)
childFile.printNameValues(System.out);
});
long filecount = start.g().V().count().next().longValue();
if (debug)
System.out.println(filecount);
assertEquals(25,filecount);
GraphTraversal<Vertex, Vertex> javaFiles = start.g().V().has("ext", "java");
long javaFileCount=javaFiles.count().next().longValue();
assertEquals(10,javaFileCount);
javaFiles.forEachRemaining(javaFile-> {
for (String key:javaFile.keys()) {
if (debug)
System.out.println(String.format("%s = %s", key, javaFile.property(key).value()));
}
//Map<String, Object> javaFileMap =javaFile.valueMap().next();
//javaFileMap.forEach((k, v) -> System.out.println(String.format("%s = %s", k, v)));
});
}
}
具有所需的能力。
// create a new FileSystem access supplying the result as a SimpleSystem API
SimpleSystem fs=new FileSystem();
// connect to this system with no extra information (e.g. no credentials) and move to the "src" node
SimpleNode start = fs.connect("").moveTo("src");
// do gremlin style out traversals recusively to any depth
start.recursiveOut("files",Integer.MAX_VALUE);