Search in sources :

Example 11 with Listing

use of org.wikivoyage.listings.entity.Listing in project wikivoyage-listings by baturin.

the class TestWikivoyagePOI method invalidURLs.

@Test
public void invalidURLs() {
    Listing p1 = TestWikivoyagePOI.createWithURL("\"http://wikivoyage.org");
    Listing p2 = TestWikivoyagePOI.createWithURL("[http://wikivoyage.org");
    Listing p3 = TestWikivoyagePOI.createWithURL("http://wikivoyage.org]");
    Listing p4 = TestWikivoyagePOI.createWithURL("wikivoyage.org");
    Listing p5 = TestWikivoyagePOI.createWithURL("mary@wikivoyage.org");
    Listing p6 = TestWikivoyagePOI.createWithURL("ftp://wikivoyage.org]");
    // Prepare validation iterable
    Iterable<Listing> pois = new WebsiteURLValidator().validate(Arrays.asList(p1, p2, p3, p4, p5, p6));
    // Check results
    for (Listing poi : pois) {
        assertFalse(poi.isValid());
    }
}
Also used : Listing(org.wikivoyage.listings.entity.Listing) WebsiteURLValidator(org.wikivoyage.listings.validators.WebsiteURLValidator) Test(org.junit.Test)

Example 12 with Listing

use of org.wikivoyage.listings.entity.Listing in project wikivoyage-listings by baturin.

the class TestWikivoyagePOI method validURLs.

@Test
public void validURLs() {
    Listing p1 = TestWikivoyagePOI.createWithURL("http://wikivoyage.org");
    Listing p2 = TestWikivoyagePOI.createWithURL("https://wikivoyage.org");
    Listing p3 = TestWikivoyagePOI.createWithURL("http://wikivoyage.org/");
    Listing p4 = TestWikivoyagePOI.createWithURL("http://www.westinmalta.com");
    Listing p5 = TestWikivoyagePOI.createWithURL("http://www.nix.de");
    // Should not that be considered valid? It works in browsers
    Listing p6 = TestWikivoyagePOI.createWithURL("http://www.kitaena.co.jp/info/馬籠線.pdf");
    Listing p7 = TestWikivoyagePOI.createWithURL("http://www.ville-douai.fr/index.php/Théâtre?idpage=14004");
    Listing p8 = TestWikivoyagePOI.createWithURL("http://www.kitaena.co.jp/info/馬籠線.pdf");
    Listing p9 = TestWikivoyagePOI.createWithURL("http://www.natuurenbos.be/nl-BE/Domeinen/Vlaams-Brabant/arborétum_Heverleebos.aspx");
    Listing p10 = TestWikivoyagePOI.createWithURL("http://www.some-url.de?q=glück");
    Listing p11 = TestWikivoyagePOI.createWithURL("https://www.emirates.store/");
    // Prepare validation iterable
    Iterable<Listing> pois = new WebsiteURLValidator().validate(Arrays.asList(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11));
    // Check results
    for (Listing poi : pois) {
        assertTrue(poi.isValid());
    }
}
Also used : Listing(org.wikivoyage.listings.entity.Listing) WebsiteURLValidator(org.wikivoyage.listings.validators.WebsiteURLValidator) Test(org.junit.Test)

Example 13 with Listing

use of org.wikivoyage.listings.entity.Listing in project wikivoyage-listings by baturin.

the class TestWikivoyagePOI method wikidata.

@Test
public void wikidata() {
    // Valid
    Listing p1 = TestWikivoyagePOI.createWithWikidata("Q42");
    // Invalid
    Listing p2 = TestWikivoyagePOI.createWithWikidata("Q42\"");
    Listing p3 = TestWikivoyagePOI.createWithWikidata("Q4 2");
    Listing p4 = TestWikivoyagePOI.createWithWikidata("QID42");
    Listing p5 = TestWikivoyagePOI.createWithWikidata("q42");
    // Prepare validation iterator
    Iterator<Listing> validationIterator = new WikidataValidator().validate(Arrays.asList(p1, p2, p3, p4, p5)).iterator();
    // Check results
    assertTrue(validationIterator.next().isValid());
    assertFalse(validationIterator.next().isValid());
    assertFalse(validationIterator.next().isValid());
    assertFalse(validationIterator.next().isValid());
    assertFalse(validationIterator.next().isValid());
}
Also used : WikidataValidator(org.wikivoyage.listings.validators.WikidataValidator) Listing(org.wikivoyage.listings.entity.Listing) Test(org.junit.Test)

Example 14 with Listing

use of org.wikivoyage.listings.entity.Listing in project wikivoyage-listings by baturin.

the class NavigationXMLOutputFormat method write.

@Override
public void write(Iterable<Listing> pois, String outputFilename, String dumpDate) throws WriteOutputException {
    try {
        LinkedList<Listing> filteredPois = new LinkedList<>();
        for (Listing poi : pois) {
            if (!poi.isPositionalDataEmpty()) {
                // POIs with no positional data are useless for navigation - do not add them
                // to reduce size of output file
                filteredPois.add(poi);
            }
        }
        Listing[] filteredPoisArr = filteredPois.toArray(new Listing[filteredPois.size()]);
        XMLSimpleNode rootNode = createXml(filteredPoisArr, dumpDate);
        rootNode.writeToFile(outputFilename);
    } catch (XMLSimpleNodeException e) {
        throw new WriteOutputException();
    }
}
Also used : XMLSimpleNode(org.wikivoyage.listings.utils.XMLSimpleNode) Listing(org.wikivoyage.listings.entity.Listing) XMLSimpleNodeException(org.wikivoyage.listings.utils.XMLSimpleNodeException) LinkedList(java.util.LinkedList)

Example 15 with Listing

use of org.wikivoyage.listings.entity.Listing in project wikivoyage-listings by baturin.

the class OsmAndGPX method createXml.

@Override
public XMLSimpleNode createXml(Listing[] pois, String dumpDate) throws XMLSimpleNodeException {
    XMLSimpleNode gpxNode = new XMLSimpleNode("gpx", dumpDate).attrib("version", "1.1").attrib("creator", "wikivoyage-pois-converter").attrib("xmlns", "http://www.topografix.com/GPX/1/1").attribNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation", "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd");
    for (Listing poi : pois) {
        String name = poi.getTitle() + " (" + poi.getArticle() + ", " + poi.getType() + ")";
        new XMLSimpleNode(gpxNode, "wpt").attrib("lat", poi.getLatitude()).attrib("lon", poi.getLongitude()).textChild("name", name);
    }
    return gpxNode;
}
Also used : XMLSimpleNode(org.wikivoyage.listings.utils.XMLSimpleNode) Listing(org.wikivoyage.listings.entity.Listing)

Aggregations

Listing (org.wikivoyage.listings.entity.Listing)30 Test (org.junit.Test)16 XMLSimpleNode (org.wikivoyage.listings.utils.XMLSimpleNode)5 BufferedWriter (java.io.BufferedWriter)3 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)3 French (org.wikivoyage.listings.language.french.French)3 WebsiteURLValidator (org.wikivoyage.listings.validators.WebsiteURLValidator)3 LinkedList (java.util.LinkedList)2 EmailValidator (org.wikivoyage.listings.validators.EmailValidator)2 WikidataValidator (org.wikivoyage.listings.validators.WikidataValidator)2 FileOutputStream (java.io.FileOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 ParserConfig (org.sweble.wikitext.parser.ParserConfig)1 WikitextPreprocessor (org.sweble.wikitext.parser.WikitextPreprocessor)1 WtNode (org.sweble.wikitext.parser.nodes.WtNode)1 SimpleParserConfig (org.sweble.wikitext.parser.utils.SimpleParserConfig)1 StringConversionException (org.sweble.wikitext.parser.utils.StringConversionException)1