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();
}
}
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;
}
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");
}
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());
}
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());
}
Aggregations