|
a/src/main/java/net/timbusproject/dpes/alternative/kb/VirtualPackageAlternativeIdentifier.java |
|
b/src/main/java/net/timbusproject/dpes/alternative/kb/VirtualPackageAlternativeIdentifier.java |
|
... |
|
... |
31 |
import java.util.LinkedHashMap;
|
31 |
import java.util.LinkedHashMap;
|
32 |
import java.util.Map;
|
32 |
import java.util.Map;
|
33 |
import java.util.Map.Entry;
|
33 |
import java.util.Map.Entry;
|
34 |
import java.util.Scanner;
|
34 |
import java.util.Scanner;
|
35 |
import java.util.Set;
|
35 |
import java.util.Set;
|
36 |
import java.util.zip.GZIPOutputStream;
|
|
|
37 |
|
36 |
|
38 |
import org.apache.commons.cli.BasicParser;
|
37 |
import org.apache.commons.cli.BasicParser;
|
39 |
import org.apache.commons.cli.CommandLine;
|
38 |
import org.apache.commons.cli.CommandLine;
|
40 |
import org.apache.commons.cli.CommandLineParser;
|
39 |
import org.apache.commons.cli.CommandLineParser;
|
41 |
import org.apache.commons.cli.HelpFormatter;
|
40 |
import org.apache.commons.cli.HelpFormatter;
|
|
... |
|
... |
60 |
import org.semanticweb.owlapi.model.OWLOntologyManager;
|
59 |
import org.semanticweb.owlapi.model.OWLOntologyManager;
|
61 |
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
|
60 |
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
|
62 |
|
61 |
|
63 |
import uk.ac.manchester.cs.owl.owlapi.OWLOntologyImpl;
|
62 |
import uk.ac.manchester.cs.owl.owlapi.OWLOntologyImpl;
|
64 |
|
63 |
|
65 |
import com.thoughtworks.xstream.XStream;
|
64 |
/**
|
66 |
import com.thoughtworks.xstream.io.xml.DomDriver;
|
65 |
* @author Rudolf Mayer
|
67 |
|
66 |
*/
|
68 |
public class VirtualPackageAlternativeIdentifier {
|
67 |
public class VirtualPackageAlternativeIdentifier {
|
|
|
68 |
public static final String PATH_KNOWDLEDGE_BASE = "knowledgeBases:softwareAlternatives:".replace(':', File.separatorChar);
|
|
|
69 |
|
69 |
public static final IRI IRI_CUDF = IRI.create("http://timbus.teco.edu/ontologies/DSOs/CUDF.owl");
|
70 |
public static final IRI IRI_CUDF = IRI.create("http://timbus.teco.edu/ontologies/DSOs/CUDF.owl");
|
70 |
|
71 |
|
71 |
public static final IRI IRI_CUDF_PACKAGE = IRI.create(IRI_CUDF.toString() + "#Package");
|
72 |
public static final IRI IRI_CUDF_PACKAGE = IRI.create(IRI_CUDF.toString() + "#Package");
|
72 |
|
73 |
|
73 |
public static final IRI IRI_CUDF_VIRTUALPACKAGE = IRI.create(IRI_CUDF.toString() + "#VirtualPackage");
|
74 |
public static final IRI IRI_CUDF_VIRTUALPACKAGE = IRI.create(IRI_CUDF.toString() + "#VirtualPackage");
|
|
... |
|
... |
81 |
|
82 |
|
82 |
public static final String IRIPREFIX_KB_PACKAGE_ALTERNATIVES = "http://timbus.teco.edu/ontologies/KB/PackageAlternatives";
|
83 |
public static final String IRIPREFIX_KB_PACKAGE_ALTERNATIVES = "http://timbus.teco.edu/ontologies/KB/PackageAlternatives";
|
83 |
|
84 |
|
84 |
public static final OWLObjectProperty OBJECTPROPERTY_CUDF_PROVIDES = OWLManager.getOWLDataFactory().getOWLObjectProperty(
|
85 |
public static final OWLObjectProperty OBJECTPROPERTY_CUDF_PROVIDES = OWLManager.getOWLDataFactory().getOWLObjectProperty(
|
85 |
IRI.create(IRI_CUDF.toString() + "#", "provides"));
|
86 |
IRI.create(IRI_CUDF.toString() + "#", "provides"));
|
86 |
|
|
|
87 |
private static final XStream xStream = new XStream(new DomDriver());
|
|
|
88 |
|
|
|
89 |
private static final String PATH = "knowledgeBases:softwareAlternatives:".replace(':', File.separatorChar);
|
|
|
90 |
|
87 |
|
91 |
private static final String completeOntologyKey = "complete";
|
88 |
private static final String completeOntologyKey = "complete";
|
92 |
|
89 |
|
93 |
public static PrintWriter log;
|
90 |
public static PrintWriter log;
|
94 |
|
91 |
|
|
... |
|
... |
215 |
public void storeResults(HashMap<String, HashMap<String, Set<String>>> packagesProviders) throws IOException {
|
212 |
public void storeResults(HashMap<String, HashMap<String, Set<String>>> packagesProviders) throws IOException {
|
216 |
System.out.println("Storing results");
|
213 |
System.out.println("Storing results");
|
217 |
String osName = OSIdentifier.getEscapedOSString();
|
214 |
String osName = OSIdentifier.getEscapedOSString();
|
218 |
|
215 |
|
219 |
// convert to all subsets to one single XML
|
216 |
// convert to all subsets to one single XML
|
220 |
writeAsXML(packagesProviders, "providers-" + osName, false);
|
217 |
SerialisationUtils.writeAsXML(packagesProviders, PATH_KNOWDLEDGE_BASE, "providers-" + osName, false);
|
221 |
|
218 |
|
222 |
// One Excel sheet that will contain all sub-sections
|
219 |
// One Excel sheet that will contain all sub-sections
|
223 |
Workbook wb = new XSSFWorkbook();
|
220 |
Workbook wb = new XSSFWorkbook();
|
224 |
for (String key : packagesProviders.keySet()) {
|
221 |
for (String key : packagesProviders.keySet()) {
|
225 |
Map<String, Set<String>> providers = packagesProviders.get(key);
|
222 |
Map<String, Set<String>> providers = packagesProviders.get(key);
|
226 |
storeSectionResult(providers, key, wb);
|
223 |
storeSectionResult(providers, key, wb);
|
227 |
storeSectionResult(providers, "providers-" + osName + "-" + key);
|
224 |
storeSectionResult(providers, "providers-" + osName + "-" + key);
|
228 |
}
|
225 |
}
|
229 |
try {
|
226 |
try {
|
230 |
FileOutputStream fos = new FileOutputStream(PATH + "providers-" + osName + ".xlsx");
|
227 |
FileOutputStream fos = new FileOutputStream(PATH_KNOWDLEDGE_BASE + "providers-" + osName + ".xlsx");
|
231 |
wb.write(fos);
|
228 |
wb.write(fos);
|
232 |
fos.close();
|
229 |
fos.close();
|
233 |
} catch (IOException e) {
|
230 |
} catch (IOException e) {
|
234 |
e.printStackTrace();
|
231 |
e.printStackTrace();
|
235 |
}
|
232 |
}
|
236 |
}
|
|
|
237 |
|
|
|
238 |
public static File writeAsXML(Object data, String fileName, boolean gzip) throws IOException {
|
|
|
239 |
String xml = xStream.toXML(data);
|
|
|
240 |
final File file = new File(PATH + fileName + ".xml");
|
|
|
241 |
PrintWriter pw;
|
|
|
242 |
if (gzip) {
|
|
|
243 |
pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(file)));
|
|
|
244 |
} else {
|
|
|
245 |
pw = new PrintWriter(file);
|
|
|
246 |
}
|
|
|
247 |
pw.println(xml);
|
|
|
248 |
pw.close();
|
|
|
249 |
return file;
|
|
|
250 |
}
|
233 |
}
|
251 |
|
234 |
|
252 |
public void storeSectionResult(final Map<String, Set<String>> providers, String sheetName, Workbook wb)
|
235 |
public void storeSectionResult(final Map<String, Set<String>> providers, String sheetName, Workbook wb)
|
253 |
throws FileNotFoundException {
|
236 |
throws FileNotFoundException {
|
254 |
// spreadsheet output
|
237 |
// spreadsheet output
|
|
... |
|
... |
269 |
PrintWriter simpleOutput = new PrintWriter(fileName + ".txt");
|
252 |
PrintWriter simpleOutput = new PrintWriter(fileName + ".txt");
|
270 |
PrintWriter csvOutput = new PrintWriter(fileName + ".csv");
|
253 |
PrintWriter csvOutput = new PrintWriter(fileName + ".csv");
|
271 |
PrintWriter xmlOutput = new PrintWriter(fileName + ".xml");
|
254 |
PrintWriter xmlOutput = new PrintWriter(fileName + ".xml");
|
272 |
|
255 |
|
273 |
// convert to XML
|
256 |
// convert to XML
|
274 |
String xml = xStream.toXML(providers);
|
257 |
String xml = SerialisationUtils.convertToXML(providers);
|
275 |
xmlOutput.println(xml);
|
258 |
xmlOutput.println(xml);
|
276 |
|
259 |
|
277 |
System.out.println("\nResults:\n");
|
260 |
System.out.println("\nResults:\n");
|
278 |
for (String pkg : providers.keySet()) {
|
261 |
for (String pkg : providers.keySet()) {
|
279 |
String s = pkg + ": " + providers.get(pkg).size() + " providers";
|
262 |
String s = pkg + ": " + providers.get(pkg).size() + " providers";
|
|
... |
|
... |
399 |
CommandLine cmd = parser.parse(options, args);
|
382 |
CommandLine cmd = parser.parse(options, args);
|
400 |
if (cmd.hasOption("providers")) { // load the providers from the file
|
383 |
if (cmd.hasOption("providers")) { // load the providers from the file
|
401 |
// initialise the member variable
|
384 |
// initialise the member variable
|
402 |
String providersFileName = cmd.getOptionValue("providers");
|
385 |
String providersFileName = cmd.getOptionValue("providers");
|
403 |
System.out.println("Trying to load package providers from XML " + providersFileName);
|
386 |
System.out.println("Trying to load package providers from XML " + providersFileName);
|
404 |
packagesProviders = (HashMap<String, HashMap<String, Set<String>>>) xStream.fromXML(new File(
|
387 |
packagesProviders = (HashMap<String, HashMap<String, Set<String>>>) SerialisationUtils.readFromXMLFile(providersFileName);
|
405 |
providersFileName));
|
|
|
406 |
System.out.println("\tDone!");
|
388 |
System.out.println("\tDone!");
|
407 |
}
|
389 |
}
|
408 |
} catch (ParseException e) {
|
390 |
} catch (ParseException e) {
|
409 |
System.err.println("CLI parsing failed. Reason: " + e.getMessage());
|
391 |
System.err.println("CLI parsing failed. Reason: " + e.getMessage());
|
410 |
// automatically generate the help statement
|
392 |
// automatically generate the help statement
|
|
... |
|
... |
423 |
|
405 |
|
424 |
System.out.println("Saving to files ... ");
|
406 |
System.out.println("Saving to files ... ");
|
425 |
for (Entry<String, OWLOntologyImpl> entry : ontologies.entrySet()) {
|
407 |
for (Entry<String, OWLOntologyImpl> entry : ontologies.entrySet()) {
|
426 |
OWLOntologyImpl ontology = entry.getValue();
|
408 |
OWLOntologyImpl ontology = entry.getValue();
|
427 |
String subPath = entry.getKey().equals(completeOntologyKey) ? "" : "subSections" + File.separatorChar;
|
409 |
String subPath = entry.getKey().equals(completeOntologyKey) ? "" : "subSections" + File.separatorChar;
|
428 |
File file = new File(PATH + subPath + "providers-" + operatingSystemName + "-" + entry.getKey() + ".owl");
|
410 |
File file = new File(PATH_KNOWDLEDGE_BASE + subPath + "providers-" + operatingSystemName + "-" + entry.getKey() + ".owl");
|
429 |
FileDocumentTarget fileDocumentTarget = new FileDocumentTarget(file);
|
411 |
FileDocumentTarget fileDocumentTarget = new FileDocumentTarget(file);
|
430 |
try {
|
412 |
try {
|
431 |
OWLManager.createOWLOntologyManager().saveOntology(ontology, new OWLXMLOntologyFormat(),
|
413 |
OWLManager.createOWLOntologyManager().saveOntology(ontology, new OWLXMLOntologyFormat(),
|
432 |
fileDocumentTarget);
|
414 |
fileDocumentTarget);
|
433 |
System.out.println("\t" + file.getAbsolutePath());
|
415 |
System.out.println("\t" + file.getAbsolutePath());
|