0

尝试待办事项:

1) 对“data”文件夹中的每个文件执行 Rapper 功能,以从 owl 文件中获取 ntriples。

2) 将生成的 ntriples 复制到另一个文件中作为 'ntriples/output_file.ntriples'

3)命令:rapper -o ntriple ./data/file1.owl > ./ntriples/file2.ntriple

使用的工具:

1)说唱歌手雷德兰图书馆

2)来自Devdaily的系统命令执行器代码

3) Eclipse IDE

问题

1)当我执行以下代码时没有问题:

        /* Running Commands for Multiple Files
     * for each file in the 'data' folder, call the rapper command
     * */
    List<String> commands = new ArrayList<String>();
    StringBuilder parsedTriples= new StringBuilder();
    final File folder = new File("./data/");

    //add commands
    commands.add("rapper");
    commands.add("-o");
    commands.add("ntriples");

    //walk the whole folder and retrieve the file path
    for (final File fileEntry : folder.listFiles()) {
        commands.add(fileEntry.getPath());
        parsedTriples.append(getTriples(commands));
        //System.out.println(parsedTriples.length());
        commands.remove(3);
    }
public static StringBuilder getTriples(List<String> commands) throws IOException, InterruptedException
{

    SystemCommandExecutor commandExecutor = new SystemCommandExecutor(commands);
    int result = commandExecutor.executeCommand();

    // stdout and stderr of the command are returned as StringBuilder objects
    StringBuilder stdout = commandExecutor.getStandardOutputFromCommand();
    StringBuilder stderr = commandExecutor.getStandardErrorFromCommand();

    return stdout;
}

该代码只是尝试为“数据”文件夹中的每个文件执行 rapper 命令并将其存储在 parsedTriples 变量中。这工作正常

2)当我尝试将结果复制到文件而不是将其保存在变量中时,它不起作用但没有错误!

代码:(getTriples() 的定义保持不变)

List<String> commands = new ArrayList<String>();
    StringBuilder parsedTriples= new StringBuilder();
    final File folder = new File("./data/");

    //add commands
    commands.add("rapper");
    commands.add("-o");
    commands.add("ntriples");

    //walk the whole folder and retrieve the file path
    for (final File fileEntry : folder.listFiles()) {

        commands.add(fileEntry.getPath());
        commands.add(">");
        String filePath="../ntriples/"+FilenameUtils.removeExtension(fileEntry.getName())+".ntriples";
        commands.add(filePath);
        parsedTriples.append(getTriples(commands));
        System.out.println(parsedTriples.length());
        //System.out.println(commands.get(0)+commands.get(1)+commands.get(2)+commands.get(3)+commands.get(4)+commands.get(5));
        commands.remove(5);
        commands.remove(4);
        commands.remove(3);
    }

项目结构:

项目结构

另外,我尝试给出路径“./ntriples/”而不是“../ntriples/”。我不确定为什么会发生这种情况,需要一些指示!提前致谢 !!

4

0 回答 0