Getting Started with Graal using Eclipse

  1. Download and install Eclipse
  2. Create a new Maven Project
    1. In the menu bar: File > New > Other > Maven Project
    2. Click twice on next (until you get the "Select an Archetype" page)
    3. Ensure that the selected archetype is "maven-archetype-quickstart"
    4. Click on next
    5. Enter a group id: com.example
    6. Enter an artifact id: graal-getting-started
    7. Click on Finish
  3. Configure your project
    1. Double-click on pom.xml (in the package or project explorer)
    2. Select the pom.xml tab (the tab that shows the raw xml content)
    3. Insert the following dependencies in the "dependencies" tag (above the "junit" dependency):
      
          <dependency>
            <groupId>fr.lirmm.graphik</groupId>
            <artifactId>graal-core</artifactId>
            <version>1.3.1</version>
          </dependency>
          <dependency>
            <groupId>fr.lirmm.graphik</groupId>
            <artifactId>graal-io-dlgp</artifactId>
            <version>1.3.1</version>
          </dependency>
          <dependency>
            <groupId>fr.lirmm.graphik</groupId>
            <artifactId>graal-kb</artifactId>
            <version>1.3.1</version>
          </dependency>
          
    4. Save the file
  4. Create your first Graal program
    1. Open the App.java file (in src/main/java)
    2. Replace your main method by the following one:
      
      	public static void main(String[] args) throws Exception {
      		// 0 - Create a KBBuilder
      		KBBuilder kbb = new KBBuilder();
      		// 1 - Add a rule
      		kbb.add(DlgpParser.parseRule("mortal(X) :- human(X)."));
      		// 2 - Add a fact
      		kbb.add(DlgpParser.parseAtom("human(socrate)."));
      		// 3 - Generate the KB
      		KnowledgeBase kb = kbb.build();
      		// 4 - Create a DLGP writer to print data
      		DlgpWriter writer = new DlgpWriter();
      		// 5 - Parse a query from a Java String
      		ConjunctiveQuery query = DlgpParser.parseQuery("?(X) :- mortal(X).");
      		// 6 - Query the KB
      		CloseableIterator resultIterator = kb.query(query);
      		// 7 - Iterate and print results
      		writer.write("\n= Answers =\n");
      		if (resultIterator.hasNext()) {
      			do {
      				writer.write(resultIterator.next());
      				writer.write("\n");
      			} while (resultIterator.hasNext());
      		} else {
      			writer.write("No answers.\n");
      		}
      		// 8 - Close resources
      		kb.close();
      		writer.close();
      	}
          
    3. In the menu bar: Source > Organize Imports (to add all needed import statements)
  5. Run App: Right-click on App.java in the package or project explorer > Run As > Java Application
  6. Do not care about following SLF4J warning (see SLF4J page to disable this warning):
             SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
             SLF4J: Defaulting to no-operation (NOP) logger implementation
             SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
        

    You are ready to work with Graal