Search in sources :

Example 1 with NamespacePrefixService

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;
    }
}
Also used : IndexingConfig(org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig) NamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService)

Example 2 with NamespacePrefixService

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);
                }
            }
        }
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) NamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService)

Example 3 with NamespacePrefixService

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);
    }
}
Also used : IndexingConfig(org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) NamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 4 with NamespacePrefixService

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);
}
Also used : NamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService) IndexReference(org.apache.stanbol.commons.solr.IndexReference) StandaloneManagedSolrServer(org.apache.stanbol.commons.solr.managed.standalone.StandaloneManagedSolrServer) ManagedSolrServer(org.apache.stanbol.commons.solr.managed.ManagedSolrServer) SolrServer(org.apache.solr.client.solrj.SolrServer) SolrYard(org.apache.stanbol.entityhub.yard.solr.impl.SolrYard) SolrYardConfig(org.apache.stanbol.entityhub.yard.solr.impl.SolrYardConfig) BeforeClass(org.junit.BeforeClass)

Example 5 with NamespacePrefixService

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));
}
Also used : URISyntaxException(java.net.URISyntaxException) StanbolNamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService) StanbolNamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService) NamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

NamespacePrefixService (org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService)5 File (java.io.File)2 IndexingConfig (org.apache.stanbol.entityhub.indexing.core.config.IndexingConfig)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 SolrServer (org.apache.solr.client.solrj.SolrServer)1 StanbolNamespacePrefixService (org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService)1 IndexReference (org.apache.stanbol.commons.solr.IndexReference)1 ManagedSolrServer (org.apache.stanbol.commons.solr.managed.ManagedSolrServer)1 StandaloneManagedSolrServer (org.apache.stanbol.commons.solr.managed.standalone.StandaloneManagedSolrServer)1 SolrYard (org.apache.stanbol.entityhub.yard.solr.impl.SolrYard)1 SolrYardConfig (org.apache.stanbol.entityhub.yard.solr.impl.SolrYardConfig)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1