Search in sources :

Example 26 with Listing

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

the class SQL method write.

@Override
public void write(Iterable<Listing> pois, String outputFilename, String dumpDate) throws WriteOutputException {
    BufferedWriter writer = null;
    try {
        try {
            FileWriter fwriter = new FileWriter(outputFilename);
            writer = new BufferedWriter(fwriter);
            writer.write("-- Generated from " + dumpDate + " Wikivoyage data.\n");
            writer.write(// These PRAGMAs make loading thousand times faster.
            "PRAGMA synchronous=OFF;\n" + "PRAGMA count_changes=OFF;\n" + "PRAGMA journal_mode=MEMORY;\n" + "PRAGMA temp_store=MEMORY;\n" + "DROP TABLE IF EXISTS wikivoyage_listings;\n");
            writer.write("CREATE TABLE wikivoyage_listings (" + "id INTEGER PRIMARY KEY, " + "article VARCHAR(128), " + "type VARCHAR(64), " + "title VARCHAR(128), " + "wikidata VARCHAR(64), " + "wikipedia VARCHAR(64), " + "alt VARCHAR(128), " + "address VARCHAR(255), " + "directions VARCHAR(255), " + "phone VARCHAR(128), " + "tollfree VARCHAR(128), " + "email VARCHAR(128), " + "fax VARCHAR(128), " + "url VARCHAR(128), " + "hours VARCHAR(128), " + "checkin VARCHAR(128), " + "checkout VARCHAR(128), " + "image VARCHAR(255)," + "price VARCHAR(128), " + "latitude DECIMAL(10, 8), " + "longitude DECIMAL(11, 8), " + "wifi VARCHAR(128), " + "accessibility VARCHAR(128), " + "lastedit VARCHAR(128), " + "description VARCHAR(4096), " + "language VARCHAR(2)" + ");\n");
            for (Listing poi : pois) {
                writer.write("INSERT INTO wikivoyage_listings (" + "article, " + "type, " + "title, " + "wikidata, " + "wikipedia, " + "alt, " + "address, " + "directions, " + "phone, " + "tollfree, " + "email, " + "fax, " + "url, " + "hours, " + "checkin, " + "checkout, " + "image, " + "price, " + "latitude, " + "longitude, " + "wifi, " + "accessibility, " + "lastedit, " + "description, " + "language" + ") " + "VALUES (" + escape(poi.getArticle()) + ", " + escape(poi.getType()) + ", " + escape(poi.getTitle()) + ", " + escape(poi.getWikidata()) + ", " + escape(poi.getWikipedia()) + ", " + escape(poi.getAlt()) + ", " + escape(poi.getAddress()) + ", " + escape(poi.getDirections()) + ", " + escape(poi.getPhone()) + ", " + escape(poi.getTollFree()) + ", " + escape(poi.getEmail()) + ", " + escape(poi.getFax()) + ", " + escape(poi.getUrl()) + ", " + escape(poi.getHours()) + ", " + escape(poi.getCheckIn()) + ", " + escape(poi.getCheckOut()) + ", " + escape(poi.getImage()) + ", " + escape(poi.getPrice()) + ", " + getPositionalValue(poi.getLatitude(), 90.0) + ", " + getPositionalValue(poi.getLongitude(), 180.0) + ", " + escape(poi.getWifi()) + ", " + escape(poi.getAccessibility()) + ", " + escape(poi.getLastEdit()) + ", " + escape(poi.getDescription()) + ", " + escape(poi.getLanguage()) + ");\n");
            }
        } finally {
            if (writer != null) {
                writer.close();
            }
        }
    } catch (IOException e) {
        throw new WriteOutputException();
    }
}
Also used : Listing(org.wikivoyage.listings.entity.Listing) FileWriter(java.io.FileWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 27 with Listing

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

the class Xml method createXml.

public XMLSimpleNode createXml(Listing[] pois, String dumpDate) throws XMLSimpleNodeException {
    XMLSimpleNode genericNode = new XMLSimpleNode("wikivoyage", dumpDate).attrib("version", "0.5").attrib("generator", "wikivoyage-pois-converter");
    for (Listing poi : pois) {
        XMLSimpleNode poiNode = new XMLSimpleNode(genericNode, "node").attrib("id", nodeId.toString()).attrib("article", poi.getArticle()).attrib("type", poi.getType()).attrib("title", poi.getTitle()).attrib("alt", poi.getAlt()).attrib("wikidata", poi.getWikidata()).attrib("wikipedia", poi.getWikipedia()).attrib("address", poi.getAddress()).attrib("directions", poi.getDirections()).attrib("phone", poi.getPhone()).attrib("tollFree", poi.getTollFree()).attrib("email", poi.getEmail()).attrib("fax", poi.getFax()).attrib("url", poi.getUrl()).attrib("lat", poi.getLatitude()).attrib("lon", poi.getLongitude()).attrib("hours", poi.getHours()).attrib("checkIn", poi.getCheckIn()).attrib("checkOut", poi.getCheckOut()).attrib("image", poi.getImage()).attrib("price", poi.getPrice()).attrib("wifi", poi.getWifi()).attrib("accessibility", poi.getAccessibility()).attrib("lastEdit", poi.getLastEdit()).attrib("description", poi.getDescription());
        nodeId++;
    }
    return genericNode;
}
Also used : XMLSimpleNode(org.wikivoyage.listings.utils.XMLSimpleNode) Listing(org.wikivoyage.listings.entity.Listing)

Example 28 with Listing

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

the class CsvOutputTests method Generate.

/**
 * Test CSV generation of the sample
 */
@Test
public void Generate() throws Exception {
    List<Listing> pois = new ArrayList<Listing>();
    pois.add(getSample());
    String output = File.createTempFile("wikivoyage-listings-unit-tests", ".tmp").getAbsolutePath();
    new CSV().write(pois, output, "20160720");
    compareWithSample(output, "sample-result.csv");
}
Also used : Listing(org.wikivoyage.listings.entity.Listing) CSV(org.wikivoyage.listings.output.CSV) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 29 with Listing

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

the class InputTests method processUnknownTemplate.

@Test
public void processUnknownTemplate() throws Exception {
    Listing poi = parseResourceSinglePOI("unknown-template.wikicode");
    Assert.assertEquals("Description with some {{unknown|template}} and another {{unknown|name=template}}", poi.getDescription());
}
Also used : Listing(org.wikivoyage.listings.entity.Listing) Test(org.junit.Test)

Example 30 with Listing

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

the class TestWikivoyagePOI method email.

@Test
public void email() {
    // Valid
    Listing p1 = TestWikivoyagePOI.createWithEmail("mary@wikivoyage.org");
    // Invalid
    Listing p2 = TestWikivoyagePOI.createWithEmail("\"mary@wikivoyage.org");
    Listing p3 = TestWikivoyagePOI.createWithEmail("mary@wikivoyage.org, jane@wikivoyage.org");
    Listing p4 = TestWikivoyagePOI.createWithEmail("mary@wikivoyage.org (reservations)");
    Listing p5 = TestWikivoyagePOI.createWithEmail("http://wikivoyage.org");
    // Prepare validation iterator
    Iterator<Listing> validationIterator = new EmailValidator().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 : EmailValidator(org.wikivoyage.listings.validators.EmailValidator) Listing(org.wikivoyage.listings.entity.Listing) Test(org.junit.Test)

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