Skip to content

Latest commit

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Getting started with OpenCompare

Examples for using OpenCompare API and services

Import a PCM

1- Define the file that you want to load.

2- Create a loader that can handle the file format. In our example, we use the KMFJSONLoader which supports the internal representation of OpenCompare.

3- Load the file. A loader returns a list of PCM containers as a file may contain multiple PCMs. A PCM container encapsulates a PCM and its associated metadata (e.g. position of the products and features, source of the information, author of the PCM).

4- Iterate over the PCM containers to get the loaded PCMs

FilepcmFile = newFile("pcms/example.pcm");
PCMLoaderloader = newKMFJSONLoader();
List<PCMContainer> pcmContainers = loader.load(pcmFile);
for (PCMContainerpcmContainer : pcmContainers) {
PCMpcm = pcmContainer.getPcm();
}

Browse a PCM

Using the API

// Browse the cells of the PCMfor (Productproduct : pcm.getProducts()) {
for (Featurefeature : pcm.getConcreteFeatures()) {
// Find the cell corresponding to the current feature and productCellcell = product.findCell(feature);
// Get information contained in the cellStringcontent = cell.getContent();
StringrawContent = cell.getRawContent();
Valueinterpretation = cell.getInterpretation();
// Print the content of the cellSystem.out.println("(" + product.getName() + ", " + feature.getName() + ") = " + content);
}
}

Using a visitor

See src/test/java/org.opencompare/VisitorTest.java

Export

If we want to export or serialize the PCM to a specific format, we can use a PCMExporter. In this example, we export our PCM to a CSV file.

CSVExportercsvExporter = newCSVExporter();
Stringcsv = csvExporter.export(pcmContainer);

Import

If we want to import a PCM from a CSV file, we can use a CSVLoader.

CSVLoadercsvL = newCSVLoader(
newPCMFactoryImpl(),
newCellContentInterpreter(newPCMFactoryImpl()));
List<PCMContainer> pcms = csvL.load(newFile("pcms/pokemon.csv"));
...

About

Examples for using OpenCompare API and services

Resources

Stars

2 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages