Search in sources :

Example 1 with CodeEntry

use of eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry in project hale by halestudio.

the class SkosCodeListTest method testSKOSFromRDF4_language_en.

/**
 * test read SKOS properties in preferred language.
 *
 * @throws Exception throws exception if something wrong occurs
 */
@Test
public void testSKOSFromRDF4_language_en() throws Exception {
    String base_ns = "http://www.locationframework.eu/codelist/";
    CodeList codeList = readCodeList_WithLanguage(getResourceURI("/data/test4_lang.rdf"), "en");
    Collection<CodeEntry> entries = codeList.getEntries();
    assertFalse(entries.isEmpty());
    assertEquals(entries.size(), 4);
    assertNotNull(codeList.getLocation());
    assertNotNull(codeList.getIdentifier());
    CodeEntry entry = codeList.getEntryByIdentifier(base_ns + "EuroGeoNamesLocationTypeValue/1");
    assertEquals("Countries, administrative units and other areas", entry.getName());
    assertEquals("Country, territorial units of a country for administrative purposes and other manmade areas.", entry.getDescription());
}
Also used : CodeList(eu.esdihumboldt.hale.common.codelist.CodeList) CodeEntry(eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry) Test(org.junit.Test)

Example 2 with CodeEntry

use of eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry in project hale by halestudio.

the class SkosCodeListTest method testSKOSFromRDF4_language_nl.

/**
 * test read SKOS properties in preferred language.
 *
 * @throws Exception throws exception if something wrong occurs
 */
@Test
public void testSKOSFromRDF4_language_nl() throws Exception {
    String base_ns = "http://www.locationframework.eu/codelist/";
    CodeList codeList = readCodeList_WithLanguage(getResourceURI("/data/test4_lang.rdf"), "nl");
    Collection<CodeEntry> entries = codeList.getEntries();
    assertFalse(entries.isEmpty());
    assertEquals(entries.size(), 4);
    assertNotNull(codeList.getLocation());
    assertNotNull(codeList.getIdentifier());
    CodeEntry entry = codeList.getEntryByIdentifier(base_ns + "EuroGeoNamesLocationTypeValue/1");
    assertEquals("Landen, administratieve en overige gebieden", entry.getName());
    assertEquals("Country, territorial units of a country for administrative purposes and other manmade areas.", entry.getDescription());
}
Also used : CodeList(eu.esdihumboldt.hale.common.codelist.CodeList) CodeEntry(eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry) Test(org.junit.Test)

Example 3 with CodeEntry

use of eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry in project hale by halestudio.

the class SkosCodeListTest method testSKOSFromRDF4_language_de.

/**
 * test read SKOS properties in preferred language, as "de" not available,
 * it will load "en" by default
 *
 * @throws Exception throws exception if something wrong occurs
 */
@Test
public void testSKOSFromRDF4_language_de() throws Exception {
    String base_ns = "http://www.locationframework.eu/codelist/";
    CodeList codeList = readCodeList_WithLanguage(getResourceURI("/data/test4_lang.rdf"), "de");
    Collection<CodeEntry> entries = codeList.getEntries();
    assertFalse(entries.isEmpty());
    assertEquals(entries.size(), 4);
    assertNotNull(codeList.getLocation());
    assertNotNull(codeList.getIdentifier());
    CodeEntry entry = codeList.getEntryByIdentifier(base_ns + "EuroGeoNamesLocationTypeValue/1");
    assertEquals("Countries, administrative units and other areas", entry.getName());
    assertEquals("Country, territorial units of a country for administrative purposes and other manmade areas.", entry.getDescription());
}
Also used : CodeList(eu.esdihumboldt.hale.common.codelist.CodeList) CodeEntry(eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry) Test(org.junit.Test)

Example 4 with CodeEntry

use of eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry in project hale by halestudio.

the class SkosCodeListTest method testSKOSFromRDF5_language_de.

/**
 * test read SKOS properties in preferred language (fallback). As "de" not
 * available, it will load "en" by default
 *
 * @throws Exception throws exception if something wrong occurs
 */
@Test
public void testSKOSFromRDF5_language_de() throws Exception {
    CodeList codeList = readCodeList_WithLanguage(getResourceURI("/data/test4_lang_fallback.rdf"), "de");
    Collection<CodeEntry> entries = codeList.getEntries();
    assertFalse(entries.isEmpty());
    assertEquals(entries.size(), 4);
    assertNotNull(codeList.getLocation());
    assertNotNull(codeList.getIdentifier());
    CodeEntry entry = codeList.getEntryByIdentifier("EuroGeoNamesLocationTypeValue/1");
    assertEquals("Countries, administrative units and other areas", entry.getName());
    assertEquals("Country, territorial units of a country for administrative purposes and other manmade areas.", entry.getDescription());
}
Also used : CodeList(eu.esdihumboldt.hale.common.codelist.CodeList) CodeEntry(eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry) Test(org.junit.Test)

Example 5 with CodeEntry

use of eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry in project hale by halestudio.

the class INSPIRECodeListReader method addEntry.

private void addEntry(Node item, INSPIRECodeList codelist, XPath xpath, IOReporter reporter) throws Exception {
    String name = null;
    String description = null;
    String identifier = null;
    String namespace = null;
    identifier = (String) xpath.evaluate("@id", item, XPathConstants.STRING);
    if (identifier == null) {
        reporter.warn(new IOMessageImpl("No id attribute present in a value of the INSPIRE codelist. Skipping value.", null));
        return;
    }
    // XXX what about multiple labels or definitions?
    NodeList labels = (NodeList) xpath.evaluate("label", item, XPathConstants.NODESET);
    if (labels.getLength() > 0)
        name = labels.item(0).getTextContent();
    else {
        reporter.warn(new IOMessageImpl("No label present in a value of the INSPIRE codelist.", null));
        name = identifier;
    }
    NodeList definitions = (NodeList) xpath.evaluate("definition", item, XPathConstants.NODESET);
    if (definitions.getLength() > 0)
        description = definitions.item(0).getTextContent();
    // in schema no description, but in data; anyways, ignore it for now
    // also ignore status, register, applicationschema and theme
    namespace = (String) xpath.evaluate("codelist/@id", item, XPathConstants.STRING);
    // XXX I guess namespace has to be the same as the codelist. Check this?
    codelist.addEntry(new CodeEntry(name, description, identifier, namespace));
}
Also used : CodeEntry(eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry) NodeList(org.w3c.dom.NodeList) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)

Aggregations

CodeEntry (eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry)11 CodeList (eu.esdihumboldt.hale.common.codelist.CodeList)10 Test (org.junit.Test)9 CodeListAssociations (eu.esdihumboldt.hale.common.codelist.config.CodeListAssociations)1 CodeListReference (eu.esdihumboldt.hale.common.codelist.config.CodeListReference)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 ValidationException (eu.esdihumboldt.hale.common.instance.extension.validation.ValidationException)1 NodeList (org.w3c.dom.NodeList)1