use of org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService in project stanbol by apache.
the class IndexingConfig method initNamespacePrefixMapper.
/**
* @param configDir
* @throws IOException
*/
private void initNamespacePrefixMapper() throws IOException {
File nsPrefixMappings = getConfigFile("namespaceprefix.mappings");
if (!nsPrefixMappings.isFile()) {
FileUtils.writeLines(nsPrefixMappings, "UTF-8", Arrays.asList("# Syntax: '{prefix}\\t{namespace}\\n", "# where:", "# {prefix} ... [0..9A..Za..z-_]", "# {namespace} ... must end with '#' or '/' for URLs and ':' for URNs", "# one mapping per line, multiple prefixes for the same namespace allowed"));
}
namespacePrefixService = new StanbolNamespacePrefixService(nsPrefixMappings);
}
use of org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService in project stanbol by apache.
the class StanbolNamespacePrefixServiceTest method testInitialisationWithoutLocalMappingFIle.
@Test
public void testInitialisationWithoutLocalMappingFIle() throws IOException {
StanbolNamespacePrefixService service = new StanbolNamespacePrefixService(null);
service.setPrefix("dummy", "http://www.dummy.org/dummy#");
Assert.assertEquals("http://www.dummy.org/dummy#", service.getNamespace("dummy"));
service.importPrefixMappings(new ByteArrayInputStream("dummy2\thttp://www.dummy.org/dummy2#".getBytes(Charset.forName("UTF-8"))));
Assert.assertEquals("http://www.dummy.org/dummy2#", service.getNamespace("dummy2"));
}
use of org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService in project stanbol by apache.
the class DefaultProviderTest method init.
@BeforeClass
public static void init() throws IOException {
//this test for now does not use predefined mappings
URL mappingURL = DefaultProviderTest.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");
}
service = new StanbolNamespacePrefixService(mappingFile);
}
use of org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService 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));
}
use of org.apache.stanbol.commons.namespaceprefix.service.StanbolNamespacePrefixService in project stanbol by apache.
the class StanbolNamespacePrefixServiceTest method init.
@BeforeClass
public static void init() throws IOException {
URL mappingURL = StanbolNamespacePrefixServiceTest.class.getClassLoader().getResource("testnamespaceprefix.mappings");
Assert.assertNotNull(mappingURL);
File mappingFile;
try {
mappingFile = new File(mappingURL.toURI());
} catch (URISyntaxException e) {
mappingFile = new File(mappingURL.getPath());
}
Assert.assertTrue(mappingFile.isFile());
service = new StanbolNamespacePrefixService(mappingFile);
}
Aggregations