// $Id: Outputter.cs 1295 2007-05-11 16:52:51Z josd $ namespace Eulersharp.test { using System; using System.IO; using System.Collections; /// /// This class outputs the results and the proofs of the different tests /// public class Outputter { private static readonly object LOCK = new object(); private static Outputter instance = null; private Hashtable _files = new Hashtable(); /// /// This method constructs an outputter object. This constructor is /// private because this class acts as a singleton. The only instance of this /// class should be retrieved via the getInstance() method /// private Outputter() { } /// /// This method returns the only instance of this class /// /// the only instance of this class public static Outputter getInstance() { lock (LOCK) { if (instance == null) { instance = new Outputter(); } } return instance; } /// /// This method initializes the given file by writing a header to the file /// /// the file to be initialized. public void initialize(String file) { if (_files[file] == null) { using (StreamWriter sw = new StreamWriter(file)) { sw.WriteLine("@prefix r: ."); sw.WriteLine("@prefix xsd: ."); sw.WriteLine("@prefix rdfs: ."); sw.WriteLine("@prefix rdf: ."); sw.WriteLine("@prefix : <#>."); sw.WriteLine(); sw.WriteLine(":eulersharp rdfs:comment \"\"\"EulerSharp"); sw.WriteLine("is an inference engine supporting logic based proofs."); sw.WriteLine("It is a backward-chaining reasoner enhanced with Euler path detection and will tell"); sw.WriteLine("you whether a given set of facts and rules supports a given conclusion."); sw.WriteLine("To parse the manifests and the test documents Jena 2 is used.\"\"\"^^rdf:XMLLiteral;"); sw.WriteLine("rdfs:label \"EulerSharp\";"); sw.WriteLine("rdfs:seeAlso ."); sw.WriteLine(); _files.Add(file, file); } } } /// /// This method adds the given result to the correct result file /// /// the file to be extended. /// The result to be appended to the given result file public void addToResult(String file, String result) { using (StreamWriter sw = new StreamWriter(file, true)) { sw.WriteLine(result); } } /// /// This method writes a proof into a given file /// /// the file to be extended. /// The proof to be saved in the given file public void writeProof(String file, String proof) { using (StreamWriter sw = new StreamWriter(file)) { sw.WriteLine(proof); } } } }