{
public void bind(Schema schema, Node coreNode, Node attributeNode) throws XerialException;
- public void bindText(Schema schema, Node coreNode, String attributeValue) throws XerialException;
+ public void bindText(Schema schema, Node coreNode, Node textNode, String textValue) throws XerialException;
}
return null;
}
- public void bindText(Schema schema, Node coreNode, String attributeValue) throws XerialException
+ public void bindText(Schema schema, Node coreNode, Node textNode, String textValue) throws XerialException
{
throw new XerialError(XerialErrorCode.UNSUPPORTED);
}
setter.bind(coreNodeInstance, attributeNodeInstance);
}
- public void bindText(Schema schema, Node coreNode, String textFragment) throws XerialException
+ public void bindText(Schema schema, Node coreNode, Node textNode, String textValue) throws XerialException
{
Object coreNodeInstance = getNodeInstance(coreNode, coreNodeType);
+ Object textNodeInstance = getNodeInstance(textNode, attributeNodeType);
- setter.bind(coreNodeInstance, textFragment);
+ if (textValue != null && !TypeInfo.isBasicType(attributeNodeType))
+ setTextValue(textNodeInstance, attributeNodeType, textValue);
+ else
+ setter.bind(coreNodeInstance, textValue);
}
}
private class QueryBuilder
{
QuerySetBuilder qs = new QuerySetBuilder();
- private Set<Class< ? >> processedClasses = new HashSet<Class< ? >>();
+ private HashMap<String, Set<Class< ? >>> processedClassTable = new HashMap<String, Set<Class< ? >>>();
+
+ //Set<Class< ? >> processedClasses = new HashSet<Class< ? >>();
public QueryBuilder()
{
if (TypeInfo.isBasicType(targetType) || targetType == MapEntry.class)
return;
- if (processedClasses.contains(targetType))
+ Set<Class< ? >> processed = processedClassTable.get(alias);
+ if (processed == null)
+ {
+ processed = new HashSet<Class< ? >>();
+ processedClassTable.put(alias, processed);
+ }
+
+ if (processed.contains(targetType))
return;
+ else
+ processed.add(targetType);
- processedClasses.add(targetType);
+ // if (processedClasses.contains(targetType))
+ // return;
+ //
+ // processedClasses.add(targetType);
ObjectLens lens = ObjectLens.getObjectLens(targetType);
if (_logger.isTraceEnabled())
}
- public Object getNodeInstance(Node node, Class< ? > nodeType) throws XerialException
+ private Object getNodeInstance(Node node, Class< ? > nodeType) throws XerialException
{
Object instance = objectHolder.get(node.nodeID);
if (instance != null)
else
{
instance = TypeInfo.createInstance(nodeType);
- // TODO bind the node value to the instance
+
+ if (node.nodeValue != null)
+ {
+ setTextValue(instance, nodeType, node.nodeValue);
+ }
}
objectHolder.put(node.nodeID, instance);
return instance;
+ }
+
+ private void setTextValue(Object instance, Class< ? > textNodeType, String textValue) throws XerialException
+ {
+ // bind the node value to the instance
+ ObjectLens lens = ObjectLens.getObjectLens(textNodeType);
+ ParameterSetter valueSetter = lens.getValueSetter();
+ if (valueSetter != null)
+ valueSetter.bind(instance, TypeConverter.convertToBasicType(valueSetter.getParameterType(), textValue));
+
+ }
+
+ private Object getTextNodeInstance(String nodeName, String nodeValue, Class< ? > nodeType) throws XerialException
+ {
+ Object instance = null;
+ if (TypeInfo.isBasicType(nodeType))
+ {
+ if (nodeValue == null)
+ return null;
+ else
+ instance = TypeConverter.convertToBasicType(nodeType, nodeValue);
+ }
+ else
+ {
+ instance = TypeInfo.createInstance(nodeType);
+
+ if (nodeValue != null)
+ {
+ // bind the node value to the instance
+ ObjectLens lens = ObjectLens.getObjectLens(nodeType);
+ ParameterSetter valueSetter = lens.getValueSetter();
+ if (valueSetter != null)
+ valueSetter.bind(instance, TypeConverter.convertToBasicType(valueSetter.getParameterType(),
+ nodeValue));
+ }
+
+ }
+
+ return instance;
}
private class RelationExtracter extends AmoebaJoinHandlerBase
}
- public void text(Schema schema, Node coreNode, String nodeName, String text) throws Exception
+ public void text(Schema schema, Node coreNode, Node textNode, String textFragment) throws Exception
{
if (_logger.isTraceEnabled())
- _logger.trace(String.format("text: (%s, %s:%s) in %s", coreNode, nodeName, text, schema));
+ _logger.trace(String.format("text: (%s, %s:%s) in %s", coreNode, textNode, textFragment, schema));
Binder binder = schema2binder.get(schema);
if (binder == null)
try
{
- binder.bindText(schema, coreNode, text);
+ binder.bindText(schema, coreNode, textNode, textFragment);
}
catch (XerialException e)
{
_logger.warn(String.format("failed to bind text: core node=%s, attributeName=%s, text=%s\n%s",
- coreNode, nodeName, text, e));
+ coreNode, textNode, textFragment, e));
}
}
static interface TextOperation
{
- void execute(String nodeName, String textData) throws Exception;
+ void execute(String testNodeName, String textData) throws Exception;
}
class SimpleTextOperation implements TextOperation
this.coreNodeName = pr.coreNodeName;
}
- public void execute(String nodeName, String textData) throws Exception
+ public void execute(String textNodeName, String textData) throws Exception
{
Deque<Node> nodeStack = getNodeStack(coreNodeName);
Node contextNode = nodeStack.getLast();
- handler.text(schema, contextNode, nodeName, textData);
+
+ Deque<Node> textNodeStack = getNodeStack(textNodeName);
+ Node textNode = textNodeStack.getLast();
+
+ handler.text(schema, contextNode, textNode, textData);
}
}
Edge currentEdge = new Edge(prevState.getID(), currentState.getID());
List<TextOperation> textOperation = operatSetOnText.get(currentEdge);
+
+ // generate a text operation set
if (textOperation == null)
{
textOperation = new ArrayList<TextOperation>();
//--------------------------------------
package org.xerial.lens;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.*;
import java.io.IOException;
import java.util.ArrayList;
{
public DASGFF gff;
public Segment segment;
- public List<Feature> feature;
+
+ @Override
+ public String toString()
+ {
+ return ObjectLens.toJSON(this);
+ }
+
}
public static class DASGFF
public String id;
public long start;
public long stop;
+ public List<Feature> feature;
}
public static class Feature
public String score;
public String orientation;
+ public Method method;
public FeatureType type;
- public Segment target;
+ public Group group;
+ public Target target;
+
+ }
+
+ public static class Target
+ {
+ public String id;
+ public long start;
+ public long stop;
}
public static class FeatureType
}
+ public static class Group
+ {
+ public String id;
+ public String type;
+ public String label;
+ public Link link;
+
+ }
+
+ public static class Link
+ {
+ public String href;
+ public String value;
+ }
+
+ public static class Method
+ {
+ public String id;
+ public String value;
+ }
+
/*
* <pre>
<SEGMENT id="13" start="1800000" stop="18100000">
public void dasTest() throws Exception
{
DASFeature das = Lens.loadXML(DASFeature.class, FileResource.find(LensTest.class, "das.xml"));
- assertEquals(1, das.feature.size());
- Feature f = das.feature.get(0);
+ assertEquals(1, das.segment.feature.size());
+ Feature f = das.segment.feature.get(0);
+ _logger.debug(das);
assertEquals("ENSE00001471274", f.id);
- assertEquals(17957458, f.start);
- assertEquals(17957578, f.end);
+ assertEquals(17957458L, f.start);
+ assertEquals(17957578L, f.end);
assertEquals("-", f.score);
assertEquals("-", f.orientation);
- Segment t = f.target;
+ Target t = f.target;
assertEquals("ENST00000342944", t.id);
- assertEquals(1, t.start);
- assertEquals(121, t.stop);
+ assertEquals(1L, t.start);
+ assertEquals(121L, t.stop);
}