Revision: 9199
http://languagetool.svn.sourceforge.net/languagetool/?rev=9199&view=rev
Author: dnaber
Date: 2013-01-23 23:21:27 +0000 (Wed, 23 Jan 2013)
Log Message:
-----------
delete conversion helpers not needed anymore
Removed Paths:
-------------
trunk/languagetool/languagetool-standalone/src/main/dev/org/languagetool/dev/MarkerConverter.java
trunk/languagetool/languagetool-standalone/src/main/dev/org/languagetool/dev/MarkerConverter2.java
Deleted:
trunk/languagetool/languagetool-standalone/src/main/dev/org/languagetool/dev/MarkerConverter.java
===================================================================
---
trunk/languagetool/languagetool-standalone/src/main/dev/org/languagetool/dev/MarkerConverter.java
2013-01-23 23:04:39 UTC (rev 9198)
+++
trunk/languagetool/languagetool-standalone/src/main/dev/org/languagetool/dev/MarkerConverter.java
2013-01-23 23:21:27 UTC (rev 9199)
@@ -1,203 +0,0 @@
-/* LanguageTool, a natural language style checker
- * Copyright (C) 2012 Daniel Naber (http://www.danielnaber.de)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
- * USA
- */
-package org.languagetool.dev;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.languagetool.JLanguageTool;
-import org.languagetool.Language;
-import org.languagetool.rules.Rule;
-import org.languagetool.rules.patterns.PatternRule;
-import org.languagetool.tools.StringTools;
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.ext.LexicalHandler;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * Convert to the new marker format. Note: is buggy at least with "and"
elements.
- *
- * @deprecated for internal one-time conversion only
- */
-public class MarkerConverter {
-
- private static final Language LANGUAGE = Language.GERMAN;
-
- public static void main(String[] args) throws SAXException,
ParserConfigurationException, IOException {
- final ConverterHandler handler = new ConverterHandler();
- final SAXParserFactory factory = SAXParserFactory.newInstance();
- final SAXParser saxParser = factory.newSAXParser();
-
saxParser.getXMLReader().setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",
false);
-
saxParser.getXMLReader().setProperty("http://xml.org/sax/properties/lexical-handler",
new MyLexicalHandler());
- saxParser.parse(new
FileInputStream("/home/dnaber/prg/languagetool-svn/trunk/JLanguageTool/src/rules/"
+ LANGUAGE.getShortName() + "/grammar.xml"), handler);
- }
-
- static class ConverterHandler extends DefaultHandler {
-
- private final Map<String, Integer> startPos = new HashMap<String,
Integer>();
- private final Map<String, Integer> endPos = new HashMap<String, Integer>();
-
- ConverterHandler() throws IOException {
- final JLanguageTool languageTool = new JLanguageTool(LANGUAGE);
- languageTool.activateDefaultPatternRules();
- final List<Rule> rules = languageTool.getAllRules();
- for (Rule rule : rules) {
- if (rule instanceof PatternRule) {
- final PatternRule pRule = (PatternRule) rule;
- //System.out.println("***" + pRule.getId() + " " + pRule.getSubId()
+ " --> " + pRule.getStartPositionCorrection()
- // + ", " + (pRule.getElements().size() +
pRule.getEndPositionCorrection()) + ", size: " + pRule.getElements());
- final String key = pRule.getId() + " " + pRule.getSubId();
- startPos.put(key, pRule.getStartPositionCorrection());
- endPos.put(key, pRule.getElements().size() +
pRule.getEndPositionCorrection());
- }
- }
- }
-
- @Override
- public void startPrefixMapping(String prefix, String uri) throws
SAXException {}
- @Override
- public void notationDecl(String name, String publicId, String systemId)
throws SAXException {}
- @Override
- public void unparsedEntityDecl(String name, String publicId, String
systemId, String notationName) throws SAXException {}
- @Override
- public void skippedEntity(String name) throws SAXException {}
-
- @Override
- public InputSource resolveEntity(String publicId, String systemId) throws
IOException, SAXException {
- return super.resolveEntity(publicId, systemId);
- }
-
- @Override
- public void processingInstruction(String target, String data) throws
SAXException {
- System.out.println("<?" + target + " " + data + "?>");
- }
-
- private int currentTokenPos = 0;
- private String currentId = "";
- private int currentSubId = 0;
- private boolean inCategory = false;
- private boolean inRuleGroup = false;
- private boolean needsMarker = false;
-
- @Override
- public void startElement(final String namespaceURI, final String lName,
- final String qName, final Attributes attrs) throws SAXException {
-
- if (qName.equals("token") && inCategory) {
- currentTokenPos++;
- final String key = currentId + " " + currentSubId;
- if (needsMarker && startPos.get(key) == currentTokenPos - 1) {
- System.out.print("<marker>\n");
- }
- }
-
- if (attrs.getLength() > 0) {
- System.out.print("<" + qName);
- for (int i = 0; i < attrs.getLength(); i++) {
- final String qName1 = attrs.getQName(i);
- if (qName1.equals("mark_from") || qName1.equals("mark_to")) {
- continue;
- }
- System.out.print(" " + qName1 + "=\"" +
StringTools.escapeXML(attrs.getValue(qName1)) + "\"");
- }
- System.out.print(">");
- } else {
- System.out.print("<" + qName + ">");
- }
- if (qName.equals("category")) {
- inCategory = true;
- } else if (qName.equals("pattern")) {
- final boolean defaultStart = attrs.getValue("mark_from") == null ||
attrs.getValue("mark_from").equals("0");
- final boolean defaultEnd = attrs.getValue("mark_to") == null ||
attrs.getValue("mark_to").equals("0");
- needsMarker = !defaultStart || !defaultEnd;
- } else if (qName.equals("rulegroup")) {
- currentTokenPos = 0;
- currentId = attrs.getValue("id");
- currentSubId = 0;
- inRuleGroup = true;
- } else if (qName.equals("rule")) {
- currentTokenPos = 0;
- if (attrs.getValue("id") != null) {
- currentId = attrs.getValue("id");
- }
- if (inRuleGroup) {
- currentSubId++;
- } else {
- currentSubId = 1;
- }
- }
-
- }
-
- @Override
- public void endElement(final String namespaceURI, final String sName,
- final String qName) throws SAXException {
- System.out.print("</" + qName + ">");
- if (qName.equals("rulegroup")) {
- inRuleGroup = false;
- } else if (qName.equals("category")) {
- inCategory = false;
- } else if (qName.equals("token") && inCategory) {
- final String key = currentId + " " + currentSubId;
- if (needsMarker && endPos.get(key) == currentTokenPos) {
- System.out.print("\n</marker>");
- }
- }
- }
-
- @Override
- public void characters(final char[] buf, final int offset, final int len) {
- final String s = new String(buf, offset, len);
- System.out.print(StringTools.escapeXML(s));
- }
-
- }
-
- static class MyLexicalHandler implements LexicalHandler {
-
- @Override
- public void startDTD(String name, String publicId, String systemId) throws
SAXException {}
- @Override
- public void endDTD() throws SAXException {}
- @Override
- public void startEntity(String name) throws SAXException {}
- @Override
- public void endEntity(String name) throws SAXException {}
- @Override
- public void startCDATA() throws SAXException {}
- @Override
- public void endCDATA() throws SAXException {}
-
- @Override
- public void comment(char[] buf, int offset, int len) throws SAXException {
- final String s = new String(buf, offset, len);
- System.out.print("<!--" + s + "-->");
- }
- }
-
-}
Deleted:
trunk/languagetool/languagetool-standalone/src/main/dev/org/languagetool/dev/MarkerConverter2.java
===================================================================
---
trunk/languagetool/languagetool-standalone/src/main/dev/org/languagetool/dev/MarkerConverter2.java
2013-01-23 23:04:39 UTC (rev 9198)
+++
trunk/languagetool/languagetool-standalone/src/main/dev/org/languagetool/dev/MarkerConverter2.java
2013-01-23 23:21:27 UTC (rev 9199)
@@ -1,187 +0,0 @@
-/* LanguageTool, a natural language style checker
- * Copyright (C) 2012 Daniel Naber (http://www.danielnaber.de)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
- * USA
- */
-package org.languagetool.dev;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.languagetool.JLanguageTool;
-import org.languagetool.Language;
-import org.languagetool.rules.Rule;
-import org.languagetool.rules.patterns.PatternRule;
-import org.languagetool.tools.StringTools;
-
-/**
- * Convert to the new marker format. Note: is buggy at least with "and"
elements.
- * Does not expand entities, unlike MarkerConverter.
- *
- * @deprecated for internal one-time conversion only
- */
-public class MarkerConverter2 {
-
- private final Map<String, Integer> startPos = new HashMap<String, Integer>();
- private final Map<String, Integer> endPos = new HashMap<String, Integer>();
- private boolean needsMarker;
- private boolean inRuleGroup;
- private int currentTokenPos = 0;
- private String currentId = "";
- private int currentSubId = 0;
- private int mark_from = Integer.MAX_VALUE;
- private int mark_to = Integer.MAX_VALUE;
-
- public void convert(String filename) throws IOException, XMLStreamException {
-
- initStartAndEndPositions();
-
- final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
- inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,
false);
- final InputStream in = new FileInputStream(filename);
- final XMLStreamReader streamReader =
inputFactory.createXMLStreamReader(in);
-
- while (streamReader.hasNext()) {
-
- final int eventType = streamReader.next();
- if (eventType == XMLStreamConstants.COMMENT) {
- if (streamReader.hasText()) {
- System.out.print("<!--" + streamReader.getText() + "-->");
- }
- } else if (eventType == XMLStreamConstants.CHARACTERS) {
- if (streamReader.hasText()) {
- System.out.print(StringTools.escapeXML(streamReader.getText()));
- }
- } else {
- if (eventType == XMLStreamConstants.START_ELEMENT) {
- final String localName = streamReader.getLocalName();
-
- initMarkFromAndMarkTo(streamReader);
- if (localName.equals("rulegroup")) {
- currentSubId = 0;
- inRuleGroup = true;
- currentTokenPos = 0;
- } else if (localName.equals("rule")) {
- currentTokenPos = 0;
- if (inRuleGroup) {
- currentSubId++;
- } else {
- currentSubId = 1;
- }
- } else if (localName.equals("pattern")) {
- final boolean defaultStart = mark_from == Integer.MAX_VALUE ||
mark_from == 0;
- final boolean defaultEnd = mark_to == Integer.MAX_VALUE || mark_to
== 0;
- needsMarker = !defaultStart || !defaultEnd;
- } else if (localName.equals("token")) {
- final String key = currentId + " " + currentSubId;
- //System.out.println("###needsMarker: " + needsMarker + ", " +
startPos.get(key) + "==" + (currentTokenPos));
- if (needsMarker && startPos.get(key) == currentTokenPos) {
- System.out.print("<marker>\n");
- }
- currentTokenPos++;
- }
-
- printStartTag(streamReader, localName);
-
- // ----------------------------------------------------
-
- } else if (eventType == XMLStreamConstants.END_ELEMENT) {
- final String localName = streamReader.getLocalName();
- System.out.print("</" + localName + ">");
- if (localName.equals("rulegroup")) {
- inRuleGroup = false;
- } else if (localName.equals("token")) {
- final String key = currentId + " " + currentSubId;
- if (needsMarker && endPos.get(key) == currentTokenPos) {
- System.out.print("\n</marker>");
- }
- }
- } else if (eventType == XMLStreamConstants.ENTITY_REFERENCE) {
- final String localName = streamReader.getLocalName();
- System.out.print("&" + localName + ";");
- }
- }
- }
- }
-
- private void initStartAndEndPositions() throws IOException {
- final JLanguageTool languageTool = new JLanguageTool(Language.GERMAN);
- languageTool.activateDefaultPatternRules();
- final List<Rule> rules = languageTool.getAllRules();
- for (Rule rule : rules) {
- if (rule instanceof PatternRule) {
- final PatternRule pRule = (PatternRule) rule;
- final String key = pRule.getId() + " " + pRule.getSubId();
- startPos.put(key, pRule.getStartPositionCorrection());
- endPos.put(key, pRule.getElements().size() +
pRule.getEndPositionCorrection());
- }
- }
- }
-
- private void printStartTag(XMLStreamReader eventReader, String localName) {
- System.out.print("<" + localName);
- mark_from = Integer.MAX_VALUE;
- mark_to = Integer.MAX_VALUE;
- for (int i = 0; i < eventReader.getAttributeCount(); i++) {
- final String attributeValue = eventReader.getAttributeValue(i);
-
- final String attributeLocalName = eventReader.getAttributeLocalName(i);
- if (!attributeLocalName.equals("mark_from") &&
!attributeLocalName.equals("mark_to")) {
- System.out.print(" " + attributeLocalName + "=\"" +
StringTools.escapeXML(attributeValue) + "\"");
- }
-
- if (attributeLocalName.equals("mark_from")) {
- mark_from = Integer.parseInt(attributeValue);
- } else if (attributeLocalName.equals("mark_to")) {
- mark_to = Integer.parseInt(attributeValue);
- }
- if ((localName.equals("rulegroup") || localName.equals("rule")) &&
attributeLocalName.equals("id")) {
- if (attributeValue != null) {
- currentId = attributeValue;
- }
- }
- }
- System.out.print(">");
- }
-
- private void initMarkFromAndMarkTo(XMLStreamReader eventReader) {
- mark_from = Integer.MAX_VALUE;
- mark_to = Integer.MAX_VALUE;
- for (int i = 0; i < eventReader.getAttributeCount(); i++) {
- final String attributeValue = eventReader.getAttributeValue(i);
- if (eventReader.getAttributeLocalName(i).equals("mark_from")) {
- mark_from = Integer.parseInt(attributeValue);
- } else if (eventReader.getAttributeLocalName(i).equals("mark_to")) {
- mark_to = Integer.parseInt(attributeValue);
- }
- }
- }
-
- public static void main(String args[]) throws XMLStreamException,
IOException {
- final MarkerConverter2 converter = new MarkerConverter2();
- converter.convert("/home/dnaber/languagetool/src/rules/de/grammar.xml");
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
Languagetool-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-commits