001 /*
002 * (c) 2009
003 * Damian Steer <mailto:pldms@mac.com>
004 */
005
006 package net.rootdev.javardfa;
007
008 import net.rootdev.javardfa.jena.JenaStatementSink;
009 import net.rootdev.javardfa.*;
010 import com.hp.hpl.jena.query.Query;
011 import com.hp.hpl.jena.query.QueryExecution;
012 import com.hp.hpl.jena.query.QueryExecutionFactory;
013 import com.hp.hpl.jena.query.QueryFactory;
014 import com.hp.hpl.jena.rdf.model.Model;
015 import com.hp.hpl.jena.rdf.model.ModelFactory;
016 import com.hp.hpl.jena.util.FileManager;
017 import java.io.IOException;
018 import java.io.InputStream;
019 import java.util.Map;
020 import java.util.Map.Entry;
021 import javax.xml.stream.XMLInputFactory;
022 import net.rootdev.javardfa.ParserFactory.Format;
023 import net.rootdev.javardfa.output.OGPReader;
024 import org.xml.sax.InputSource;
025 import org.xml.sax.SAXException;
026 import org.xml.sax.XMLReader;
027 import org.xml.sax.helpers.XMLReaderFactory;
028
029 /**
030 *
031 * @author pldms
032 */
033 public class Scratch {
034
035 private static XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
036
037 public static void main(String[] args) throws SAXException, IOException, ClassNotFoundException {
038 Map<String, String> prop = OGPReader.getOGP("http://uk.rottentomatoes.com/m/1217700-kick_ass", Format.HTML);
039
040 for (Entry<String, String> ent: prop.entrySet()) {
041 System.err.printf("[%s] => '%s'\n", ent.getKey(), ent.getValue());
042 }
043
044 if (true) return;
045
046 String base = "http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/";
047 String testHTML = base + "0121.xhtml";
048 String testSPARQL = base + "0121.sparql";
049
050 check(testHTML, testSPARQL, Format.XHTML);
051
052 //XMLReader parser = ParserFactory.createReaderForFormat(new NTripleSink(System.out), Format.HTML);
053 //parser.parse(Scratch.class.getResource("/simple.html").toExternalForm());
054 /*Class.forName(RDFaReader.class.getName());
055 Model model = ModelFactory.createDefaultModel();
056 //model.read("http://www.ivan-herman.net/foaf.html", "HTML");
057 model.read("http://www.myspace.com/parishilton", "HTML");
058 System.err.println("== Read ==");
059 model.write(System.err, "TTL");*/
060 }
061
062 private static void check(String testHTML, String testSPARQL, Format format)
063 throws SAXException, IOException {
064 Model model = ModelFactory.createDefaultModel();
065 StatementSink sink = new JenaStatementSink(model);
066 InputStream in = FileManager.get().open(testHTML);
067
068 XMLReader reader = ParserFactory.createReaderForFormat(sink, format);
069
070 InputSource ins = new InputSource(in);
071 ins.setEncoding("utf-8");
072 ins.setSystemId(testHTML);
073 reader.parse(ins);
074 Query theQuery = QueryFactory.read(testSPARQL);
075 QueryExecution qe = QueryExecutionFactory.create(theQuery, model);
076 if (qe.execAsk()) {
077 System.err.println("It worked! " + testHTML);
078 return;
079 }
080
081 System.err.println("Failed: ");
082 model.write(System.err, "TTL");
083 System.err.println(theQuery);
084 }
085
086 }