Giter Club home page Giter Club logo

getting-started's Introduction

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

File pcmFile = new File("pcms/example.pcm");
PCMLoader loader = new KMFJSONLoader();
List<PCMContainer> pcmContainers = loader.load(pcmFile);
for (PCMContainer pcmContainer : pcmContainers) {
  PCM pcm = pcmContainer.getPcm();
}

Browse a PCM

Using the API

// Browse the cells of the PCM
for (Product product : pcm.getProducts()) {
  for (Feature feature : pcm.getConcreteFeatures()) {
    // Find the cell corresponding to the current feature and product
    Cell cell = product.findCell(feature);

    // Get information contained in the cell
    String content = cell.getContent();
    String rawContent = cell.getRawContent();
    Value interpretation = cell.getInterpretation();

    // Print the content of the cell
    System.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.

CSVExporter csvExporter = new CSVExporter();
String csv = csvExporter.export(pcmContainer);

getting-started's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.