All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.articulate.sigma.HTMLformatter Maven / Gradle / Ivy

Go to download

Sigma knowledge engineering system is an system for developing, viewing and debugging theories in first order logic. It works with Knowledge Interchange Format (KIF) and is optimized for the Suggested Upper Merged Ontology (SUMO) www.ontologyportal.org.

There is a newer version: 2.10
Show newest version
package com.articulate.sigma;

/* This code is copyright Articulate Software (c) 2003-2011.  Some portions
copyright Teknowledge (c) 2003 and reused under the terms of the GNU license.
This software is released under the GNU Public License .
Users of this code also consent, by use of this code, to credit Articulate Software
and Teknowledge in any writings, briefings, publications, presentations, or
other representations of any software which incorporates, builds on, or uses this
code.  Please cite the following article in any publication with references:

Pease, A., (2003). The Sigma Ontology Development Environment,
in Working Notes of the IJCAI-2003 Workshop on Ontology and Distributed Systems,
August 9, Acapulco, Mexico. See also http://sigmakee.sourceforge.net
 */

import com.articulate.sigma.nlg.NLGUtils;

import java.io.File;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/** A utility class that creates HTML-formatting Strings for various purposes. */
public class HTMLformatter {

    public static String htmlDivider =
        (""
                + ""
                + "
" + "" + "


\n"); // set by BrowseBody.jsp or SimpleBrowseBody.jsp public static String kbHref = ""; // set by BrowseBody.jsp or SimpleBrowseBody.jsp public static String language = "EnglishLanguage"; public static ArrayList availableFormalLanguages = new ArrayList(Arrays.asList("SUO-KIF","TPTP","traditionalLogic","OWL")); /** ************************************************************* * Create the HTML for the labeled divider between the sections * of the term display. Each section displays a sorted list of * the Formulae for which a term appears in a specified argument * position. */ public static String htmlDivider(String label) { String result = ""; try { StringBuilder sb = new StringBuilder(); sb.append("

"); sb.append(""); sb.append(StringUtil.getLineSeparator()); if (StringUtil.isNonEmptyString(label)) { sb.append(" "); sb.append(StringUtil.getLineSeparator()); sb.append(" "); sb.append(StringUtil.getLineSeparator()); sb.append(" "); sb.append(StringUtil.getLineSeparator()); } sb.append(" "); sb.append(StringUtil.getLineSeparator()); sb.append(" "); sb.append(StringUtil.getLineSeparator()); sb.append(" "); sb.append(StringUtil.getLineSeparator()); sb.append("
"); sb.append(StringUtil.getLineSeparator()); sb.append(" "); sb.append(label); sb.append(""); sb.append(StringUtil.getLineSeparator()); sb.append("
"); sb.append(StringUtil.getLineSeparator()); sb.append(" "); sb.append(""); sb.append(StringUtil.getLineSeparator()); sb.append("
"); sb.append(StringUtil.getLineSeparator()); sb.append("
"); sb.append("
"); sb.append(StringUtil.getLineSeparator()); result = sb.toString(); } catch (Exception ex) { ex.printStackTrace(); } return result; } /** ************************************************************* * Create the HTML for a single step in a proof. */ public static String createKBHref(String kbName, String language) { String hostname = KBmanager.getMgr().getPref("hostname"); if (hostname == null) hostname = "localhost"; String port = KBmanager.getMgr().getPref("port"); if (port == null) port = "8080"; return "http://" + hostname + ":" + port + "/sigma/Browse.jsp?lang=" + language + "&kb=" + kbName; } /** ************************************************************* * Create the HTML for a single step in a proof. */ public static String proofTableFormat(String query, ProofStep step, String kbName, String language) { // System.out.println("Info in HTMLformatter.proofTableFormat(): " + step); StringBuilder result = new StringBuilder(); Formula f = new Formula(); KB kb = KBmanager.getMgr().getKB(kbName); f.read(step.axiom); f.theFormula = Formula.postProcess(f.theFormula); f.theFormula = ProofProcessor.removeNestedAnswerClause(f.theFormula); String kbHref = HTMLformatter.createKBHref(kbName,language); if (f.theFormula.equalsIgnoreCase("FALSE")) { // Successful resolution theorem proving results in a contradiction. f.theFormula = "True"; // Change "FALSE" to "True" so it makes more sense to the user. result.append("" + "True" + ""); } else result.append("" + f.htmlFormat(kbHref) + ""); result.append(""); // System.out.println("Info in HTMLformatter.proofTableFormat(): premises : " + step.premises); if (step.inferenceType!=null && step.inferenceType.equals("assume_negation")) { result.append("[Negated Query]"); } else { for (int i = 0; i < step.premises.size(); i++) { Integer stepNum = (Integer) step.premises.get(i); result.append(stepNum.toString() + " "); } if (step.premises.size() == 0) { if (step.formulaType != null && step.formulaType.equals("conjecture")) result.append("[Query]"); else if (step.formulaRole != null) result.append(step.formulaRole); else result.append("[KB]"); } } result.append(""); if (StringUtil.isNonEmptyString(language)) { String pph = NLGUtils.htmlParaphrase(kbHref, f.theFormula, KBmanager.getMgr().getKB(kbName).getFormatMap(language), KBmanager.getMgr().getKB(kbName).getTermFormatMap(language), kb, language); if (StringUtil.emptyString(pph)) pph = ""; else { pph = NLGUtils.upcaseFirstVisibleChar(pph, true, language); boolean isArabic = (language.matches(".*(?i)arabic.*") || language.equalsIgnoreCase("ar")); if (isArabic) pph = ("" + pph + ""); // pph = ("‫" + pph + "‬"); } result.append(pph); } result.append(""); return result.toString(); } /** ************************************************************* */ public static String processFormalLanguage(String flang) { if (!StringUtil.isNonEmptyString(flang) || !availableFormalLanguages.contains(flang)) return "SUO-KIF"; else return flang; } /** ************************************************************* */ public static String processNaturalLanguage(String lang, KB kb) { if (kb == null || !kb.availableLanguages().contains(lang) || !StringUtil.isNonEmptyString(lang)) return "EnglishLanguage"; else return lang; } /** ************************************************************* * Show a hyperlinked list of terms. */ public static String termList(ArrayList terms, String kbHref) { StringBuilder show = new StringBuilder(); for (int i = 0; i < terms.size(); i++) { String term = terms.get(i); show.append("" + term + ""); if (i < terms.size()-1) show.append(", "); } return show.toString(); } /** ************************************************************* * Show knowledge base statistics */ public static String showStatistics(KB kb) { StringBuilder show = new StringBuilder(); show.append("Knowledge base statistics:
"); show.append("\n"); show.append("
Total TermsTotal AxiomsTotal Rules
" + kb.getCountTerms()); show.append(" " + kb.getCountAxioms()); show.append(" " + kb.getCountRules()); show.append("

\n"); show.append("Relations: " + kb.getCountRelations()); show.append("

\n"); return show.toString(); } /** ************************************************************* * Show a map if coordinates are given in the kb */ public static String showMap(KB kb, String term) { ArrayList lats = kb.askWithRestriction(0,"latitude",1,term); ArrayList lons = kb.askWithRestriction(0,"longitude",1,term); String result = ""; int zoom = 12; if (lats != null && lats.size() > 0 && lons != null && lons.size() > 0) { Formula f = lats.get(0); String lat = f.getArgument(2); f = lons.get(0); String lon = f.getArgument(2); if (kb.childOf(term,"Nation")) zoom = 6; if (kb.childOf(term,"Ocean")) zoom = 3; if (kb.childOf(term,"Continent")) zoom = 6; result = "\n"; } return result; } /** ************************************************************* * Show knowledge base pictures */ public static String showPictures(KB kb, String term) { return showNumberPictures(kb,term,4); } /** ************************************************************* * Show knowledge base pictures */ public static String showNumberPictures(KB kb, String term, int count) { StringBuilder show = new StringBuilder(); ArrayList pictures = kb.askWithRestriction(0,"externalImage",1,term); // Handle picture display if (pictures != null && pictures.size() > 0) { show.append("
"); int numPictures = pictures.size(); boolean more = false; if (pictures.size() > count) { numPictures = count; more = true; } for (int i = 0; i < numPictures; i++) { Formula f = pictures.get(i); String url = f.getArgument(2); if (url.startsWith("\"http://upload.wikimedia.org")) { String imageFile = url.substring(url.lastIndexOf("/")+1,url.length()-1); if (imageFile.matches("\\d+px-.*")) imageFile = imageFile.substring(imageFile.indexOf("px-")+3); String domain = "http://simple.wikipedia.org/"; if (url.indexOf("/en/") > -1) domain = "http://en.wikipedia.org/"; if (url.indexOf("/commons/") > -1) domain = "http://commons.wikimedia.org/"; show.append("\n" ); } else show.append("\n"); } if (more) show.append("more pictures..."); } return show.toString(); } public static String showNeighborTerms(KB kb, String term) { return HTMLformatter.showNeighborTerms(kb, term, term); } /** ************************************************************* * Show alphabetic list of neighbor terms */ public static String showNeighborTerms(KB kb, String nonRelTerm, String relTerm) { String markup = ""; try { StringBuilder show = new StringBuilder(); ArrayList relations = kb.getNearestRelations(relTerm); ArrayList nonRelations = kb.getNearestNonRelations(nonRelTerm); String lowcaseTerm = Character.toLowerCase(nonRelTerm.charAt(0)) + nonRelTerm.substring(1); String uppercaseTerm = Character.toUpperCase(relTerm.charAt(0)) + relTerm.substring(1); show.append("

"); markup = show.toString(); } catch (Exception ex) { ex.printStackTrace(); } return markup; } /** ***************************************************** */ public static ArrayList getAllRelTerms(KB kb, ArrayList matchesList) { ArrayList result = new ArrayList(); for (int i = 0; i < matchesList.size(); i++) if (kb.kbCache.relations.contains(matchesList.get(i))) result.add(matchesList.get(i)); return result; } /** ***************************************************** */ public static ArrayList getAllNonRelTerms(KB kb, ArrayList matchesList) { ArrayList result = new ArrayList(); for (int i = 0; i < matchesList.size(); i++) if (!kb.kbCache.relations.contains(matchesList.get(i))) result.add(matchesList.get(i)); return result; } /** ***************************************************** * Show list of 30 relation & nonRelation terms that contain a match to the input RE term. The inputed Strings * relREmatch and nonRelREmatch are the two relation and nonRelation terms respectively that are the first terms * at the top of the list. They are passed into the method to keep track of what 30 terms are being viewed. */ public static String showREMatches(KB kb, String relREmatch, String nonRelREmatch, String term) { String markup = ""; try { StringBuilder show = new StringBuilder(); ArrayList matchesList = kb.getREMatch(term); ArrayList relTermsList = getAllRelTerms(kb,matchesList); ArrayList nonRelTermsList = getAllNonRelTerms(kb,matchesList); ArrayList largerList = (relTermsList.size()>nonRelTermsList.size())?relTermsList:nonRelTermsList; ArrayList smallerList = (relTermsList.size()>nonRelTermsList.size())?nonRelTermsList:relTermsList; int sizeDiff = largerList.size() - smallerList.size(); for (int i = 0; i < sizeDiff; i++) { //buffer smaller list smallerList.add(""); } show.append("
"); show.append(""); show.append(""); show.append("\n

"); for (int i = 0; i < 30; i++) { String relation = (String) relations.get(i); String relationName = DocGen.getInstance(kb.name).showTermName(kb,relation,language); String nonRelation = (String) nonRelations.get(i); String nonRelationName = DocGen.getInstance(kb.name).showTermName(kb,nonRelation,language); if (! relation.isEmpty() || ! nonRelation.isEmpty()) { if (i == 0) show.append("\n"); show.append("\n"); show.append(" "); show.append(" "); show.append("\n"); if (i == 14) show.append("" + ""); if (i == 29) show.append("\n"); } } show.append("
" + relTerm + " " + nonRelTerm + "
previous " + 25 + "" + "
" + relation + " (" + relationName + ")" + "" + nonRelation + " (" + nonRelationName + ")" + "
" + uppercaseTerm + " " + lowcaseTerm + "
next " + 25 + "" + "
"); markup = show.toString(); break; } } } catch (Exception ex) { ex.printStackTrace(); } return markup; } /** ************************************************************* * Show a hyperlinked list of term mappings from WordNet. */ public static String termMappingsList(String terms, String kbHref) { StringBuilder result = new StringBuilder(); String[] sumoList = terms.split("\\s+"); result.append("

  • \tSUMO Mappings: "); for (int j=0; j" + sumoEquivalent + " "); String mapping = WordNetUtilities.mappingCharToName(symbol); result.append(" (" + mapping + " mapping) "); } result.append("\n\n
"); return result.toString(); } /** ************************************************************* * Show a hyperlinked list of WordNet synsets. */ public static String synsetList(ArrayList synsets, String kbHref) { StringBuilder show = new StringBuilder(); for (int i = 0; i < synsets.size(); i++) { String synset = (String) synsets.get(i); if (Character.isDigit(synset.charAt(0))) show.append("" + synset + ""); else show.append(synset); if (i < synsets.size()-1) show.append(", "); if (i % 10 == 0) show.append("\n"); } return show.toString(); } /** ************************************************************* * Create the HTML for a section of the Sigma term browser page. * Needs a
"); show.append(""); show.append(""); show.append("\n

"); for (String t : largerList) { if (t.equals((largerList==relTermsList?relREmatch:nonRelREmatch))) { //keeps track of which term is at the top int matchIndex = largerList.indexOf(t); //matchIndex is the index of an REmatch in the larger list int listLength = largerList.size(); //listLength is the the larger count of either relMatches or nonRelMatches int finalIndex = (listLength>(matchIndex + 29) ? (matchIndex + 30) : listLength); //finalIndex is 1 + the index of the final match that will be displayed //If there are at least 30 more matches after REmatch, then finalIndex=matchIndex+30, otherwise finalIndex = listLength for (int i=matchIndex;i\n"); show.append("\n"); if (nonRelTermsList.get(i) == "") show.append(" "); else { show.append(" "); } if (relTermsList.get(i) == "") show.append(" "); else { show.append(" "); } show.append("\n"); if (i==(finalIndex - 1) && listLength>(matchIndex + 30)) { int nextCount = (listLength>finalIndex+29)?30:(listLength-finalIndex+1); show.append("\n"); } } show.append("
" + term + "
previous " + 30 + "" + "
" + " " + "" + nonRelTermsList.get(i) + "" + " " + " " + "" + relTermsList.get(i) + "" + "
next " + nextCount + "" + "
...
enclosure to format HTML properly. */ public static String formatFormulaList(ArrayList forms, String header, KB kb, String language, String flang, int start, int localLimit, String limitString) { boolean traditionalLogic = false; if (flang.equals("traditionalLogic")) traditionalLogic = true; StringBuilder show = new StringBuilder(); boolean isArabic = (language.matches(".*(?i)arabic.*") || language.equalsIgnoreCase("ar")); if (forms.size() < localLimit || localLimit == 0) localLimit = forms.size(); for (int i = start; i < localLimit; i++) { System.out.println(forms.get(i).getClass().getName()); String strForm = forms.get(i).theFormula; //System.out.println("INFO in HTMLformatter.formatFormulaList(): formula: " + strForm); Formula f = (Formula) kb.formulaMap.get(strForm); //System.out.println("INFO in HTMLformatter.formatFormulaList(): structured formula: " + f); if (KBmanager.getMgr().getPref("showcached").equalsIgnoreCase("yes") || !f.sourceFile.endsWith(KB._cacheFileSuffix) ) { String arg0 = f.getArgument(0); show.append(""); String formattedFormula = null; if (flang.equals("TPTP") || flang.equals("traditionalLogic")) formattedFormula = TPTPutil.htmlTPTPFormat(f,kbHref,traditionalLogic) + "\n"; else formattedFormula = f.htmlFormat(kbHref) + "\n"; if (Formula.DOC_PREDICATES.contains(arg0)) show.append(kb.formatDocumentation(kbHref,formattedFormula,language)); else show.append(formattedFormula); File srcfile = new File(f.sourceFile); String sourceFilename = srcfile.getName(); if (StringUtil.isNonEmptyString(sourceFilename)) { show.append(sourceFilename); show.append(" " + f.startLine + "-" + f.endLine); } show.append(""); show.append("\n"); String pph = null; if (!Formula.DOC_PREDICATES.contains(arg0)) pph = NLGUtils.htmlParaphrase(kbHref, f.theFormula, kb.getFormatMap(language), kb.getTermFormatMap(language), kb, language); if (StringUtil.emptyString(pph)) pph = ""; else if (isArabic) pph = ("" + pph + ""); else pph = NLGUtils.upcaseFirstVisibleChar(pph, true, language); show.append(pph + "\n"); } } show.append(limitString); return show.toString(); } /** ************************************************************* * Create the HTML for a section of the Sigma term browser page. */ public static String browserSectionFormatLimit(String term, String header, KB kb, String language, String flang, int start, int limit, int arg, String type) { ArrayList forms = kb.ask(type,arg,term); StringBuilder show = new StringBuilder(); String limitString = ""; int localLimit = start + limit; if (forms != null && !KBmanager.getMgr().getPref("showcached").equalsIgnoreCase("yes")) forms = TaxoModel.removeCached(forms); if (forms != null && !forms.isEmpty()) { Collections.sort(forms); show.append(htmlDivider(header)); show.append(""); if (forms.size() < localLimit || localLimit == 0) localLimit = forms.size(); else limitString = ("\n"); show.append(formatFormulaList(forms,header,kb,language,flang,start,localLimit,limitString)); show.append(limitString); show.append("

Display limited to " + limit + " items. " + "Show next " + limit + "
\n"); } return show.toString(); } /** ************************************************************* * Create the HTML for a section of the Sigma term browser page. */ public static String browserSectionFormat(String term, String header, KB kb, String language, String flang, int arg, String type) { return browserSectionFormatLimit(term, header,kb, language, flang, 0, 50, arg,type); } /** ************************************************************* * Change spaces to "%20" along with many other URL codes. (for passing regex expressions through hyperlinks) */ public static String encodeForURL(String s) { s = s.replaceAll(" ","%20"); s = s.replaceAll("\\!","%21"); s = s.replaceAll("\\$","%24"); s = s.replaceAll("\\(","%28"); s = s.replaceAll("\\)","%29"); s = s.replaceAll("\\*","%2A"); s = s.replaceAll("\\+","%2B"); s = s.replaceAll("\\.","%2E"); s = s.replaceAll("\\?","%3F"); s = s.replaceAll("\\[","%5B"); s = s.replaceAll("\\]","%5D"); s = s.replaceAll("\\^","%5E"); return s; } /** ************************************************************* * Change spaces to "%20" */ public static String decodeFromURL(String s) { return s.replaceAll("%20"," "); } /** ************************************************************* * change reserved characters from '&' tags */ public static String encodeForHTML(String s) { s = s.replaceAll("<","<"); s = s.replaceAll(">",">"); return s; } /** ************************************************************* * change reserved characters to '&' tags */ public static String decodeFromHTML(String s) { s = s.replaceAll("<","<"); s = s.replaceAll(">",">"); return s; } /** ************************************************************* * Create an HTML menu, given an ArrayList of Strings where the * value(s) are String representations of int(s) but the displayed * menu items are String(s). */ public static String createNumberedMenu(String menuName, String selectedOption, ArrayList options) { StringBuilder result = new StringBuilder(); String menuNameProcessed = encodeForURL(menuName); result.append("\n"); return result.toString(); } /** ************************************************************* * Create an HTML menu, given an ArrayList of Strings. */ public static String createMenu(String menuName, String selectedOption, ArrayList options) { String params = null; return createMenu(menuName, selectedOption, options, params); } /** ************************************************************* * Create an HTML menu of KB names */ public static String createKBMenu(String kbName) { ArrayList kbnames = new ArrayList(); kbnames.addAll(KBmanager.getMgr().getKBnames()); return(HTMLformatter.createMenu("kb",kbName,kbnames)); } /** ************************************************************* * hyperlink formulas in error messages. It assumes that the errors * are in and TreeSet of Strings in kb.errors. It further * assumes that the error message is given first, followed by * a colon, and then the axiom. There must be no other colon * characters. */ //public static String formatErrors(KB kb, String kbHref) { public static String formatErrors(KB kb) { System.out.println("INFO in HTMLformatter.formatErrors(): href: " + kbHref); StringBuilder result = new StringBuilder(); Iterator it = kb.errors.iterator(); while (it.hasNext()) { String err = it.next(); err = err.replaceAll("\\n", "
"); int p = err.indexOf(":"); String begin = "
"; String end = ""; if (p > -1) { begin += err.substring(0, p + 1); end = err.substring(p + 1); Formula f = new Formula(); f.theFormula = end; //end = f.htmlFormat(kbHref); end = f.htmlFormat(kb); } else begin = err; result.append(begin + end + "

"); } return result.toString(); } /** ************************************************************* * Create an HTML menu with an ID, given an ArrayList of * Strings, and possibly multiple selections. */ public static String createMultiMenu(String menuName, TreeMap options) { StringBuilder result = new StringBuilder(); String menuNameProcessed = encodeForURL(menuName); result.append("\n"); return result.toString(); } /** ************************************************************* * Create an HTML menu with an ID, given an ArrayList of Strings. */ public static String createMenu(String menuName, String selectedOption, ArrayList options, String params) { StringBuilder result = new StringBuilder(); TreeSet menuOptions = new TreeSet(); menuOptions.addAll(options); String menuNameProcessed = encodeForURL(menuName); result.append("\n"); return result.toString(); } /** ************************************************************* * Create an HTML formatted result of a query. */ public static String formatProofResult(String result, String stmt, String processedStmt, String lineHtml, String kbName, String language) { return formatProofResult(result, stmt, processedStmt, lineHtml, kbName, language, 1); } /** ************************************************************* */ public static String formatProofResult(String result, String stmt, String processedStmt, String lineHtml, String kbName, String language, int answerOffset) { if (result != null && result.toString().length() > 0) { BasicXMLparser res = new BasicXMLparser(result.toString()); if (res != null) { ArrayList elements = res.elements; return formatProofResult(elements, stmt, processedStmt, lineHtml, kbName, language, answerOffset); } } return null; } /** ************************************************************* */ public static String formatTPTP3ProofResult(TPTP3ProofProcessor tpp, String stmt, String lineHtml, String kbName, String language) { System.out.println("INFO in HTMLformatter.formatTPTP3ProofResult(): number steps" + tpp.proof.size()); StringBuffer html = new StringBuffer(); for (int i = 0; i < tpp.bindings.size(); i++) { if (i != 0) html.append(lineHtml + "\n"); html.append("Answer " + "\n"); html.append(i+1); html.append(". "); String term = TPTP2SUMO.transformTerm(tpp.bindings.get(i)); String kbHref = HTMLformatter.createKBHref(kbName,language); html.append("" + term + ""); html.append("
"); } html.append("

" + "\n"); for (int l = 0; l < tpp.proof.size(); l++) { if (l % 2 == 1) html.append("" + "\n"); else html.append("" + "\n"); html.append("" + "\n"); html.append(HTMLformatter.proofTableFormat(stmt,tpp.proof.get(l), kbName, language) + "\n"); html.append("\n" + "\n"); } html.append("
" + "\n"); html.append(l+1); html.append(".
" + "\n"); return html.toString(); } /** ************************************************************* */ public static String formatProofResult(ArrayList proof, String stmt, String processedStmt, String lineHtml, String kbName, String language, int answerOffset) { StringBuilder html = new StringBuilder(); ProofProcessor pp = new ProofProcessor(proof); for (int i = 0; i < pp.numAnswers(); i++) { ArrayList proofSteps = null; // proofSteps = pp.getProofSteps(i); proofSteps = new ArrayList(ProofStep.normalizeProofStepNumbers(proofSteps)); proofSteps = new ArrayList(ProofStep.removeDuplicates(proofSteps)); if (i != 0) html = html.append(lineHtml + "\n"); html = html.append("Answer " + "\n"); html = html.append(i+answerOffset); html = html.append(". "); String[] answer = null; //answer = pp.returnAnswer(i, processedStmt).split(";"); for(int k=0; k"); String answerstr = null; //answerstr = pp.returnAnswer(i, processedStmt); if (!answerstr.equalsIgnoreCase("no")) { html = html.append("

" + "\n"); for (int l = 0; l < proofSteps.size(); l++) { if (l % 2 == 1) html = html.append("" + "\n"); else html = html.append("" + "\n"); html = html.append("" + "\n"); html = html.append(HTMLformatter.proofTableFormat(stmt,(ProofStep) proofSteps.get(l), kbName, language) + "\n"); html = html.append("\n" + "\n"); } html = html.append("
" + "\n"); html = html.append(l+1); html = html.append(".
" + "\n"); } } } return html.toString(); } /** ************************************************************* */ public static String formatConsistencyCheck(String msg, String ccheckResult, String language, int page) { StringBuilder html = new StringBuilder(); String lineHtml = "

\n"; html.append(msg); html.append("
"); if (ccheckResult != null) { BasicXMLparser res = new BasicXMLparser(ccheckResult); String kbName = null; try { if (res != null) { ArrayList elements = res.elements; ArrayList subElements = ((BasicXMLelement) elements.get(0)).subelements; for (int i = 0; i < subElements.size(); i++) { BasicXMLelement item = (BasicXMLelement) subElements.get(i); if (item.tagname.equals("kb")) kbName = item.contents; else if (item.tagname.equals("entries")) { ArrayList entries = ((BasicXMLelement) subElements.get(i)).subelements; html.append("
Consistency Check Results:
"); if (page == 0) { String pagelink = "CCheck.jsp?kb=" + kbName + "&lang=" + language + "&page="; html.append("
"); html.append(""); html.append(""); for (int j=0; j < entries.size(); j++) { ArrayList entry = ((BasicXMLelement) entries.get(j)).subelements; String query = null; String type = null; String sourceFile = null; for (int k=0; k < entry.size(); k++) { BasicXMLelement entryItem = (BasicXMLelement) entry.get(k); if (entryItem.tagname.equals("query")) query = entryItem.contents; else if (entryItem.tagname.equals("type")) type = entryItem.contents; else if (entryItem.tagname.equals("sourceFile")) sourceFile = entryItem.contents; } int pageNum = j + 1; html.append(""); } html.append("
QueryResult TypeSource File
" + query + "" + type + "" + sourceFile + "
"); if (entries.size() > 0) html.append("

Individual Results >>

"); } else if (page >= 1 && page <= entries.size()) { int j = page - 1; ArrayList entry = ((BasicXMLelement) entries.get(j)).subelements; String query = null; String type = null; String processedQ = null; String proof = null; String sourceFile = null; for (int k=0; k < entry.size(); k++) { BasicXMLelement entryItem = (BasicXMLelement) entry.get(k); if (entryItem.tagname.equals("query")) query = entryItem.contents; else if (entryItem.tagname.equals("type")) type = entryItem.contents; else if (entryItem.tagname.equals("processedStatement")) processedQ = entryItem.contents; else if (entryItem.tagname.equals("sourceFile")) sourceFile = entryItem.contents; else if (entryItem.tagname.equals("proof")) { if (type.indexOf("Error") == -1) if (entryItem.attributes.get("src") != null && entryItem.attributes.get("src").equals("EProver")) proof = formatProofResult(entryItem.subelements, query, processedQ, lineHtml, kbName, language, 0); else { proof = entryItem.contents; proof = proof.replaceAll("%3C","<"); proof = proof.replaceAll("%3E",">"); } else proof = entryItem.contents; } } html.append("
Query: " + query + "
"); html.append("Type: " + type + "
"); html.append("Source File: " + sourceFile + "

"); html.append(proof); html.append(lineHtml); html.append(""); int before = page - 1; int after = page + 1; if (page == 1) html.append(""); else if (page > 1) { html.append(""); html.append(""); } if (after <= entries.size() && page >= 1) html.append(""); html.append("
<< Summary Result<< Prev<< Summary Results >>Next >>
"); } } } } } catch (Exception ex) { System.out.println(ex.getMessage()); } } return html.toString(); } /** ************************************************************* */ public static void main(String[] args) { try { KBmanager.getMgr().initializeOnce(); } catch (Exception ex ) { System.out.println(ex.getMessage()); } KB kb = KBmanager.getMgr().getKB("SUMO"); System.out.println("INFO in HTMLformatter.main()"); ArrayList forms = KButilities.termIntersection(kb,"ShapeChange","ShapeAttribute"); /* should get from Merge.kif 15034-15041 * (=> (and (instance ?OBJ Object) (attribute ?OBJ Pliable)) (exists (?CHANGE) (and (instance ?CHANGE ShapeChange) (patient ?CHANGE ?OBJ)))) */ System.out.println("INFO in HTMLformatter.main(): got intersections: " + forms); System.out.println("HTMLformatter.main() ready to call formatFormulaList( )"); System.out.println(HTMLformatter.formatFormulaList(forms,"", kb, "EnglishLanguage", "SUO-KIF", 0, 0, "")); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy