Search in sources :

Example 6 with IndexingConfig

use of org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig in project stanbol by apache.

the class ConfigTest method loadSimpleConfigDir.

/**
     * Loads a simple but not functional configuration to test the loading and
     * parsing of configuration files
     */
@Test
public void loadSimpleConfigDir() throws IOException {
    String name = CONFIG_ROOT + "simple";
    IndexingConfig config = new IndexingConfig(name, name) {
    };
    //assert that this directory exists (is created)
    File expectedRoot = new File(testRoot, name);
    expectedRoot = new File(expectedRoot, "indexing");
    assertTrue("Root Dir not created", expectedRoot.isDirectory());
    assertEquals("Root dir other the expected ", expectedRoot.getCanonicalPath(), config.getIndexingFolder().getCanonicalPath());
    assertTrue(config.getConfigFolder().isDirectory());
    assertTrue(config.getSourceFolder().isDirectory());
    assertTrue(config.getDestinationFolder().isDirectory());
    assertTrue(config.getDistributionFolder().isDirectory());
    //test the name
    assertEquals(config.getName(), "simple");
    assertEquals(config.getDescription(), "Simple Configuration");
    //test if the normaliser configuration was parsed correctly!
    final ScoreNormaliser normaliser = config.getNormaliser();
    //test if the config files where copied form the classpath to the
    //config directory.
    assertTrue("Config File for the RangeNormaliser not copied", new File(config.getConfigFolder(), "range.properties").isFile());
    assertTrue("Config File for the MinScoreNormalizer not copied", new File(config.getConfigFolder(), "minscore.properties").isFile());
    //now test if the configuration was parsed correctly
    ScoreNormaliser testNormaliser = normaliser;
    assertNotNull(testNormaliser);
    assertEquals(testNormaliser.getClass(), RangeNormaliser.class);
    testNormaliser = testNormaliser.getChained();
    assertNotNull(testNormaliser);
    assertEquals(testNormaliser.getClass(), NaturalLogNormaliser.class);
    testNormaliser = testNormaliser.getChained();
    assertNotNull(testNormaliser);
    assertEquals(testNormaliser.getClass(), MinScoreNormalizer.class);
    EntityIterator entityIterator = config.getEntityIdIterator();
    assertNotNull(entityIterator);
    assertEquals(entityIterator.getClass(), LineBasedEntityIterator.class);
    if (entityIterator.needsInitialisation()) {
        entityIterator.initialise();
    }
    Map<String, Float> entityIds = new HashMap<String, Float>();
    //the values test if the normaliser configuration was readed correctly
    //the keys if the configured entiyScore file was configured correctly
    float boost = 10f / (float) Math.log1p(100);
    entityIds.put("http://www.example.org/entity/test", Float.valueOf(10));
    entityIds.put("http://www.example.org/entity/test2", Float.valueOf((float) (Math.log1p(10) * boost)));
    entityIds.put("http://www.example.org/entity/test3", Float.valueOf(-1));
    while (entityIterator.hasNext()) {
        EntityIterator.EntityScore entityScore = entityIterator.next();
        Float expectedScore = entityIds.remove(entityScore.id);
        assertNotNull("Entity with ID " + entityScore.id + " not found!", expectedScore);
        Float score = normaliser.normalise(entityScore.score);
        assertTrue("Entity score " + score + " is not the expected " + expectedScore, expectedScore.compareTo(score) == 0);
    }
    assertTrue(entityIds.isEmpty());
    List<EntityProcessor> processors = config.getEntityProcessors();
    assertNotNull(processors);
}
Also used : ScoreNormaliser(org.apache.stanbol.entityhub.indexing.core.normaliser.ScoreNormaliser) IndexingConfig(org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig) HashMap(java.util.HashMap) LineBasedEntityIterator(org.apache.stanbol.entityhub.indexing.core.source.LineBasedEntityIterator) File(java.io.File) Test(org.junit.Test)

Example 7 with IndexingConfig

use of org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig in project stanbol by apache.

the class OsgiConfigurationUtilTest method testOsgiConfigurationGeneration.

@Test
public void testOsgiConfigurationGeneration() throws URISyntaxException, IOException {
    String name = CONFIG_ROOT + "bundlebuild";
    //copy test destination folder to mock-up the destination "config" folder creation operation
    String destConfFolder = name + "/indexing/destination/" + "config";
    File destConfSource = new File(this.getClass().getResource("/" + destConfFolder).toURI());
    File destConfTarget = new File(testRoot + "/" + destConfFolder);
    FileUtils.copyDirectory(destConfSource, destConfTarget);
    File distFolder = new File(testRoot + '/' + name + "/indexing/dist");
    File bundle = new File(distFolder, "org.apache.stanbol.data.site.simple-1.0.0.jar");
    IndexingConfig config = new IndexingConfig(name, name) {
    };
    OsgiConfigurationUtil.createBundle(config);
    assertTrue("Configuration bundle '" + bundle + "' was not created!", bundle.isFile());
//if choose to get .createBundle throwing exceptions, this test may be better :
//        try{
//        	OsgiConfigurationUtil.createBundle(config);
//        }catch(Exception npe){
//        	fail("NPE fired when try to build the osgi configuration");
//        }
}
Also used : IndexingConfig(org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig) File(java.io.File) Test(org.junit.Test)

Example 8 with IndexingConfig

use of org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig in project stanbol by apache.

the class SolrYardIndexingDestinationTest method testSimple.

@Test
public void testSimple() throws YardException, IOException {
    String testName = "simple";
    IndexingConfig config = new IndexingConfig(CONFIG_ROOT + File.separatorChar + testName, CONFIG_ROOT + '/' + testName) {
    };
    validateSolrDestination(config);
}
Also used : IndexingConfig(org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig) Test(org.junit.Test)

Example 9 with IndexingConfig

use of org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig in project stanbol by apache.

the class SolrYardIndexingDestinationTest method testInvalidBoostConfig.

@Test(expected = IllegalArgumentException.class)
public void testInvalidBoostConfig() {
    String testName = "invalidBoostConfig";
    IndexingConfig config = new IndexingConfig(CONFIG_ROOT + File.separatorChar + testName, CONFIG_ROOT + '/' + testName) {
    };
    config.getIndexingDestination();
}
Also used : IndexingConfig(org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig) Test(org.junit.Test)

Example 10 with IndexingConfig

use of org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig in project stanbol by apache.

the class RdfIndexingSourceTest method testEntityDataProvider.

@Test
public void testEntityDataProvider() {
    log.info(" --- testEntityDataProvider ---");
    String testName = "provider";
    IndexingConfig config = new IndexingConfig(CONFIG_ROOT + File.separatorChar + testName, CONFIG_ROOT + '/' + testName) {
    };
    EntityIterator entityIdIterator = config.getEntityIdIterator();
    assertNotNull("Unable to perform test whithout EntityIterator", entityIdIterator);
    if (entityIdIterator.needsInitialisation()) {
        entityIdIterator.initialise();
    }
    EntityDataProvider dataProvider = config.getEntityDataProvider();
    try {
        assertNotNull(dataProvider);
        if (dataProvider.needsInitialisation()) {
            dataProvider.initialise();
        }
        assertEquals(dataProvider.getClass(), RdfIndexingSource.class);
        long count = 0;
        while (entityIdIterator.hasNext()) {
            EntityScore entityScore = entityIdIterator.next();
            assertNotNull(entityScore);
            assertNotNull(entityScore.id);
            validateRepresentation(dataProvider.getEntityData(entityScore.id), entityScore.id);
            count++;
        }
        //check if all entities where found
        assertEquals(String.format("%s Entities expected but %s processed!", NUMBER_OF_ENTITIES_EXPECTED, count), NUMBER_OF_ENTITIES_EXPECTED, count);
    } finally {
        //we need to ensure close is called as otherwise other tests might fail 
        dataProvider.close();
    }
}
Also used : EntityDataProvider(org.apache.stanbol.entityhub.indexing.core.EntityDataProvider) EntityScore(org.apache.stanbol.entityhub.indexing.core.EntityIterator.EntityScore) IndexingConfig(org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig) EntityIterator(org.apache.stanbol.entityhub.indexing.core.EntityIterator) Test(org.junit.Test)

Aggregations

IndexingConfig (org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig)26 Test (org.junit.Test)15 File (java.io.File)8 EntityIterator (org.apache.stanbol.entityhub.indexing.core.EntityIterator)4 EntityScore (org.apache.stanbol.entityhub.indexing.core.EntityIterator.EntityScore)4 IOException (java.io.IOException)3 EntityDataIterable (org.apache.stanbol.entityhub.indexing.core.EntityDataIterable)3 EntityDataIterator (org.apache.stanbol.entityhub.indexing.core.EntityDataIterator)3 EntityDataProvider (org.apache.stanbol.entityhub.indexing.core.EntityDataProvider)3 ResourceLoader (org.apache.stanbol.entityhub.indexing.core.source.ResourceLoader)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 NamespacePrefixService (org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService)2 ScoreNormaliser (org.apache.stanbol.entityhub.indexing.core.normaliser.ScoreNormaliser)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IndexerImpl (org.apache.stanbol.entityhub.indexing.core.impl.IndexerImpl)1 EntityIneratorToScoreProviderAdapter (org.apache.stanbol.entityhub.indexing.core.source.EntityIneratorToScoreProviderAdapter)1