From 10fcc55c46753f1c1f3e2b5a2659263d7b64578e Mon Sep 17 00:00:00 2001 From: Rogan Creswick Date: Sun, 16 Jun 2013 22:08:45 -0700 Subject: removed debugging statements from upGoerFive rule, caught some exceptions in HeadlessAtom --- .../language-processing/natural/upGoerFive.js | 39 ++++++++++------------ .../main/java/com/galois/fiveui/HeadlessAtom.java | 14 ++++++-- .../src/main/java/com/galois/fiveui/Reporter.java | 2 +- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/exampleData/ruleSets/language-processing/natural/upGoerFive.js b/exampleData/ruleSets/language-processing/natural/upGoerFive.js index fb17a54..092a181 100644 --- a/exampleData/ruleSets/language-processing/natural/upGoerFive.js +++ b/exampleData/ruleSets/language-processing/natural/upGoerFive.js @@ -1,6 +1,6 @@ var natural = require('natural'); -rule = {}; +rule = {}; rule.name = "Common words"; rule.description = "Identifies rare word use (words not in the 1000 most common English word list)."; @@ -144,25 +144,25 @@ var stemmer = natural.PorterStemmer; var tokenizer = new natural.TreebankWordTokenizer(); var getTextNodesIn = function (node, includeWhitespaceNodes) { - var textNodes = [], whitespace = /^\s*$/; + var textNodes = [], whitespace = /^\s*$/; - function getTextNodes(node) { - if ($(node).attr('id') == 'fiveui-top') { - return; - } - if (node.nodeType == 3) { - if (includeWhitespaceNodes || !whitespace.test(node.nodeValue)) { - textNodes.push(node); - } - } else { - for (var i = 0, len = node.childNodes.length; i < len; ++i) { - getTextNodes(node.childNodes[i]); - } - } + function getTextNodes(node) { + if ($(node).attr('id') == 'fiveui-top') { + return; } + if (node.nodeType == 3) { + if (includeWhitespaceNodes || !whitespace.test(node.nodeValue)) { + textNodes.push(node); + } + } else { + for (var i = 0, len = node.childNodes.length; i < len; ++i) { + getTextNodes(node.childNodes[i]); + } + } + } - getTextNodes(node); - return textNodes; + getTextNodes(node); + return textNodes; }; var isCommonWord = function(word) { @@ -173,11 +173,9 @@ var isPunctuation = function(str) { return _.contains(['&', '%', '(', ')', ';', ':', '.', ',', '"', "'", '`', '!', '?' ], str); }; - var markWords = function(obj, report) { var toks = tokenizer.tokenize($(obj).text()); var rawObj = $('

', {id: 'text'}); -// $(obj).empty(); $(obj).replaceWith(rawObj); _.each(toks, function(tok) { @@ -192,14 +190,11 @@ var markWords = function(obj, report) { }; rule.rule = function(report) { - console.log("checking for rare words"); fiveui.query('body').each( function(i){ var nodes = getTextNodesIn(this); _.map(nodes, function(n){ - console.log(n); markWords(n, report); }); }); - console.log("done checking for rare words"); }; \ No newline at end of file diff --git a/src/batchtools/headless/src/main/java/com/galois/fiveui/HeadlessAtom.java b/src/batchtools/headless/src/main/java/com/galois/fiveui/HeadlessAtom.java index 01ffae0..12da948 100644 --- a/src/batchtools/headless/src/main/java/com/galois/fiveui/HeadlessAtom.java +++ b/src/batchtools/headless/src/main/java/com/galois/fiveui/HeadlessAtom.java @@ -48,8 +48,18 @@ public class HeadlessAtom { * @throws JsonParseException */ public static HeadlessAtom fromJsonObject(JsonObject obj, String dir) throws IOException { - String url = obj.get("url").getAsString(); - String ruleSet = obj.get("ruleSet").getAsString(); + String url = null; + String ruleSet = null; + + try { + url = obj.get("url").getAsString(); + } catch (NullPointerException e) { + } + + try { + ruleSet = obj.get("ruleSet").getAsString(); + } catch (NullPointerException e) { + } if (url == null || ruleSet == null) { throw new JsonParseException("could get either 'url' or 'ruleSet' properties"); diff --git a/src/batchtools/headless/src/main/java/com/galois/fiveui/Reporter.java b/src/batchtools/headless/src/main/java/com/galois/fiveui/Reporter.java index 5c0b233..cad8bee 100644 --- a/src/batchtools/headless/src/main/java/com/galois/fiveui/Reporter.java +++ b/src/batchtools/headless/src/main/java/com/galois/fiveui/Reporter.java @@ -92,7 +92,7 @@ public class Reporter { h1().text("Headless Run Summary").end(); p(); ul(); - li().a().href("byUrl.html").text("Results organized by URL").end().end(); + li().a().href("byURL.html").text("Results organized by URL").end().end(); li().a().href("byRule.html").text("Results organized by Rule").end().end(); end(); end(); -- cgit v1.2.3