Search Mailing List Archives


Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[protege-owl] Using PROMPT from own application

Sean Falconer falconer.sean at gmail.com
Tue Apr 13 08:48:56 PDT 2010


You can programmatically use Prompt. You'll need to have Protege,
Protege-OWL, and the Prompt jar files in your classpath. To my
knowledge there isn't a lot of documentation on the Prompt API, so you
may need to download the source and dig through it to figure some
things out.  I included some code below to get you started. It sets up
and runs the Prompt mapping algorithm for two ontologies loaded using
the Protege API.  The code is a bit long as Prompt was never really
designed to be used this way.

// the sourceProject and targetProject are the path locations for the pprj files
public void createMapping(String sourceProject, String targetProject) {
     // load the ontologies using the Protege API
     KnowledgeBase sourceKb = loadOntology(sourceProject);
     KnowledgeBase targetKb = loadOntology(targetProject);
					
     String sourceProject = sourceKb.getProject().getProjectURI().getPath();
     String targetProject = targetKb.getProject().getProjectURI().getPath();	

     // have to tell Protege what the current project is since we are
bypassing the UI
     ProjectManager.getProjectManager().setCurrentProject(sourceKb.getProject(),
false, true);
					
     // configure Prompt
     // we set the comparison plugin to null to make Prompt use the default					
     PluginManager.getInstance().setActiveComparisonPlugin(null);
     Preferences.pluginMatch(false);

     // setup how the mappings will be stored    	
     LinkedList listOfStorageOptions =
               PluginManager.getInstance().getPlugins(PluginManager.PLUGIN_MAPPING_STORAGE);
     MappingStoragePluginOrder.putSimplePluginFirst (listOfStorageOptions);
		    		
     Collection storagePlugins = new ArrayList();
     storagePlugins.add(listOfStorageOptions.get(0));
	
     // set the active storage plugin	    		
     PluginManager.getInstance().setActiveMappingStoragePlugins(storagePlugins);
	
     // force Prompt to initialize				
     new PromptTab();
     PromptTab.setMapping();
     PromptTab.setCompareSources(true);
     Preferences.approximateMatch(true);
					
     if(targetProject.charAt(0) == '/') targetProject =
targetProject.substring(1);
     if(sourceProject.charAt(0) == '/') sourceProject =
sourceProject.substring(1);
					
     String[] projectFiles = new String[] {targetProject, "", "",
sourceProject};
     String[] projectNames = new String[]
{getProjectName(targetProject), "", "",
getProjectName(sourceProject)};
	
    // add a listener so we know when the mapping is complete
    PromptListenerManager.addListener(new PromptAdapter() {
						public void taskComplete(PromptEvent event, boolean interrupted) {
							if(!interrupted) {
								// mapping complete! do something
							}
						}
					});
				
     PromptTab.setUpMerging(projectFiles, projectNames, -1, true);
}

private String getProjectName(String projectPath) {
		int start = projectPath.lastIndexOf(File.separatorChar)+1;
		int end = projectPath.lastIndexOf(".");
		
		if(start >= 0 && end >= 0) {
			return projectPath.substring(start, end);
		}
		
		return "";
	}

private KnowledgeBase loadOntology(String projectFile) {
		if (projectFile != null) {
			if(projectFile.endsWith(".pprj")) {
				try {
					Collection<Object> errors = new ArrayList<Object>(0);
					Project project =
ProjectManager.getProjectManager().loadProjectFromURI(URIUtilities.createURI(projectFile),
errors);
	
					return project.getKnowledgeBase();
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}

		return null;
	}



On Tue, Apr 13, 2010 at 6:48 AM, Maria Mitina <mitina.maria at gmail.com> wrote:
> Hi everyone,
>
> i am new to Protege and feeling a bit lost regarding
> the use of plugins.
> In my task i need to compare two ontologies from my own
> application in java.
> I found out that the results of comparosin by PROMPT are
> very close to what i
> need. But i cannot find any information on how to access
> PROMPT from my programme.
>
> Do i need to use Protege-OWL API? Or is there the way to
> access PROMPT directly
> from java application sourcing pathes to my ontologies only?
>
>
> If someone has experience of accessing PROMPT (or using a
> similar tool to
> compare ontologies) from their own programme, please, share
> it! I would really
> appreciate this!
>
>
>
> Thank everyone,
> Maria.
>
> _______________________________________________
> protege-owl mailing list
> protege-owl at lists.stanford.edu
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing:
> http://protege.stanford.edu/doc/faq.html#01a.03
>
>



-- 
Sean Falconer, PhD
Postdoctoral Researcher
Stanford Center for Biomedical Informatics Research
http://www.stanford.edu/~sfalc



More information about the protege-owl mailing list