wiki:sample client code using the Maven artifacts

This sample client code can be also found at peregrine/rmi/src/org/erasmusmc/data_mining/peregrine/rmi/PeregrineRMI.java

package org.erasmusmc.data_mining.peregrine.rmi;

import java.util.Collection;
import java.io.Serializable;

import org.erasmusmc.data_mining.ontology.api.Language;
import org.erasmusmc.data_mining.peregrine.api.DisambiguationInfo;
import org.erasmusmc.data_mining.peregrine.api.IndexingDisambiguationResult;
import org.erasmusmc.data_mining.peregrine.api.IndexingResult;
import org.erasmusmc.data_mining.peregrine.api.Peregrine;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class PeregrineRMI {

	public static void main(String[] args) {
		// Just instantiate the context:
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
				"/org/erasmusmc/data_mining/peregrine/rmi/peregrine-rmi.context.xml");

		Peregrine peregrine = (Peregrine) applicationContext.getBean("peregrine");

		String text = "Malaria test blabla.";
				
		Collection<IndexingResult> results = peregrine.index(text, Language.PT);
		
		System.out.println("\nNow IndexingResult:\n\n");
		
		for (IndexingResult indexingResult : results) {
			Serializable conceptId = indexingResult.getTermId().getConceptId();
								
			System.out.println("\n\nFound conceptId: " + conceptId + ", matched text: "
					+ text.substring(indexingResult.getStartPos(), indexingResult.getEndPos()+1));
		}		
		
		System.out.println("\nNow DisambiguationResults:\n\n");
		
		Collection<IndexingDisambiguationResult> DisambiguationResults = peregrine.indexAndDisambiguateVerbose(text, Language.EN);
		for (IndexingDisambiguationResult indexingResult : DisambiguationResults) {
			Serializable conceptId = indexingResult.getTermId().getConceptId();

			System.out.println("\n\nFound conceptId: " + conceptId + ", matched text: "
					+ text.substring(indexingResult.getStartPos(), indexingResult.getEndPos() + 1) + "\n");
			for (DisambiguationInfo info : indexingResult.getDisambiguationInfos()) {
				System.out.println(info.getKeyword());
				System.out.println(info.getMessage());
				System.out.println(info.getWeight());
			}
		}

		System.out.println("DONE!");
	}
}
Last modified 11 years ago Last modified on Nov 1, 2011, 5:14:36 PM