From 594fe7de90b6a90c96fc7cd50b033c5234ab38b7 Mon Sep 17 00:00:00 2001 From: Meng Luan Date: Fri, 14 Nov 2014 22:52:00 -0400 Subject: [PATCH 1/2] keep comments by default --- src/ca/unb/meng/RuleML2TPTP.java | 50 +++++++++++++++----------------- src/resources/ruleml2tptp.xslt | 46 ++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 39 deletions(-) diff --git a/src/ca/unb/meng/RuleML2TPTP.java b/src/ca/unb/meng/RuleML2TPTP.java index 004c84b..4352e8d 100644 --- a/src/ca/unb/meng/RuleML2TPTP.java +++ b/src/ca/unb/meng/RuleML2TPTP.java @@ -153,18 +153,17 @@ private static Options buildOptions() { .withLongOpt("transformer-factory") .create('t')); options.addOption(OptionBuilder - .hasOptionalArg() + .hasArg() .withArgName("pattern") - .withDescription("keep comments matching given pattern " - + "or any pattern if pattern is omitted or empty") - .withLongOpt("keep-comments") + .withDescription("use give pattern to match comments") + .withLongOpt("comment-pattern") .create('c')); options.addOption(OptionBuilder .hasArg() .withArgName("flags") .withDescription("flags following the specification of XPath " - + "except for flag v (see NOTES below)") - .withLongOpt("matching-flags") + + "except for flag \"v\" (see NOTES below)") + .withLongOpt("comment-matching-flags") .create('g')); options.addOption(OptionBuilder .hasArg() @@ -182,12 +181,13 @@ private static Options buildOptions() { private static void printUsage(Options options) { new HelpFormatter().printHelp("java -jar ruleml2tptp.jar", null, options, String.format("%nNOTES%n" - + "If '-s' or '-o' is omitted, the standard input or " - + "output will be used accordingly.%n" - + "If '-h' is used, " - + "no XML transformation will be performed.%n" - + "Flag v means the matching behavior is reverted, " - + "so comments DO NOT match the given pattern are kept. " + + "If '-s' or '-o' is omitted, the standard input or output will be used accordingly.%n" + + "If '-h' is used, no XML transformation will be performed.%n" + + "By default, all the comments in the source will be kept in the output. " + + "'-c' can switch to keep only those matching the given pattern. " + + "An empty pattern has no effect. " + + "Flag \"v\" reverts the behavior by keeping those not matching the pattern, " + + "or by ignoring all the comments if no or empty pattern is given." ), true); System.out.println(); @@ -246,15 +246,19 @@ public void run(CommandLine cmd) throws FileNotFoundException, IOException, new BufferedReader(new InputStreamReader( xsltNormalizer)))); } else { + // parse translator parameters String commentPattern = cmd.getOptionValue('c'); - String matchingFlags = cmd.getOptionValue('g'); - if (matchingFlags == null) { - matchingFlags = ""; + if (commentPattern == null) { + commentPattern = ""; + } + String commentMatchingFlags = cmd.getOptionValue('g'); + if (commentMatchingFlags == null) { + commentMatchingFlags = ""; } - boolean keepComments = cmd.hasOption('c') - && (matchingFlags.indexOf('v') == -1); - matchingFlags = matchingFlags.replaceAll("v", ""); + boolean keepComments = (commentMatchingFlags.indexOf('v') == -1); + commentMatchingFlags = commentMatchingFlags.replaceAll("v", ""); boolean useCrlf = cmd.hasOption('r'); + Transformer translator = null; // to set params if (xsltNormalizer == null) { translator = tFactory.newTransformer( @@ -273,14 +277,8 @@ public void run(CommandLine cmd) throws FileNotFoundException, IOException, new BufferedReader(new InputStreamReader( xsltNormalizer)))); } - if (commentPattern != null && !commentPattern.isEmpty()) { - translator.setParameter( - "match-comments", commentPattern); - } - if (!matchingFlags.isEmpty()) { - translator.setParameter( - "matching-flags", matchingFlags); - } + translator.setParameter("comment-pattern", commentPattern); + translator.setParameter("comment-matching-flags", commentMatchingFlags); translator.setParameter("keep-comments", keepComments); translator.setParameter("use-crlf", useCrlf); } diff --git a/src/resources/ruleml2tptp.xslt b/src/resources/ruleml2tptp.xslt index 21ace22..366bb89 100644 --- a/src/resources/ruleml2tptp.xslt +++ b/src/resources/ruleml2tptp.xslt @@ -6,11 +6,11 @@ xmlns:r="http://ruleml.org/spec"> - + - + - + @@ -20,16 +20,36 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + From 2924c39ed01f73ee4da136e4e9e334ff83c52f42 Mon Sep 17 00:00:00 2001 From: Meng Luan Date: Fri, 14 Nov 2014 22:57:00 -0400 Subject: [PATCH 2/2] modify the help --- src/ca/unb/meng/RuleML2TPTP.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ca/unb/meng/RuleML2TPTP.java b/src/ca/unb/meng/RuleML2TPTP.java index 4352e8d..4e1193b 100644 --- a/src/ca/unb/meng/RuleML2TPTP.java +++ b/src/ca/unb/meng/RuleML2TPTP.java @@ -184,7 +184,7 @@ private static void printUsage(Options options) { + "If '-s' or '-o' is omitted, the standard input or output will be used accordingly.%n" + "If '-h' is used, no XML transformation will be performed.%n" + "By default, all the comments in the source will be kept in the output. " - + "'-c' can switch to keep only those matching the given pattern. " + + "Use '-c' to switch to keep only those matching the given pattern. " + "An empty pattern has no effect. " + "Flag \"v\" reverts the behavior by keeping those not matching the pattern, " + "or by ignoring all the comments if no or empty pattern is given."