Getting Started with Graal using NetBeans

  1. Download and install NetBeans
  2. Create a new Maven Project
    1. In the menu bar: File > New Project
    2. Select Maven in the categories and Java Application in the projects.
    3. Click on next
    4. Enter a name: graal-getting-started
    5. Enter a group id: com.examples
    6. Click on Finish
  3. Configure your project
    1. Unfold the Project Files folder (in the projects frame)
    2. Double-click on pom.xml
    3. Insert the following dependencies in the root tag "project" (after </properties> and before </project>):
      
          <dependencies>
            <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>
          </dependencies>
          
    4. Save the file
  4. Create your first Graal program
    1. Unfold the Source Packages folder (in the projects frame)
    2. Right-click on the package below this folder: New > Java Class
    3. Define a name
    4. Click on Finish
    5. Insert the following main method:
      
      	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();
      	}
          
    6. In the menu bar: Source > Fix Imports (to add all needed import statements)
  5. Run App:
    1. Click on the green arrow in the toolbar
    2. Select the created class
    3. Click on "Select Main Class" button
  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