// $Id: check.java,v 1.4 2003/05/24 15:27:07 mdean Exp $


class check
{
    static void usage()
    {
	System.err.println("Usage:  uri");
	System.exit(1);
    }

    public static void main(String args[])
	throws com.hp.hpl.mesa.rdf.jena.model.RDFException
    {
	com.hp.hpl.mesa.rdf.jena.model.Model model = new com.hp.hpl.mesa.rdf.jena.mem.ModelMem();
	if (args.length != 1)
	    usage();
	model.read(args[0]);

	System.out.println("graph G {");

	com.hp.hpl.mesa.rdf.jena.model.Property first = model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#first");
	com.hp.hpl.mesa.rdf.jena.model.Property rest = model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest");
	com.hp.hpl.mesa.rdf.jena.model.Property nil = model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
	
	com.hp.hpl.mesa.rdf.jena.model.ResIterator lines = model.listSubjectsWithProperty(com.hp.hpl.mesa.rdf.jena.vocabulary.RDF.type,
											  model.createResource("http://www.daml.org/2003/05/subway/subway-ont#Line"));
	while (lines.hasNext())
	    {
		com.hp.hpl.mesa.rdf.jena.model.Resource line = lines.next();
		
		String color = line.toString();
		int hash = color.lastIndexOf('#');
		if (hash != (-1))
		    color = color.substring(hash + 1);
		color = color.toLowerCase();

		com.hp.hpl.mesa.rdf.jena.model.Resource previousStation = null;
		
		for (com.hp.hpl.mesa.rdf.jena.model.Resource list = line.getProperty(model.createProperty("http://www.daml.org/2003/05/subway/subway-ont#stations")).getResource();
		     ! list.equals(nil);
		     list = list.getProperty(rest).getResource())
		    {
			com.hp.hpl.mesa.rdf.jena.model.Resource station = list.getProperty(first).getResource();
			if (previousStation != null)
			    System.out.println("  \"" + previousStation + "\" -- \"" + station + "\" [ color=\"" + color + "\" ];");
			previousStation = station;
		    }
	    }

	System.out.println("}");
    }
}
