Skip to content

Commit

Permalink
added test data; implemented loading data (without probabilities)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoechp committed May 17, 2017
1 parent e3c53f8 commit 88adbdc
Show file tree
Hide file tree
Showing 44 changed files with 303,939 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package org.fujaba.graphengine.stateelimination;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Iterator;

import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;

import org.fujaba.graphengine.IdManager;
import org.fujaba.graphengine.graph.Graph;
import org.fujaba.graphengine.graph.Node;

/**
*
* thanks to google:
*
* http://www.tutorialspoint.com/java_xml/java_stax_parse_document.htm
*
* @author hoechp
*
*/
public class TTCStateCaseGraphLoader {
public static Graph load(String path) {
Graph graph = new Graph();
try {
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLEventReader eventReader =
factory.createXMLEventReader(new FileReader(path));
IdManager idManager = new IdManager();
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
switch (event.getEventType()) {
case XMLStreamConstants.START_ELEMENT:
StartElement startElement = event.asStartElement();
String qName = startElement.getName().getLocalPart();
if (qName.equalsIgnoreCase("states")) {
Node node = new Node();
Iterator<Attribute> attributes = startElement.getAttributes();
while (attributes.hasNext()) {
Attribute currentAttribute = attributes.next();
String attributeName = currentAttribute.getName().toString();
String attributeValue = currentAttribute.getValue();
if (attributeName.equalsIgnoreCase("isInitial")) {
// telling the idManager that this node has id == 0:
/**
* in the paper i though it said there could be multiple initial states.
* but there's always just one and it has no id...
* though still it is references as id == 0. so I'll just assume it to be that way.
*/
idManager.tellId(new Long(0), node);

node.setAttribute("initial", true); // set attribute for initial state
} else if (attributeName.equalsIgnoreCase("id")) {
// telling the idManager that this node has that id:
idManager.tellId(Long.parseLong(attributeValue), node);
} else if (attributeName.equalsIgnoreCase("outgoing")) {
// shouldn't matter right here
} else if (attributeName.equalsIgnoreCase("ingoing")) {
// shouldn't matter right here
} else if (attributeName.equalsIgnoreCase("isFinal")) {
node.setAttribute("final", true); // set attribute for final state
}
}
graph.addNode(node);
} else if (qName.equalsIgnoreCase("transitions")) {
Iterator<Attribute> attributes = startElement.getAttributes();
String label = "";
long sourceId = -1;
long targetId = -1;
double probability = -1;
while (attributes.hasNext()) {
Attribute currentAttribute = attributes.next();
String attributeName = currentAttribute.getName().toString();
String attributeValue = currentAttribute.getValue();
if (attributeName.equalsIgnoreCase("label")) {
// so we have an edge label
label = attributeValue;
} else if (attributeName.equalsIgnoreCase("source")) {
// the source id
sourceId = Long.parseLong(attributeValue.substring(attributeValue.lastIndexOf('.') + 1));
} else if (attributeName.equalsIgnoreCase("target")) {
// the target id
targetId = Long.parseLong(attributeValue.substring(attributeValue.lastIndexOf('.') + 1));
} else if (attributeName.equalsIgnoreCase("probability")) {
// the probability (not used for now)
probability = Double.parseDouble(attributeValue); // TODO: also use the probability
}
}
((Node)idManager.getObject(sourceId)).addEdge(label, ((Node)idManager.getObject(targetId)));
}
break;
case XMLStreamConstants.CHARACTERS:
// shouldn't even happen
break;
case XMLStreamConstants.END_ELEMENT:
// shouldn't really matter
break;
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (XMLStreamException e) {
e.printStackTrace();
}
return graph;
}
}
15 changes: 15 additions & 0 deletions src/main/resources/ExperimentalData/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: ExperimentalData;singleton:=true
Bundle-Version: 0.1.0.qualifier
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: transitiongraph,
transitiongraph.impl,
transitiongraph.util
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.ecore;visibility:=reexport
Bundle-ActivationPolicy: lazy
10 changes: 10 additions & 0 deletions src/main/resources/ExperimentalData/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#

bin.includes = .,\
model/,\
META-INF/,\
plugin.xml,\
plugin.properties
jars.compile.order = .
source.. = src/
output.. = bin/
27 changes: 27 additions & 0 deletions src/main/resources/ExperimentalData/model/TransitionGraph.ecore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="transitiongraph" nsURI="http://transitiongraph/1.0" nsPrefix="transitiongraph">
<eClassifiers xsi:type="ecore:EClass" name="TransitionGraph">
<eStructuralFeatures xsi:type="ecore:EReference" name="states" upperBound="-1"
eType="#//State" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="transitions" upperBound="-1"
eType="#//Transition" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="State">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="outgoing" upperBound="-1"
eType="#//Transition" eOpposite="#//Transition/source"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="incoming" upperBound="-1"
eType="#//Transition" eOpposite="#//Transition/target"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="isFinal" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="isInitial" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Transition">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="label" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="source" lowerBound="1"
eType="#//State" eOpposite="#//State/outgoing"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="target" lowerBound="1"
eType="#//State" eOpposite="#//State/incoming"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="probability" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDouble"/>
</eClassifiers>
</ecore:EPackage>
Loading

0 comments on commit 88adbdc

Please sign in to comment.