Jorge Villalón
How to contact
  • Home
  • EMarking
  • TML
    • Quick start
    • Using TML from Java
  • Concept Maps in Moodle
  • Publications
  • ISI journals search
  • CV
  • My calendar
  • New Page

Using TML from a Java program

To use TML from another java program you have to include TML in your classpath. You can use the provided tml-3.2-core.jar that does not include dependencies to avoid conflicting jars and save disk space.

Simple program that adds documents to a repository:

import tml.storage.*;

public class AddingFilesToRepository {

    public static void main(String[] args) throws Exception {
        Repository repository = new Repository("path/to/repository");

        repository.addDocumentsInFolder("path/to/txt/files");
        
        System.out.println("Documents added to repository successfully!");
    }
}
Simple program that runs an operation with the documents in the repository:

import tml.vectorspace.TermWeighting.GlobalWeight;
import tml.vectorspace.TermWeighting.LocalWeight;
import tml.vectorspace.operations.PassagesSimilarity;
import tml.corpus.SearchResultsCorpus;
import tml.corpus.CorpusParameters.DimensionalityReduction;
import tml.corpus.CorpusParameters.TermSelection;
import tml.storage.Repository;

public class passagesSimilarityTml {

    public static void main(String[] args) throws Exception {
        Repository repository = new Repository("path/to/repository");

        SearchResultsCorpus corpus = new SearchResultsCorpus("type:document");
        corpus.getParameters().setTermSelectionCriterion(TermSelection.DF);
        corpus.getParameters().setTermSelectionThreshold(0);
        corpus.getParameters().setDimensionalityReduction(DimensionalityReduction.NUM);
        corpus.getParameters().setDimensionalityReductionThreshold(50);
        corpus.getParameters().setTermWeightGlobal(GlobalWeight.Entropy);
        corpus.getParameters().setTermWeightLocal(LocalWeight.LOGTF);
        corpus.load(repository);
        
        System.out.println("Corpus loaded and Semantic space calculated");
        System.out.println("Total documents:" + corpus.getPassages().length);

        PassagesSimilarity distances = new PassagesSimilarity();
        distances.setCorpus(corpus);
        distances.start();

        distances.printResults();
    }
}
Create a free web site with Weebly