Java Docs

ConStore Java Documentation provides the information about the interfaces and classes which helps for programming. The documentation can be accessed here.

Installation

ConStore is distributed as a .jar file. To use ConStore:
  • Download the latest release of ConStore.
  • Place the constore_x.jar file in the JAVA CLASSPATH and start using it.

Programming Example

To capture the Concept-Net model and using ConStore to persist the Concept-Net involves two major steps:

  • To create the meta-model of the desired Concept-Net, in terms of Entities and Relations
  • To construct the Concept-Net using the meta-model. It is an instantiation process of the meta-model.

Consider a simple example of Concept-Net of Students and Professors with relations as 'Guides'. We call it as 'Student-Net'.

  • Concept-Net Creation: As first step the Concept-Net need to be created. It is similar to file creation and it creates the necessary folders and files.
    public class ConceptNetCreation {
    
    	static ConceptNet studentNet = null;
    	
    	public static void main(String[] args) {
    		try {
    			studentNet = ConStore.create("StudentNet");
    			System.out.println("ConceptNet - 'StudentNet' is created successfully");
    		}catch(IOException ie) {
    			ie.printStackTrace();
    		}
    
    	}
    }	
    
  • Constucting the Meta-Model: The second step is to construct the meta-model of the Concept-Net and programatically induct the meta-model into the Concept-Net. In this case the meta model is: [Professor] --- (Guides) ---> [Student]
    try {
    	ConceptNet studentNet = ConStore.open("StudentNet","rw");
    	Entity student = new Entity("Student");
    	student.addAttribute("name", DataType.STRING, false);
    	student.addAttribute("skills", DataType.STRING, true);	
    
    	Entity professor = new Entity("Professor");
    	professor.addAttribute("name", DataType.STRING, false);
    	professor.addAttribute("expertise", DataType.STRING, true);
    	
    	studentNet.induct(student);
    	studentNet.induct(professor);
    	studentNet.commit();
    	
    	Relation guides = new Relation("Guides");
    	guides.setLeft((Entity)studentNet.getType("Professor"));
    	guides.setRight((Entity)studentNet.getType("Student"));
    	guides.setDirectionKind(Relation.LEFT_TO_RIGHT);
    		
    	studentNet.induct(guides);	
    	studentNet.commit();
    	studentNet.close();
    	//Java class are created automatically for the entities and relations under concept-net	
    
    }catch(IOException ie) {
    	ie.printStackTrace();
    }
    
  • Constructing the Concept-Net (Instantiation of Meta-model): The third step is to construct Concept-Net using the Entity and Relation instances. (Set the Concept-Net folder [here StudentNet] in the Java Classpath)
    try {
    	ConceptNet studentNet = ConStore.open("StudentNet","rw");
    	Student s = new Student();
    	s.name = "Ram";
    	s.skills.add("Java");
    	s.skills.add("OOP");
    	studentNet.add(s);
    
    	Professor p = new Professor();
    	p.name = "Gopal";
    	p.expertise.add("OS");
    	p.expertise.add("OOP");
    	studentNet.add(p);
    
    	studentNet.commit();
    	studentNet.close();
    
    	//studentNet.update(p); to update the instance
    	//studentNet.remove(p); to remove the instance
    
    }catch(IOException ie) {
    	ie.printStackTrace();
    }
    
  • Querying from Concept-Net: Using the 'Query' instance, user can retrieve various information from Concept-Net.
    try {
    	studentNet = ConStore.open("StudentNet","r");
    	
    	Query q = studentNet.query();
    	List instances = q.getInstances("Student", "name", "Ram");
    	
    	for(Instance i : instances) {
    		System.out.println(i.getAttributeValue("skills"));
    	}
    	studentNet.close();
    }catch(IOException ie) {
    	ie.printStackTrace();
    }
    
  • Indexing an attribute: Presently, ConStore uses static indexing i.e. any instance changes will not be reflected in the index and the index need to be created again. Below code snippet show how to index an attribute for the improving the query performance.
        studentNet.createIndex("Student", "name", new String());
    
    To drop the index:
        studentNet.dropIndex("Student", "name");
    


For more details about using the ConStore programming download this chapter.