Trying To-Do:
1) Execute Rapper functionality for each file in 'data' folder to get ntriples out of owl files.
2) Copy the resultant ntriples into another file as 'ntriples/output_file.ntriples'
3) Command : rapper -o ntriple ./data/file1.owl > ./ntriples/file2.ntriple
Tools used:
1) Rapper Redland libraries
2) System command executor code from Devdaily
3) Eclipse IDE
Issues:
1)No issues when I execute the following code:
/* 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;
}
The code just tries to execute rapper command for each file within 'data' folder and store it in parsedTriples variable. This works fine
2)When I try to copy the result to a file instead of keeping it in just a variable, it doesn't work but provides no error !!
Code: (definition for getTriples() remains the same)
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);
}
Project Structure:
Also, i have tried giving path "./ntriples/" instead of "../ntriples/". I am not sure why this is happening and need some pointers !! Thanks in advance !!
