Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • deniz.cingoez/robocup-speechrec
  • t.dilger/robocup-speechrec
  • msterz/robocup-speechrec
  • patric.steckstor/robocup-speechrec
  • jennifer.lee/robocup-speechrec
  • jharin/robocup-speechrec
  • f.thiemer/robocup-speechrec
  • augustin.harter/robocup-speechrec
  • jleichert/robocup-speechrec
9 results
Show changes
Showing
with 0 additions and 1465 deletions
package hterhors.editor.xml;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jface.text.Position;
/**
* @author Hendrik
*/
public class XMLElement {
private List elementChildren = new ArrayList();
private List attributeChildren = new ArrayList();
/**
* @uml.property name="name"
*/
private String name;
/**
* @uml.property name="parent"
* @uml.associationEnd
*/
private XMLElement parent;
/**
* @uml.property name="position"
*/
private Position position;
public XMLElement(String name) {
super();
this.name = name;
}
public List getChildrenDTDElements() {
return elementChildren;
}
public XMLElement addChildElement(XMLElement element) {
elementChildren.add(element);
element.setParent(this);
return this;
}
/**
* @param element
* @uml.property name="parent"
*/
public void setParent(XMLElement element) {
this.parent = element;
}
/**
* @return
* @uml.property name="parent"
*/
public XMLElement getParent() {
return parent;
}
public XMLElement addChildAttribute(XMLAttribute attribute) {
attributeChildren.add(attribute);
return this;
}
/**
* @return
* @uml.property name="name"
*/
public String getName() {
return name;
}
public String getAttributeValue(String localName) {
for (Iterator iter = attributeChildren.iterator(); iter.hasNext();) {
XMLAttribute attribute = (XMLAttribute) iter.next();
if (attribute.getName().equals(localName))
return attribute.getValue();
}
return null;
}
public void clear() {
elementChildren.clear();
attributeChildren.clear();
}
/**
* @param position
* @uml.property name="position"
*/
public void setPosition(Position position) {
this.position = position;
}
/**
* @return
* @uml.property name="position"
*/
public Position getPosition() {
return position;
}
}
\ No newline at end of file
package hterhors.editor.xml;
import java.io.StringReader;
import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.ContentHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
/**
* @author Hendrik
*/
public class XMLParser {
private ErrorHandler errorHandler;
private ContentHandler contentHandler;
/**
* @param errorHandler
* @uml.property name="errorHandler"
*/
public void setErrorHandler(ErrorHandler errorHandler) {
this.errorHandler = errorHandler;
}
/**
* @param contentHandler
* @uml.property name="contentHandler"
*/
public void setContentHandler(ContentHandler contentHandler) {
this.contentHandler = contentHandler;
}
public static final String VALIDATION_FEATURE = "http://xml.org/sax/features/validation";
public void doParse(String xmlText) throws RuntimeException {
InputSource inputSource = new InputSource(new StringReader(xmlText));
try {
XMLReader reader = new SAXParser();
reader.setErrorHandler(errorHandler);
reader.setContentHandler(contentHandler);
reader.setFeature(VALIDATION_FEATURE, true);
reader.parse(inputSource);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
package hterhors.editor.xmlconverter;
import hterhors.editor.ISREditor;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
public class ConvertToXMLAction implements IObjectActionDelegate {
private Shell shell;
/**
* Constructor for Action1.
*/
public ConvertToXMLAction() {
super();
}
/**
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
shell = targetPart.getSite().getShell();
}
/**
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
ISREditor textEditor = (ISREditor) PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IDocument doc = textEditor.getInputDocument();
if (doc != null) {
createOutput(shell, extractResource(textEditor), doc.get());
} else {
MessageBox pmb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
pmb.setText("An error has accrued!");
pmb.setMessage("Please try again!");
pmb.open();
}
}
/**
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
}
private QualifiedName path = new QualifiedName("xml", "path");
private IResource extractResource(IEditorPart editor) {
// ISelection sel = HandlerUtil.getActiveMenuSelection(event);
// IStructuredSelection selection = (IStructuredSelection) sel;
IEditorInput input = editor.getEditorInput();
if (!(input instanceof IFileEditorInput))
return null;
return ((IFileEditorInput) input).getFile();
}
private void createOutput(Shell shell, IResource resource, String text) {
String directory;
boolean newDirectory = true;
directory = getPersistentProperty(resource, path);
if (directory != null && directory.length() > 0) {
newDirectory = !(MessageDialog.openQuestion(
shell,
"Question",
"Use the previous output directory?"
+ System.getProperty("line.separator")
+ System.getProperty("line.separator")
+ "Attention homonymous file "
+ System.getProperty("line.separator")
+ "will be override automatically!"));
}
if (newDirectory) {
DirectoryDialog fileDialog = new DirectoryDialog(shell);
IWorkspace workspace = ResourcesPlugin.getWorkspace();
File workspaceDirectory = workspace.getRoot().getLocation()
.toFile();
fileDialog.setFilterPath(workspaceDirectory.getAbsolutePath());
directory = fileDialog.open();
}
if (directory != null && directory.length() > 0) {
setPersistentProperty(resource, path, directory);
write(directory, text, resource.getName());
}
}
private String getPersistentProperty(IResource res, QualifiedName qn) {
try {
return res.getPersistentProperty(qn);
} catch (CoreException e) {
return "";
}
}
private void setPersistentProperty(IResource res, QualifiedName qn,
String value) {
try {
res.setPersistentProperty(qn, value);
} catch (CoreException e) {
e.printStackTrace();
}
}
private void write(String dir, String text, String name) {
IsrFileToXmlFileUsingXOM converter = new IsrFileToXmlFileUsingXOM();
try {
String n;
try {
n = name.split("\\.")[0];
} catch (ArrayIndexOutOfBoundsException e) {
n = name;
}
String xmlFile = dir + "\\" + n + ".xml";
FileWriter output = new FileWriter(xmlFile);
BufferedWriter writer = new BufferedWriter(output);
writer.write(converter.convertText(text));
writer.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
package hterhors.editor.xmlconverter;
//package hterhors.editor.xmlconverter;
//
//import java.io.BufferedWriter;
//import java.io.File;
//import java.io.FileWriter;
//import java.io.IOException;
//
//import org.eclipse.core.commands.AbstractHandler;
//import org.eclipse.core.commands.ExecutionEvent;
//import org.eclipse.core.commands.ExecutionException;
//import org.eclipse.core.resources.IResource;
//import org.eclipse.core.resources.IWorkspace;
//import org.eclipse.core.resources.ResourcesPlugin;
//import org.eclipse.core.runtime.CoreException;
//import org.eclipse.core.runtime.QualifiedName;
//import org.eclipse.jface.dialogs.MessageDialog;
//import org.eclipse.swt.widgets.DirectoryDialog;
//import org.eclipse.swt.widgets.Shell;
//import org.eclipse.ui.IEditorInput;
//import org.eclipse.ui.IEditorPart;
//import org.eclipse.ui.IFileEditorInput;
//import org.eclipse.ui.contexts.IContextActivation;
//import org.eclipse.ui.contexts.IContextService;
//import org.eclipse.ui.handlers.HandlerUtil;
//import org.eclipse.ui.texteditor.ITextEditor;
//
//public class CopyOfConvertToXMLHandler extends AbstractHandler {
// private QualifiedName path = new QualifiedName("xml", "path");
//
// @Override
// public Object execute(ExecutionEvent event) throws ExecutionException {
// ITextEditor textEditor = (ITextEditor) HandlerUtil
// .getActiveEditor(event);
// HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
// IEditorInput input = HandlerUtil.getActiveEditorInput(event);
// Shell shell = HandlerUtil.getActiveShell(event);
// IResource inputResource = extractResource(textEditor);
// createOutput(shell, inputResource, textEditor.getDocumentProvider()
// .getDocument(input).get());
// return null;
// }
//
// private IResource extractResource(IEditorPart editor) {
// IEditorInput input = editor.getEditorInput();
// if (!(input instanceof IFileEditorInput))
// return null;
// return ((IFileEditorInput) input).getFile();
// }
//
// private void createOutput(Shell shell, IResource resource, String text) {
// String directory;
// boolean newDirectory = true;
// directory = getPersistentProperty(resource, path);
//
// if (directory != null && directory.length() > 0) {
// newDirectory = !(MessageDialog.openQuestion(shell, "Question",
// "Use the previous output directory?"));
// }
// if (newDirectory) {
// DirectoryDialog fileDialog = new DirectoryDialog(shell);
// IWorkspace workspace = ResourcesPlugin.getWorkspace();
// File workspaceDirectory = workspace.getRoot().getLocation()
// .toFile();
// fileDialog.setFilterPath(workspaceDirectory.getAbsolutePath());
// directory = fileDialog.open();
//
// }
// if (directory != null && directory.length() > 0) {
// setPersistentProperty(resource, path, directory);
// write(directory, text, resource.getName());
// }
// }
//
// private String getPersistentProperty(IResource res, QualifiedName qn) {
// try {
// return res.getPersistentProperty(qn);
// } catch (CoreException e) {
// return "";
// }
// }
//
// private void setPersistentProperty(IResource res, QualifiedName qn,
// String value) {
// try {
// res.setPersistentProperty(qn, value);
// } catch (CoreException e) {
// e.printStackTrace();
// }
// }
//
// private void write(String dir, String text, String name) {
// IsrFileToXmlFile converter = new IsrFileToXmlFile();
// try {
// String htmlFile = dir + "\\" + name + ".xml";
// FileWriter output = new FileWriter(htmlFile);
// BufferedWriter writer = new BufferedWriter(output);
// writer.write(converter.convertText(text));
// writer.flush();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// }
//}
\ No newline at end of file
package hterhors.editor.xmlconverter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import nu.xom.*;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
public class IsrFileToXmlFileUsingXOM {
private static final String TERMINAL = "([a-zA-Z_\\\"][a-zA-Z_\\-\\\"0-9]*)";
private static final String IGNORE = "%IGNORE";
private static final String C = ":";
private static final String E = ";";
private static final String O = "(\\|)";
private static final String S = "(\\$\\$S)";
private static final String N = "(\\${1,2}[a-zA-Z_\\\"][a-zA-Z_\\-\\\"0-9]*)";
private static final String J_T = "((!\\*)?([a-zA-Z_\\\"][a-zA-Z_\\-\\\"0-9]*))";
private static final String J_T_N = J_T + "|" + N;
private static final String JE_TE_NE = "(" + J_T + ";)|(" + N + ";)";
private List<String> ignores = new ArrayList<String>();
private String xmlString = "<!DOCTYPE world SYSTEM \"IsrGrammarXmlDefinition.dtd\">\n\n<ISR_GRAMMAR>\n";
private boolean addIgnore = true;
private Element ignore_one_of;
private Element root = new Element("grammar");
private boolean forContentOutline = false;
public IsrFileToXmlFileUsingXOM(boolean forContentOutline) {
this.forContentOutline = forContentOutline;
}
public IsrFileToXmlFileUsingXOM() {
}
public String convertText(String isrGrammar) {
if (isrGrammar != null) {
write(new StringTokenizer(isrGrammar));
}
// root.setBaseURI("http://www.w3.org/2001/06/grammar");
// ("version", "1.0");
root.addAttribute(new Attribute("version", "1.0"));
root.addAttribute(new Attribute("root", "S"));
root.addAttribute(new Attribute("mode", "voice"));
// root.addAttribute(new Attribute("xmlns",
// "http://www.w3.org/2001/06/grammar/"));
//
// root.addNamespaceDeclaration("xmlns",
// "http://www.w3.org/2001/06/grammar/");
// root.addNamespaceDeclaration("xmlns:xsi",
// "http://www.w3.org/2001/XMLSchema-instance");
// root.addNamespaceDeclaration("xsi:schemaLocation",
// "http://www.w3.org/2001/06/grammar\n"
// + "http://www.w3.org/TR/speech-grammar/grammar.xsd");
// root.addNamespaceDeclaration("xml:lange", "en-US");
// root.addNamespaceDeclaration("mode", "voice");
// root.addNamespaceDeclaration("root", "Start");
nu.xom.Document doc = new nu.xom.Document(root);
String result = doc.toXML();
return result;
}
public IDocument convertFile(IDocument document) {
return new Document(convertText(document.get()));
}
void write(StringTokenizer stringTokenizer) {
try {
String token;
while (stringTokenizer.hasMoreElements()) {
token = stringTokenizer.nextToken();
if ((token.matches(IGNORE + "="))
|| (token.matches(IGNORE)
&& stringTokenizer.hasMoreElements() && stringTokenizer
.nextToken().matches("="))) {
if (addIgnore) {
addIgnore = false;
Element ignore = new Element("rule");
ignore.addAttribute(new Attribute("id", "Ignore"));
ignore.appendChild(ignore_one_of = new Element("one-of"));
root.appendChild(ignore);
}
do {
String element = stringTokenizer.nextToken();
if (!element.matches(TERMINAL + ";|" + E)) {
if (element.matches(TERMINAL)) {
if (!ignores.contains(element)) {
ignores.add(getAttributeName(element));
}
}
}
if (element.matches(TERMINAL + ";|" + E)) {
if (!getAttributeName(element).isEmpty()
&& !ignores.contains(element)) {
ignores.add(getAttributeName(element));
}
break;
}
} while (stringTokenizer.hasMoreTokens());
} else if (token.matches(S + C)
|| (token.matches(S)
&& stringTokenizer.hasMoreElements() && stringTokenizer
.nextToken().matches(C))) {
Element start = new Element("rule");
start.addAttribute(new Attribute("id", "Start"));
root.appendChild(start);
Element oneOf = new Element("one-of");
Element item;
oneOf.appendChild(item = new Element("item"));
start.appendChild(oneOf);
do {
String element = stringTokenizer.nextToken();
if (!element.matches(E)) {
if (element.matches(N + ";?")) {
Element nt = new Element("ruleref");
nt.addAttribute(new Attribute("uri", "#"
+ getAttributeName(element)));
item.appendChild(nt);
} else if (element.matches(TERMINAL + ";?")) {
item.appendChild(getAttributeName(element)
+ " ");
}
}
if (element.matches(O)) {
oneOf.appendChild(item = new Element("item"));
}
if (element.matches(JE_TE_NE + "|" + E)) {
break;
}
} while (stringTokenizer.hasMoreTokens());
} else if (token.matches(N + C)
|| (token.matches(N)
&& stringTokenizer.hasMoreElements() && stringTokenizer
.nextToken().matches(C))) {
Element start = new Element("rule");
start.addAttribute(new Attribute("id",
getAttributeName(token)));
root.appendChild(start);
Element oneOf = new Element("one-of");
Element item;
oneOf.appendChild(item = new Element("item"));
start.appendChild(oneOf);
do {
String element = stringTokenizer.nextToken();
if (element.matches(O)) {
oneOf.appendChild(item = new Element("item"));
} else if (!element.matches(E)) {
if (element.matches(N + ";?")) {
Element nt = new Element("ruleref");
if (forContentOutline) {
nt.addAttribute(new Attribute("id",
getAttributeName(element)));
} else {
nt.addAttribute(new Attribute("uri", "#"
+ getAttributeName(element)));
}
item.appendChild(nt);
} else if (element.matches(TERMINAL + ";?")) {
if (forContentOutline) {
Element t = new Element("token");
t.addAttribute(new Attribute("id",
getAttributeName(element)));
item.appendChild(t);
} else {
item.appendChild(getAttributeName(element)
+ " ");
}
}
}
if (element.matches(JE_TE_NE + "|" + E)) {
break;
}
} while (stringTokenizer.hasMoreTokens());
}
}
} catch (Exception e) {
e.printStackTrace();
}
Element item;
for (String ignore : ignores) {
ignore_one_of.appendChild(item = new Element("item"));
if (forContentOutline) {
Element t = new Element("token");
t.addAttribute(new Attribute("id", getAttributeName(ignore)));
item.appendChild(t);
} else {
item.appendChild(getAttributeName(ignore));
}
}
}
private String getAttributeName(String token) {
return token.replace("$", "").replace("$$", "").replace(":", "")
.replace("!*", "").replace(";", "");
}
}
package hterhors.editor.zest;
/**
* @author Hendrik
*/
public enum ELayouts {
/**
* @uml.property name="treeLayoutAlgorithm"
* @uml.associationEnd
*/
TreeLayoutAlgorithm, /**
* @uml.property name="horizontalTreeLayoutAlgorithm"
* @uml.associationEnd
*/
HorizontalTreeLayoutAlgorithm, /**
* @uml.property name="radialLayoutAlgorithm"
* @uml.associationEnd
*/
RadialLayoutAlgorithm, /**
* @uml.property name="gridLayoutAlgorithm"
* @uml.associationEnd
*/
GridLayoutAlgorithm, /**
* @uml.property name="verticalLayoutAlgorithm"
* @uml.associationEnd
*/
VerticalLayoutAlgorithm, /**
* @uml.property name="springLayoutAlgorithm"
* @uml.associationEnd
*/
SpringLayoutAlgorithm;
}
package hterhors.editor.zest;
import hterhors.editor.IISRColorConstants;
import hterhors.editor.markers.IsrRuleValidator;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;
import org.eclipse.zest.layouts.LayoutAlgorithm;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.CompositeLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.HorizontalShift;
import org.eclipse.zest.layouts.algorithms.HorizontalTreeLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.VerticalLayoutAlgorithm;
/**
* @author Hendrik
*/
public class IsrGraphBuilder {
private static String isrGrammar;
public static void getGraph(Composite parent) {
if (isrGrammar != null) {
Device device = parent.getDisplay().getSystemColor(SWT.COLOR_GREEN)
.getDevice();
List<String> graphNodes = new ArrayList<String>();
final Graph graph = new Graph(parent, SWT.NONE);
StringTokenizer ruleToken = new StringTokenizer(isrGrammar, ";",
false);
boolean isIgnoreRule;
boolean isEmptyRule;
while (ruleToken.hasMoreTokens()) {
isIgnoreRule = false;
isEmptyRule = false;
GraphNode currentStartNode = null;
GraphNode lastNode = null;
String ruleText = ruleToken.nextToken();
if (!ruleText.trim().isEmpty()) {
lastNode = new GraphNode(graph, SWT.NONE, ";");
lastNode.setBackgroundColor(new Color(device, 230, 230, 230));
} else {
isEmptyRule = true;
}
StringTokenizer orRulePartToken = new StringTokenizer(ruleText,
"|", false);
while (orRulePartToken.hasMoreTokens()) {
StringTokenizer wordToken = new StringTokenizer(
orRulePartToken.nextToken());
int tokenCount = wordToken.countTokens();
graphNodes.clear();
String tmp;
while (wordToken.hasMoreTokens()) {
if ((tmp = wordToken.nextToken()).matches(":|=")) {
} else {
if (tmp.charAt(0) == '%') {
tmp = tmp.replace("=", "");
graphNodes.add(tmp + "=");
isIgnoreRule = true;
} else if (tmp.charAt(0) == '$') {
if (tmp.contains(":")) {
tmp = tmp.replace(":", "");
graphNodes.add(tmp + ":");
} else {
graphNodes.add(tmp);
}
} else {
graphNodes.add(tmp);
}
}
}
GraphNode gn1 = null;
GraphNode gn2 = null;
for (int i = 0; i < graphNodes.size(); i++) {
if (isIgnoreRule) {
if (gn1 == null) {
gn1 = new GraphNode(graph, SWT.NONE,
graphNodes.get(i));
currentStartNode = gn1;
currentStartNode
.setBackgroundColor(new Color(device,
IISRColorConstants.IGNORE_GRAPH));
} else {
try {
gn2 = new GraphNode(graph, SWT.NONE,
graphNodes.get(i + 1));
gn2.setBackgroundColor(new Color(device,
255, 200, 200));
GraphConnection gc = new GraphConnection(
graph,
ZestStyles.CONNECTIONS_DIRECTED,
currentStartNode, gn2);
gc.setLineColor(new Color(device,
IISRColorConstants.OR));
new GraphConnection(graph,
ZestStyles.CONNECTIONS_DIRECTED,
gn2, lastNode);
} catch (IndexOutOfBoundsException e) {
}
}
} else {
if (gn2 == null) {
gn1 = new GraphNode(graph, SWT.NONE,
graphNodes.get(i));
if (graphNodes.get(i).matches(
IsrRuleValidator.TERMINAL + ";?")) {
gn1.setBackgroundColor(new Color(device,
255, 255, 255));
} else if (graphNodes.get(i).matches(
"(!\\*)" + IsrRuleValidator.TERMINAL
+ ";?")) {
gn1.setBackgroundColor(new Color(device,
255, 255, 255));
} else {
if (graphNodes.get(i).matches(
IsrRuleValidator.PRE_START_SYMBOL
+ ":?")) {
gn1.setBackgroundColor(new Color(
device,
IISRColorConstants.START_GRAPH));
} else if (graphNodes.get(i).matches(
IsrRuleValidator.IGNORE + "=?")) {
gn1.setBackgroundColor(new Color(
device,
IISRColorConstants.IGNORE_GRAPH));
} else {
gn1.setBackgroundColor(new Color(
device,
IISRColorConstants.DEC_NON_TERMINAL_GRAPH));
}
}
if (currentStartNode == null) {
currentStartNode = gn1;
} else {
GraphConnection gc = new GraphConnection(
graph,
ZestStyles.CONNECTIONS_DIRECTED,
currentStartNode, gn1);
gc.setLineColor(new Color(device,
IISRColorConstants.OR_GRAPH));
}
} else {
gn1 = gn2;
setColor(device, graphNodes.get(i), gn1);
}
try {
gn2 = new GraphNode(graph, SWT.NONE,
graphNodes.get(i + 1));
setColor(device, graphNodes.get(i), gn2);
} catch (IndexOutOfBoundsException e) {
gn2 = lastNode;
}
if (gn2 != null) {
GraphConnection gc = new GraphConnection(graph,
ZestStyles.CONNECTIONS_DIRECTED, gn1,
gn2);
if (gn1 == currentStartNode
&& orRulePartToken.countTokens() == 1) {
gc.setLineColor(new Color(device,
IISRColorConstants.OR_GRAPH));
}
}
}
}
if (tokenCount == 0 && !isEmptyRule) {
GraphConnection gc = new GraphConnection(graph,
ZestStyles.CONNECTIONS_DIRECTED,
currentStartNode, lastNode);
gc.setLineColor(new Color(device,
IISRColorConstants.OR_GRAPH));
}
}
}
switch (layout) {
case TreeLayoutAlgorithm:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new TreeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
break;
case HorizontalTreeLayoutAlgorithm:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new HorizontalTreeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
break;
case RadialLayoutAlgorithm:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new RadialLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
break;
case GridLayoutAlgorithm:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new GridLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
break;
case VerticalLayoutAlgorithm:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new VerticalLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
break;
case SpringLayoutAlgorithm:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new SpringLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
break;
default:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new HorizontalTreeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
}
}
}
private static void setColor(Device device, String nodeText, GraphNode node) {
if (nodeText.matches(IsrRuleValidator.NON_TERMINAL + ";?")) {
node.setBackgroundColor(new Color(device,
IISRColorConstants.NON_TERMINAL_GRAPH));
} else if (nodeText.matches(IsrRuleValidator.IGNORE + "=?")) {
node.setBackgroundColor(new Color(device,
IISRColorConstants.IGNORE_GRAPH));
} else if (nodeText
.matches("(!\\*)" + IsrRuleValidator.TERMINAL + ";?")) {
node.setBackgroundColor(new Color(device,
IISRColorConstants.IGNORE_GRAPH));
} else {
node.setBackgroundColor(new Color(device, 255, 255, 255));
}
}
/**
* @uml.property name="layout"
* @uml.associationEnd
*/
private static ELayouts layout = ELayouts.HorizontalTreeLayoutAlgorithm;
public static void setInput(String isrGrammar, ELayouts l) {
IsrGraphBuilder.isrGrammar = remNumbers(isrGrammar);
if (l != null)
layout = l;
}
private static String remNumbers(String isrGrammar2) {
return isrGrammar2.replaceAll(IsrRuleValidator.NUMBER, "");
}
}
package hterhors.editor.zest;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
public class IsrGraphView extends ViewPart {
public static final String ID = "hterhors.editor.zest.IsrGraphView";
Composite parent;
public void createPartControl(Composite composite) {
this.parent = composite;
// SentenceGraphBuilder.getGraph(composite);
IsrGraphBuilder.getGraph(composite);
}
/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
}
}
\ No newline at end of file
package hterhors.editor.zest;
import hterhors.editor.IISRColorConstants;
import hterhors.editor.sentenceparser.grammar.TreeData;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;
import org.eclipse.zest.layouts.LayoutAlgorithm;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.CompositeLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.HorizontalShift;
import org.eclipse.zest.layouts.algorithms.HorizontalTreeLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.VerticalLayoutAlgorithm;
/**
* Buggy wegen recursion
* @author Hendrik
*/
public class SentenceGraphBuilder {
private static List<ArrayList<TreeData>> treeDatas = new ArrayList<ArrayList<TreeData>>();
public static void getGraph(Composite parent) {
if (treeDatas != null) {
for (ArrayList<TreeData> treeData : treeDatas) {
gns.clear();
if (treeData != null) {
Device device = parent.getDisplay()
.getSystemColor(SWT.COLOR_GREEN).getDevice();
final Graph graph = new Graph(parent, SWT.NONE);
GraphNode parentNode = null;
Iterator<TreeData> it = treeData.iterator();
while (it.hasNext()) {
if (it.next().parent == null) {
parentNode = new GraphNode(graph, SWT.NONE, "$$S");
break;
}
}
parentNode.setBackgroundColor(new Color(device,
IISRColorConstants.START_GRAPH));
it = treeData.iterator();
while (it.hasNext()) {
TreeData nd = it.next();
TreeData pd;
if (nd.data.isLeaf()) {
GraphNode ndNode = new GraphNode(graph, SWT.NONE,
nd.data.getData().toString());
add(ndNode);
GraphNode pdNode = null;
while (true) {
pd = nd.parent;
if (pd != null) {
if (pd.parent != null) {
pdNode = getndNod(graph, pd.data
.getData().toString());
add(pdNode);
if (!pd.data.isLeaf()) {
pdNode.setBackgroundColor(new Color(
device,
IISRColorConstants.NON_TERMINAL_GRAPH));
}
new GraphConnection(
graph,
ZestStyles.CONNECTIONS_DIRECTED,
pdNode, ndNode);
} else {
new GraphConnection(
graph,
ZestStyles.CONNECTIONS_DIRECTED,
parentNode, ndNode);
}
nd = pd;
ndNode = pdNode;
} else {
break;
}
}
}
}
switch (layout) {
case TreeLayoutAlgorithm:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new TreeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
break;
case HorizontalTreeLayoutAlgorithm:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new HorizontalTreeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
break;
case RadialLayoutAlgorithm:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new RadialLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
break;
case GridLayoutAlgorithm:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new GridLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
break;
case VerticalLayoutAlgorithm:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new VerticalLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
break;
case SpringLayoutAlgorithm:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new SpringLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
break;
default:
graph.setLayoutAlgorithm(
new CompositeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING,
new LayoutAlgorithm[] {
new HorizontalTreeLayoutAlgorithm(
LayoutStyles.NO_LAYOUT_NODE_RESIZING),
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) }),
true);
}
}
}
}
}
private static GraphNode getndNod(Graph graph, String ndNodeText) {
int index;
if ((index = contains(ndNodeText)) == -1)
return new GraphNode(graph, SWT.NONE, ndNodeText);
return gns.get(index);
}
static List<GraphNode> gns = new ArrayList<GraphNode>();
private static void add(GraphNode ndNode) {
if (contains(ndNode) == null) {
gns.add(ndNode);
}
}
private static GraphNode contains(GraphNode ndNode) {
if (ndNode.getText().equals(ndNode.getText().toUpperCase())) {
for (int i = 0; i < gns.size(); i++) {
if (gns.get(i).getText().equals(ndNode.getText())) {
return ndNode;
}
}
}
return null;
}
private static int contains(String ndNodeText) {
if (ndNodeText.equals(ndNodeText.toUpperCase())) {
for (int i = 0; i < gns.size(); i++) {
if (gns.get(i).getText().equals(ndNodeText)) {
return i;
}
}
}
return -1;
}
/**
* @uml.property name="layout"
* @uml.associationEnd
*/
private static ELayouts layout = ELayouts.HorizontalTreeLayoutAlgorithm;
public static void addInput(ArrayList<TreeData> tree_data, ELayouts l) {
SentenceGraphBuilder.treeDatas.add(tree_data);
if (l != null)
layout = l;
}
public static void clearInput() {
SentenceGraphBuilder.treeDatas.clear();
}
}
package hterhors.editor.zest;
import hterhors.editor.markers.IsrRuleValidator;
import java.util.StringTokenizer;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.ITextEditor;
/**
* @author Hendrik
*/
public class SetGraphSettingsHandler extends AbstractHandler {
/**
* @uml.property name="layout"
* @uml.associationEnd
*/
public static ELayouts layout;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
generateInput(event);
IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event)
.getActivePage();
IViewPart findView = (IViewPart) page
.findView("hterhors.editor.zest.IsrGraphView");
page.hideView(findView);
try {
page.showView("hterhors.editor.zest.IsrGraphView");
} catch (PartInitException e) {
}
return null;
}
/**
* @param l
* @uml.property name="layout"
*/
public void setLayout(ELayouts l) {
layout = l;
}
private void generateInput(ExecutionEvent event) {
ITextEditor textEditor = (ITextEditor) HandlerUtil
.getActiveEditor(event);
IEditorInput input = HandlerUtil.getActiveEditorInput(event);
ITextSelection selection = (ITextSelection) textEditor.getEditorSite()
.getSelectionProvider().getSelection();
if (selection.getText().trim().isEmpty()) {
IsrGraphBuilder.setInput(textEditor.getDocumentProvider()
.getDocument(input).get(), layout);
} else {
if (testSelectionIsARule(selection.getText().trim())) {
IsrGraphBuilder.setInput(selection.getText(), layout);
} else {
Shell shell = (Shell) HandlerUtil.getActiveShell(event);
MessageBox pmb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
pmb.setText("Unvalid selection");
pmb.setMessage("The selection you did, was not a valid construct and cannot be displayed!");
pmb.open();
}
}
}
private boolean testSelectionIsARule(String selection) {
StringTokenizer tokenizer = new StringTokenizer(selection);
String preToken = tokenizer.nextToken();
if (selection.trim().endsWith(";")) {
if ((preToken.matches(IsrRuleValidator.IGNORE + "="))
|| (preToken.matches(IsrRuleValidator.IGNORE)
&& tokenizer.hasMoreElements() && tokenizer
.nextToken().matches("="))) {
return true;
} else if (((preToken.matches(IsrRuleValidator.NUMBER) && tokenizer
.hasMoreElements()) && (((preToken = tokenizer.nextToken())
.matches(IsrRuleValidator.NON_TERMINAL + ":")) || (preToken
.matches(IsrRuleValidator.NON_TERMINAL)
&& tokenizer.hasMoreElements() && tokenizer.nextToken()
.matches(":"))))
|| ((preToken.matches(IsrRuleValidator.NON_TERMINAL + ":")) || (preToken
.matches(IsrRuleValidator.NON_TERMINAL)
&& tokenizer.hasMoreElements() && tokenizer
.nextToken().matches(":")))) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}
package hterhors.editor.zest;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
public class UpdateGraphHandler extends SetGraphSettingsHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
setLayout(null);
return super.execute(event);
}
}
\ No newline at end of file
package hterhors.editor.zest.layouthandler;
import hterhors.editor.zest.ELayouts;
import hterhors.editor.zest.SetGraphSettingsHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
public class GridLayoutGraphHandler extends SetGraphSettingsHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
setLayout(ELayouts.GridLayoutAlgorithm);
return super.execute(event);
}
}
\ No newline at end of file
package hterhors.editor.zest.layouthandler;
import hterhors.editor.zest.ELayouts;
import hterhors.editor.zest.SetGraphSettingsHandler;
import hterhors.editor.zest.UpdateGraphHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
public class HorizontalTreeLayoutGraphHandler extends SetGraphSettingsHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
UpdateGraphHandler.layout = ELayouts.HorizontalTreeLayoutAlgorithm;
return super.execute(event);
}
}
\ No newline at end of file
package hterhors.editor.zest.layouthandler;
import hterhors.editor.zest.ELayouts;
import hterhors.editor.zest.SetGraphSettingsHandler;
import hterhors.editor.zest.UpdateGraphHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
public class RadialLayoutGraphHandler extends SetGraphSettingsHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
UpdateGraphHandler.layout = ELayouts.RadialLayoutAlgorithm;
return super.execute(event);
}
}
\ No newline at end of file
package hterhors.editor.zest.layouthandler;
import hterhors.editor.zest.ELayouts;
import hterhors.editor.zest.SetGraphSettingsHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
public class SpringLayoutGraphHandler extends SetGraphSettingsHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
setLayout(ELayouts.SpringLayoutAlgorithm);
return super.execute(event);
}
}
\ No newline at end of file
package hterhors.editor.zest.layouthandler;
import hterhors.editor.zest.ELayouts;
import hterhors.editor.zest.SetGraphSettingsHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
public class TreeLayoutGraphHandler extends SetGraphSettingsHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
setLayout(ELayouts.TreeLayoutAlgorithm);
return super.execute(event);
}
}
package hterhors.editor.zest.layouthandler;
import hterhors.editor.zest.ELayouts;
import hterhors.editor.zest.SetGraphSettingsHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
public class VerticalLayoutGraphHandler extends SetGraphSettingsHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
setLayout(ELayouts.VerticalLayoutAlgorithm);
return super.execute(event);
}
}
\ No newline at end of file
Grm_def 4grm "Sven Wachsmuth & Gernot A. Fink" - "ESMERALDA-Manual"
This is an example grammar describing a time constituent:
$TIME : $DAY $TIME_CIRCA $TIME_PRECISE ;
$DAY : today ;
$TIME_CIRCA : in the morning | ;
$TIME_PRECISE : at $TIME_HOUR oclock | at $TIME_HOUR point $TIME_MIN | ;
$TIME_HOUR : one | two | three ;
$TIME_MIN : zero | fifteen | thirty ;
$$S : $TIME ;
Some word sequences defined by the grammar are:
today in the morning
today in the morning at three oclock
today at one point thirty
today
This info describes the implemented functionalities!
Implemented by Hendrik ter Horst (hterhors@techfak.uni-bielefeld.de)
*Syntax-highliting
*Live Errorhandler
*Automatic check of the wordproblem and create syntax trees (Strg+shift+P)
*Autoformatting (Strg+Shift+F)
*Hover-Info(hold the mouse pointer over a faulty rule-element or over a nonterminal)
*Hyperlinks(Strg+Klick) on a nonterminal > jumps to his declaration
*visualization of the rules. Select a rule and press shortcut(Strg+Shift+V) > . (beta...)
*Content Assitent (Strg+Leertaste) > invokes a wizard to quickly create rule-elements
*Outline-Page(beta) shows a rough outline of the grammar according to the W3C standard for speech recognition grammars
*Menu item (ISR) for more help and examples, and advanced virtualization features(beta).
\ No newline at end of file
Grm_def 4grm "Sven Wachsmuth & Gernot A. Fink" - "ESMERALDA-Manual"
The grammar library provides methods for using a context free grammar
in conjunction with an incremental partial parser as a language model
for a statistical recognizer.
The grammar library provides functions which generate a LR(1) parse-table
from a grammar definition. The terminal symbols used in the
grammar must be defined in a separated lexicon.
For more informations take a look at Esmeralda-man-page!
"/vol/esmeralda/man/man4/grm_def.4"
Call "-M /vol/esmeralda/man grm_def"
\ No newline at end of file