use of org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService in project stanbol by apache.
the class FreebaseKeyProcessor method setConfiguration.
@Override
public void setConfiguration(Map<String, Object> config) {
IndexingConfig indexingConfig = (IndexingConfig) config.get(IndexingConfig.KEY_INDEXING_CONFIG);
NamespacePrefixService nsPrefixService = indexingConfig.getNamespacePrefixService();
Object value = config.get(PARAM_LINK_PROPERTY);
if (value != null) {
linkProperty = nsPrefixService.getFullName(value.toString());
if (linkProperty == null) {
throw new IllegalArgumentException("Unknown Namespace Prefix use in " + PARAM_LINK_PROPERTY + '=' + value + "!");
}
} else {
linkProperty = DEFAULT_LINK_PROPERTY;
}
value = config.get(PARAM_DBPEDIA_STATE);
if (value != null) {
dbpediaState = Boolean.parseBoolean(value.toString());
} else {
dbpediaState = DEFAULT_DBPEDIA_STATE;
}
value = config.get(PARAM_MUSICBRAINZ_STATE);
if (value != null) {
musicbrainzState = Boolean.parseBoolean(value.toString());
} else {
musicbrainzState = DEFAULT_MUSICBRAINZ_STATE;
}
}
use of org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService in project stanbol by apache.
the class DereferenceContext method parseEntityReferences.
private void parseEntityReferences(Object value) throws DereferenceConfigurationException {
Collection<String> entityRefProps;
try {
entityRefProps = EnhancementEngineHelper.parseConfigValues(value, String.class);
} catch (IllegalStateException e) {
throw new DereferenceConfigurationException(e, engine.getDereferencer().getClass(), DereferenceConstants.ENTITY_REFERENCES);
}
//start with the references present in the config
this.entityReferences = new HashSet<IRI>(getConfig().getEntityReferences());
if (entityRefProps != null && !entityRefProps.isEmpty()) {
NamespacePrefixService nps = engine.getConfig().getNsPrefixService();
for (String prop : entityRefProps) {
if (!StringUtils.isBlank(prop)) {
try {
entityReferences.add(new IRI(NamespaceMappingUtils.getConfiguredUri(nps, prop)));
} catch (IllegalArgumentException e) {
throw new DereferenceConfigurationException(e, engine.getDereferencer().getClass(), DereferenceConstants.ENTITY_REFERENCES);
}
}
}
}
}
use of org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService in project stanbol by apache.
the class PropertyPrefixFilter method setConfiguration.
@Override
public void setConfiguration(Map<String, Object> config) {
IndexingConfig indexingConfig = (IndexingConfig) config.get(IndexingConfig.KEY_INDEXING_CONFIG);
NamespacePrefixService nsPrefixService = indexingConfig.getNamespacePrefixService();
log.info("Configure {}", getClass().getSimpleName());
Object value = config.get(PARAM_PROPERTY_FILTERS);
if (value == null) {
propertyPrefixMap = Collections.emptyMap();
propertyMap = Collections.emptyMap();
includeAll = true;
} else {
log.info(" > property Prefix Filters");
//ensure that longer prefixes are first
File propertyPrefixConfig = indexingConfig.getConfigFile(value.toString());
List<String> lines;
InputStream in = null;
try {
in = new FileInputStream(propertyPrefixConfig);
lines = IOUtils.readLines(in, "UTF-8");
} catch (IOException e) {
throw new IllegalArgumentException("Unable to read property filter configuration " + "from the configured File " + propertyPrefixConfig.getAbsolutePath(), e);
} finally {
IOUtils.closeQuietly(in);
}
parsePropertyPrefixConfig(nsPrefixService, lines);
}
}
use of org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService in project stanbol by apache.
the class SolrYardTest method initYard.
@BeforeClass
public static final void initYard() throws YardException, IOException {
// get the working directory
// use property substitution to test this feature!
String prefix = System.getProperty("basedir") == null ? "." : "${basedir}";
String solrServerDir = prefix + TEST_INDEX_REL_PATH;
log.info("Test Solr Server Directory: " + solrServerDir);
SolrYardConfig config = new SolrYardConfig(TEST_YARD_ID, TEST_SOLR_CORE_NAME);
config.setName("Solr Yard Test");
config.setDescription("The Solr Yard instance used to execute the Unit Tests defined for the Yard Interface");
config.setAllowInitialisation(true);
//for unit testing we want immidiate commits (required after STANBOL-1092
// as the default changed to false)
config.setImmediateCommit(true);
//init the ManagedSolrServer used for the UnitTest
System.setProperty(ManagedSolrServer.MANAGED_SOLR_DIR_PROPERTY, solrServerDir);
IndexReference solrServerRef = IndexReference.parse(config.getSolrServerLocation());
solrServerProvider = StandaloneEmbeddedSolrServerProvider.getInstance();
SolrServer server = solrServerProvider.getSolrServer(solrServerRef, config.isAllowInitialisation() ? config.getIndexConfigurationName() : null);
//Optional support for the nsPrefix service
final NamespacePrefixService nsPrefixService;
ServiceLoader<NamespacePrefixService> spsl = ServiceLoader.load(NamespacePrefixService.class);
Iterator<NamespacePrefixService> it = spsl.iterator();
if (it.hasNext()) {
nsPrefixService = it.next();
} else {
nsPrefixService = null;
}
yard = new SolrYard(server, config, nsPrefixService);
}
use of org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService in project stanbol by apache.
the class PrefixccProviderTest method testServiceLoader.
@Test
public void testServiceLoader() throws IOException {
//this test works only if online
if (!checkServiceAvailable()) {
//skip test
return;
}
//this test for now does not use predefined mappings
URL mappingURL = PrefixccProviderTest.class.getClassLoader().getResource("testnamespaceprefix.mappings");
//Assert.assertNotNull(mappingURL);
File mappingFile;
if (mappingURL != null) {
try {
mappingFile = new File(mappingURL.toURI());
} catch (URISyntaxException e) {
mappingFile = new File(mappingURL.getPath());
}
//Assert.assertTrue(mappingFile.isFile());
} else {
mappingFile = new File("testnamespaceprefix.mappings");
}
NamespacePrefixService service = new StanbolNamespacePrefixService(mappingFile);
//assertMappings
Assert.assertEquals(foaf_pf, service.getPrefix(foaf_ns));
Assert.assertEquals(foaf_ns, service.getNamespace(foaf_pf));
}
Aggregations