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);
}
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");
// }
}
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);
}
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();
}
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();
}
}
Aggregations