text
stringlengths
30
1.67M
<s> package annis . gui . media ; public interface MediaControllerHolder { public MediaController getMediaController ( ) ; public void setMediaController ( MediaController mediaController ) ; } </s>
<s> package annis . gui ; import annis . visualizers . LoadableVisualizer ; public interface VisualizationToggle { public void toggleVisualizer ( boolean visible , LoadableVisualizer . Callback callback ) ; public boolean visualizerIsVisible ( ) ; } </s>
<s> package annis . provider ; import annis . exceptions . AnnisQLSyntaxException ; import javax . ws . rs . core . Response ; import javax . ws . rs . ext . ExceptionMapper ; import javax . ws . rs . ext . Provider ; @ Provider public class AnnisQLSyntaxMapper implements ExceptionMapper < AnnisQLSyntaxException > { @ Override public Response toResponse ( AnnisQLSyntaxException exception ) { return Response . status ( Response . Status . BAD_REQUEST ) . entity ( "<STR_LIT>" + exception . getMessage ( ) ) . type ( "<STR_LIT:text/plain>" ) . build ( ) ; } } </s>
<s> package annis . provider ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . SaltCommonFactory ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . SaltCommonPackage ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . SaltProject ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SCorpusGraph ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SDocument ; import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; import java . lang . annotation . Annotation ; import java . lang . reflect . Type ; import java . util . Map ; import java . util . logging . Level ; import java . util . logging . Logger ; import javax . ws . rs . WebApplicationException ; import javax . ws . rs . core . MediaType ; import javax . ws . rs . core . MultivaluedMap ; import javax . ws . rs . ext . MessageBodyReader ; import javax . ws . rs . ext . MessageBodyWriter ; import javax . ws . rs . ext . Provider ; import org . eclipse . emf . ecore . EObject ; import org . eclipse . emf . ecore . resource . Resource ; import org . eclipse . emf . ecore . resource . ResourceSet ; import org . eclipse . emf . ecore . resource . impl . ResourceSetImpl ; import org . eclipse . emf . ecore . xmi . XMLParserPool ; import org . eclipse . emf . ecore . xmi . XMLResource ; import org . eclipse . emf . ecore . xmi . impl . XMIResourceImpl ; import org . eclipse . emf . ecore . xmi . impl . XMLParserPoolImpl ; import org . slf4j . LoggerFactory ; @ Provider public class SaltProjectProvider implements MessageBodyWriter < SaltProject > , MessageBodyReader < SaltProject > { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( SaltProjectProvider . class ) ; private static ThreadLocal < XMLParserPool > xmlParserPool = new ThreadLocal < XMLParserPool > ( ) ; @ Override public boolean isWriteable ( Class < ? > type , Type genericType , Annotation [ ] annotations , MediaType mediaType ) { return ( MediaType . APPLICATION_XML_TYPE . isCompatible ( mediaType ) || MediaType . TEXT_XML_TYPE . isCompatible ( mediaType ) ) && SaltProject . class . isAssignableFrom ( type ) ; } @ Override public long getSize ( SaltProject t , Class < ? > type , Type genericType , Annotation [ ] annotations , MediaType mediaType ) { return - <NUM_LIT:1> ; } @ Override public void writeTo ( SaltProject project , Class < ? > type , Type genericType , Annotation [ ] annotations , MediaType mediaType , MultivaluedMap < String , Object > httpHeaders , OutputStream entityStream ) throws IOException , WebApplicationException { Resource resource = new XMIResourceImpl ( ) ; resource . getContents ( ) . add ( project ) ; for ( SCorpusGraph corpusGraph : project . getSCorpusGraphs ( ) ) { for ( SDocument doc : corpusGraph . getSDocuments ( ) ) { if ( doc . getSDocumentGraph ( ) != null ) { resource . getContents ( ) . add ( doc . getSDocumentGraph ( ) ) ; } } } try { resource . save ( entityStream , null ) ; } catch ( Exception ex ) { log . error ( "<STR_LIT>" , ex ) ; } } @ Override public boolean isReadable ( Class < ? > type , Type genericType , Annotation [ ] annotations , MediaType mediaType ) { return ( MediaType . APPLICATION_XML_TYPE . isCompatible ( mediaType ) || MediaType . TEXT_XML_TYPE . isCompatible ( mediaType ) ) && SaltProject . class . isAssignableFrom ( type ) ; } @ Override public SaltProject readFrom ( Class < SaltProject > type , Type genericType , Annotation [ ] annotations , MediaType mediaType , MultivaluedMap < String , String > httpHeaders , InputStream entityStream ) throws IOException , WebApplicationException { ResourceSet resourceSet = new ResourceSetImpl ( ) ; resourceSet . getPackageRegistry ( ) . put ( SaltCommonPackage . eINSTANCE . getNsURI ( ) , SaltCommonPackage . eINSTANCE ) ; XMIResourceImpl resource = new XMIResourceImpl ( ) ; resourceSet . getResources ( ) . add ( resource ) ; if ( xmlParserPool . get ( ) == null ) { xmlParserPool . set ( new XMLParserPoolImpl ( ) ) ; } Map < Object , Object > options = resource . getDefaultLoadOptions ( ) ; options . put ( XMLResource . OPTION_USE_PARSER_POOL , xmlParserPool . get ( ) ) ; options . put ( XMLResource . OPTION_DEFER_IDREF_RESOLUTION , Boolean . TRUE ) ; resource . load ( entityStream , null ) ; SaltProject project = SaltCommonFactory . eINSTANCE . createSaltProject ( ) ; for ( EObject o : resource . getContents ( ) ) { if ( o instanceof SaltProject ) { project = ( SaltProject ) o ; break ; } } return project ; } } </s>
<s> package annis . provider ; import annis . exceptions . AnnisQLSemanticsException ; import javax . ws . rs . core . Response ; import javax . ws . rs . ext . ExceptionMapper ; import javax . ws . rs . ext . Provider ; @ Provider public class AnnisQLSemanticsMapper implements ExceptionMapper < AnnisQLSemanticsException > { @ Override public Response toResponse ( AnnisQLSemanticsException exception ) { return Response . status ( Response . Status . BAD_REQUEST ) . entity ( "<STR_LIT>" + exception . getMessage ( ) ) . type ( "<STR_LIT:text/plain>" ) . build ( ) ; } } </s>
<s> package annis . provider ; import annis . exceptions . AnnisCorpusAccessException ; import javax . ws . rs . core . Response ; import javax . ws . rs . ext . ExceptionMapper ; import javax . ws . rs . ext . Provider ; @ Provider public class AnnisCorpusAccessMapper implements ExceptionMapper < AnnisCorpusAccessException > { @ Override public Response toResponse ( AnnisCorpusAccessException exception ) { return Response . status ( Response . Status . BAD_REQUEST ) . entity ( "<STR_LIT>" + exception . getMessage ( ) ) . type ( "<STR_LIT:text/plain>" ) . build ( ) ; } } </s>
<s> package annis . service . objects ; import java . io . Serializable ; import java . util . Collection ; import java . util . LinkedHashSet ; import java . util . List ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlElementWrapper ; import org . apache . commons . lang3 . builder . EqualsBuilder ; import org . apache . commons . lang3 . builder . HashCodeBuilder ; import javax . xml . bind . annotation . XmlRootElement ; @ XmlRootElement public class AnnisAttribute implements Serializable { public enum Type { node , edge , segmentation , unknown } ; public enum SubType { n , d , p , c , unknown } ; private String name = "<STR_LIT>" ; private String edgeName = null ; private LinkedHashSet < String > distinctValues = new LinkedHashSet < String > ( ) ; private Type type ; private SubType subtype ; @ XmlElementWrapper ( name = "<STR_LIT>" ) @ XmlElement ( name = "<STR_LIT:value>" ) public Collection < String > getValueSet ( ) { return distinctValues ; } public void setValueSet ( Collection < String > values ) { this . distinctValues = new LinkedHashSet < String > ( values ) ; } public String getName ( ) { return this . name ; } public void setName ( String name ) { this . name = name ; } public String getEdgeName ( ) { return edgeName ; } public void setEdgeName ( String edgeName ) { this . edgeName = edgeName ; } public Type getType ( ) { return type ; } public void setType ( Type type ) { this . type = type ; } public SubType getSubtype ( ) { return subtype ; } public void setSubtype ( SubType subtype ) { this . subtype = subtype ; } public void addValue ( String value ) { this . distinctValues . add ( value ) ; } public boolean hasValue ( String value ) { return this . distinctValues . contains ( value ) ; } @ Override public String toString ( ) { return name + "<STR_LIT:U+0020>" + distinctValues ; } @ Override public boolean equals ( Object obj ) { if ( obj == null || ! ( obj instanceof AnnisAttribute ) ) { return false ; } AnnisAttribute other = ( AnnisAttribute ) obj ; return new EqualsBuilder ( ) . append ( this . name , other . name ) . append ( this . distinctValues , other . distinctValues ) . isEquals ( ) ; } @ Override public int hashCode ( ) { return new HashCodeBuilder ( ) . append ( name ) . append ( distinctValues ) . toHashCode ( ) ; } } </s>
<s> package annis . service . objects ; import java . io . Serializable ; import java . util . Arrays ; import javax . xml . bind . annotation . XmlRootElement ; @ XmlRootElement public class AnnisBinary extends AnnisBinaryMetaData implements Serializable { private byte [ ] bytes ; public byte [ ] getBytes ( ) { return Arrays . copyOf ( bytes , bytes . length ) ; } public void setBytes ( byte [ ] bytes ) { if ( bytes == null ) { throw new RuntimeException ( "<STR_LIT>" ) ; } this . bytes = Arrays . copyOf ( bytes , bytes . length ) ; } } </s>
<s> package annis . service . objects ; import java . io . Serializable ; import javax . xml . bind . annotation . XmlRootElement ; @ XmlRootElement public class AnnisBinaryMetaData implements Serializable { private String corpusName ; private String mimeType ; private String fileName ; private int length ; public String getCorpusName ( ) { return corpusName ; } public void setCorpusName ( String corpusName ) { this . corpusName = corpusName ; } public String getMimeType ( ) { return mimeType ; } public void setMimeType ( String mimeType ) { this . mimeType = mimeType ; } public String getFileName ( ) { return fileName ; } public void setFileName ( String fileName ) { this . fileName = fileName ; } public int getLength ( ) { return length ; } public void setLength ( int length ) { this . length = length ; } } </s>
<s> package annis . service . objects ; import java . io . Serializable ; import java . util . Map ; import javax . xml . bind . annotation . XmlElementWrapper ; import javax . xml . bind . annotation . XmlRootElement ; @ XmlRootElement public class CorpusConfig implements Serializable { private Map < String , String > config ; @ XmlElementWrapper public Map < String , String > getConfig ( ) { return config ; } public void setConfig ( Map < String , String > config ) { this . config = config ; } } </s>
<s> package annis . service . objects ; import java . io . Serializable ; import java . util . Collection ; import java . util . HashSet ; import javax . xml . bind . annotation . XmlRootElement ; @ XmlRootElement public class AnnisCorpusSet extends HashSet < AnnisCorpus > implements Serializable { public AnnisCorpusSet ( ) { super ( ) ; } public AnnisCorpusSet ( Collection < ? extends AnnisCorpus > collection ) { super ( collection ) ; } } </s>
<s> package annis . service . objects ; import java . util . HashMap ; import org . apache . commons . lang3 . builder . EqualsBuilder ; import org . apache . commons . lang3 . builder . HashCodeBuilder ; import annis . service . ifaces . AnnisToken ; public class AnnisTokenImpl extends HashMap < String , String > implements AnnisToken { private long id ; private String text ; private long left ; private long right ; private long tokenIndex ; private long corpusId ; public AnnisTokenImpl ( long id , String text , long left , long right , long tokenIndex , long corpusId ) { this . id = id ; this . text = text ; this . left = left ; this . right = right ; this . tokenIndex = tokenIndex ; this . corpusId = corpusId ; } public AnnisTokenImpl ( ) { } @ Override public long getId ( ) { return id ; } @ Override public String getText ( ) { return text ; } @ Override public long getLeft ( ) { return left ; } @ Override public long getRight ( ) { return right ; } @ Override public long getTokenIndex ( ) { return tokenIndex ; } @ Override public boolean equals ( Object o ) { if ( ! ( o instanceof AnnisTokenImpl ) ) { return false ; } AnnisTokenImpl other = ( AnnisTokenImpl ) o ; return new EqualsBuilder ( ) . append ( this . id , other . id ) . append ( this . text , other . text ) . isEquals ( ) ; } @ Override public int hashCode ( ) { return new HashCodeBuilder ( ) . append ( id ) . append ( text ) . toHashCode ( ) ; } public void setId ( long id ) { } @ Override public void setText ( String text ) { } @ Override public String toString ( ) { return "<STR_LIT>" + text + "<STR_LIT>" + super . toString ( ) ; } @ Override public long getCorpusId ( ) { return this . corpusId ; } @ Override public void setCorpusId ( long corpusId ) { this . corpusId = corpusId ; } } </s>
<s> package annis . service . objects ; import java . io . Serializable ; import java . util . Collection ; import java . util . Comparator ; import java . util . HashSet ; import java . util . Set ; import java . util . TreeSet ; import annis . service . ifaces . AnnisResult ; import annis . service . ifaces . AnnisResultSet ; public class AnnisResultSetImpl extends TreeSet < AnnisResult > implements AnnisResultSet { private static class AnnisResultSetComparator implements Comparator < AnnisResult > , Serializable { @ Override public int compare ( AnnisResult o1 , AnnisResult o2 ) { int order = Long . signum ( o1 . getStartNodeId ( ) - o2 . getStartNodeId ( ) ) ; if ( order == <NUM_LIT:0> ) { order = Long . signum ( o1 . getEndNodeId ( ) - o2 . getEndNodeId ( ) ) ; if ( order == <NUM_LIT:0> ) return - <NUM_LIT:1> ; else return order ; } else return order ; } } public AnnisResultSetImpl ( ) { super ( new AnnisResultSetComparator ( ) ) ; } public AnnisResultSetImpl ( Collection < ? extends AnnisResult > collection ) { this ( ) ; addAll ( collection ) ; } @ Override public Set < String > getAnnotationLevelSet ( ) { Set < String > levelSet = new HashSet < String > ( ) ; for ( AnnisResult result : this ) levelSet . addAll ( result . getAnnotationLevelSet ( ) ) ; return levelSet ; } @ Override public Set < String > getTokenAnnotationLevelSet ( ) { Set < String > levelSet = new HashSet < String > ( ) ; for ( AnnisResult result : this ) levelSet . addAll ( result . getTokenAnnotationLevelSet ( ) ) ; return levelSet ; } } </s>
<s> package annis . service . objects ; import java . io . Serializable ; import javax . xml . bind . annotation . XmlRootElement ; @ XmlRootElement public class AnnisCorpus implements Serializable , Comparable < AnnisCorpus > { private long id ; private String name ; private int textCount , tokenCount ; private String sourcePath ; public AnnisCorpus ( long id , String name , int textCount , int tokenCount ) { this . id = id ; this . textCount = textCount ; this . tokenCount = tokenCount ; this . name = name ; } public AnnisCorpus ( ) { this ( <NUM_LIT:0> , null , <NUM_LIT:0> , <NUM_LIT:0> ) ; } public long getId ( ) { return id ; } public void setId ( long id ) { this . id = id ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public int getTextCount ( ) { return textCount ; } public void setTextCount ( int textCount ) { this . textCount = textCount ; } public int getTokenCount ( ) { return tokenCount ; } public void setTokenCount ( int tokenCount ) { this . tokenCount = tokenCount ; } public String getSourcePath ( ) { return sourcePath ; } public void setSourcePath ( String sourcePath ) { this . sourcePath = sourcePath ; } @ Override public String toString ( ) { return String . valueOf ( "<STR_LIT>" + id + "<STR_LIT::U+0020>" + name ) ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final AnnisCorpus other = ( AnnisCorpus ) obj ; if ( this . id != other . id ) { return false ; } return true ; } @ Override public int hashCode ( ) { int hash = <NUM_LIT:5> ; hash = <NUM_LIT> * hash + ( int ) ( this . id ^ ( this . id > > > <NUM_LIT:32> ) ) ; return hash ; } @ Override public int compareTo ( AnnisCorpus o ) { if ( o == null ) { return - <NUM_LIT:1> ; } else { return id < o . getId ( ) ? - <NUM_LIT:1> : ( id > o . getId ( ) ? + <NUM_LIT:1> : <NUM_LIT:0> ) ; } } } </s>
<s> package annis . service . objects ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlElementWrapper ; import javax . xml . bind . annotation . XmlRootElement ; import javax . xml . bind . annotation . XmlTransient ; @ SuppressWarnings ( "<STR_LIT:serial>" ) @ XmlRootElement public class Match implements Serializable { private List < String > saltIDs ; public Match ( ) { saltIDs = new ArrayList < String > ( ) ; } public void setSaltId ( String id ) { saltIDs . add ( id ) ; } public String getSaltId ( int i ) { return saltIDs . get ( i ) ; } @ XmlElementWrapper ( name = "<STR_LIT>" ) @ XmlElement ( name = "<STR_LIT:id>" ) public List < String > getSaltIDs ( ) { return saltIDs ; } public void setSaltIDs ( List < String > saltIDs ) { this . saltIDs = saltIDs ; } } </s>
<s> package annis . service . objects ; import java . io . StringWriter ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . Set ; import javax . xml . parsers . DocumentBuilderFactory ; import javax . xml . transform . OutputKeys ; import javax . xml . transform . Transformer ; import javax . xml . transform . TransformerFactory ; import javax . xml . transform . dom . DOMSource ; import javax . xml . transform . stream . StreamResult ; import org . w3c . dom . Document ; import org . w3c . dom . Element ; import annis . model . AnnisNode ; import annis . model . Annotation ; import annis . model . AnnotationGraph ; import annis . model . Edge ; import annis . model . Edge . EdgeType ; import annis . service . ifaces . AnnisResult ; import annis . service . ifaces . AnnisToken ; import java . io . UnsupportedEncodingException ; import java . util . LinkedHashSet ; import javax . xml . parsers . ParserConfigurationException ; import javax . xml . transform . TransformerException ; @ Deprecated public class AnnisResultImpl implements AnnisResult { private AnnotationGraph graph ; private String paulaString = null ; public AnnisResultImpl ( ) { } public AnnisResultImpl ( AnnotationGraph graph ) { this . graph = graph ; } public List < AnnisToken > getTokenList ( ) { List < AnnisToken > result = new ArrayList < AnnisToken > ( ) ; for ( AnnisNode node : graph . getTokens ( ) ) { AnnisTokenImpl annisToken = new AnnisTokenImpl ( node . getId ( ) , node . getSpannedText ( ) , node . getLeft ( ) , node . getRight ( ) , node . getTokenIndex ( ) , node . getCorpus ( ) ) ; for ( Annotation annotation : node . getNodeAnnotations ( ) ) { annisToken . put ( annotation . getQualifiedName ( ) , annotation . getValue ( ) ) ; } result . add ( annisToken ) ; } return result ; } public long getStartNodeId ( ) { List < AnnisNode > tokens = graph . getTokens ( ) ; if ( ! tokens . isEmpty ( ) ) { return tokens . get ( <NUM_LIT:0> ) . getId ( ) ; } else { return <NUM_LIT:0> ; } } public long getEndNodeId ( ) { List < AnnisNode > tokens = graph . getTokens ( ) ; if ( ! tokens . isEmpty ( ) ) { return tokens . get ( tokens . size ( ) - <NUM_LIT:1> ) . getId ( ) ; } else { return <NUM_LIT:0> ; } } public Set < String > getAnnotationLevelSet ( ) { Set < String > result = new HashSet < String > ( ) ; for ( AnnisNode node : graph . getNodes ( ) ) { if ( ! node . isToken ( ) ) { for ( Annotation annotation : node . getNodeAnnotations ( ) ) { result . add ( annotation . getQualifiedName ( ) ) ; } } } return result ; } public Set < String > getTokenAnnotationLevelSet ( ) { Set < String > result = new HashSet < String > ( ) ; for ( AnnisNode token : graph . getTokens ( ) ) { for ( Annotation annotation : token . getNodeAnnotations ( ) ) { result . add ( annotation . getQualifiedName ( ) ) ; } } return result ; } public String getMarkerId ( Long nodeId ) { return isMarked ( nodeId ) ? String . valueOf ( nodeId ) : null ; } public boolean hasMarker ( String markerId ) { return isMarked ( Long . parseLong ( markerId ) ) ; } private void addNamespace ( Set < String > namespaces , String namespace ) { if ( namespace != null ) { namespaces . add ( namespace ) ; } } private boolean isMarked ( Long nodeId ) { return graph . getMatchedNodeIds ( ) . contains ( nodeId ) ; } public AnnotationGraph getGraph ( ) { return graph ; } public void setGraph ( AnnotationGraph graph ) { this . graph = graph ; } @ Override public String getDocumentName ( ) { return graph . getDocumentName ( ) ; } @ Override public String [ ] getPath ( ) { return graph . getPath ( ) ; } } </s>
<s> package annis . service . ifaces ; import annis . model . AnnotationGraph ; import java . io . Serializable ; import java . util . List ; import java . util . Set ; public interface AnnisResult extends Serializable { public String getDocumentName ( ) ; public String [ ] getPath ( ) ; public long getEndNodeId ( ) ; public long getStartNodeId ( ) ; public List < AnnisToken > getTokenList ( ) ; public Set < String > getAnnotationLevelSet ( ) ; public Set < String > getTokenAnnotationLevelSet ( ) ; public String getMarkerId ( Long nodeId ) ; public boolean hasMarker ( String markerId ) ; public AnnotationGraph getGraph ( ) ; } </s>
<s> package annis . service . ifaces ; import java . io . Serializable ; import java . util . Map ; public interface AnnisToken extends Map < String , String > , Serializable { public abstract long getId ( ) ; public abstract void setId ( long id ) ; public abstract String getText ( ) ; public abstract void setText ( String text ) ; public abstract long getCorpusId ( ) ; public abstract void setCorpusId ( long corpusId ) ; long getLeft ( ) ; long getRight ( ) ; long getTokenIndex ( ) ; } </s>
<s> package annis . service . ifaces ; import java . io . Serializable ; import java . util . Set ; public interface AnnisResultSet extends Set < AnnisResult > , Serializable { public abstract Set < String > getAnnotationLevelSet ( ) ; public abstract Set < String > getTokenAnnotationLevelSet ( ) ; } </s>
<s> package annis . resolver ; import java . io . Serializable ; import java . util . Properties ; import javax . xml . bind . annotation . XmlRootElement ; @ XmlRootElement public class ResolverEntry implements Serializable { public enum ElementType { node , edge } private long id ; private String corpus ; private String version ; private String namespace ; private ElementType element ; private String visType ; private String displayName ; private String visibility ; private Properties mappings ; private int order ; public ResolverEntry ( ) { } public ResolverEntry ( long id , String corpus , String version , String namespace , ElementType element , String visType , String displayName , String visibility , Properties mappings , int order ) { this . id = id ; this . corpus = corpus ; this . version = version ; this . namespace = namespace ; this . element = element ; this . visType = visType ; this . displayName = displayName ; this . mappings = mappings ; this . visibility = visibility ; this . order = order ; } public String getCorpus ( ) { return corpus ; } public void setCorpus ( String corpus ) { this . corpus = corpus ; } public String getDisplayName ( ) { return displayName ; } public void setDisplayName ( String displayName ) { this . displayName = displayName ; } public ElementType getElement ( ) { return element ; } public void setElement ( ElementType element ) { this . element = element ; } public long getId ( ) { return id ; } public void setId ( long id ) { this . id = id ; } public Properties getMappings ( ) { return mappings ; } public void setMappings ( Properties mappings ) { this . mappings = mappings ; } public String getNamespace ( ) { return namespace ; } public void setNamespace ( String namespace ) { this . namespace = namespace ; } public int getOrder ( ) { return order ; } public void setOrder ( int order ) { this . order = order ; } public String getVersion ( ) { return version ; } public void setVersion ( String version ) { this . version = version ; } public String getVisType ( ) { return visType ; } public void setVisType ( String visType ) { this . visType = visType ; } public String getVisibility ( ) { return this . visibility ; } public void setVisibility ( String visibility ) { this . visibility = visibility ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final ResolverEntry other = ( ResolverEntry ) obj ; if ( this . id != other . id ) { return false ; } if ( ( this . corpus == null ) ? ( other . corpus != null ) : ! this . corpus . equals ( other . corpus ) ) { return false ; } if ( ( this . version == null ) ? ( other . version != null ) : ! this . version . equals ( other . version ) ) { return false ; } if ( ( this . namespace == null ) ? ( other . namespace != null ) : ! this . namespace . equals ( other . namespace ) ) { return false ; } if ( this . element != other . element && ( this . element == null || ! this . element . equals ( other . element ) ) ) { return false ; } if ( ( this . visType == null ) ? ( other . visType != null ) : ! this . visType . equals ( other . visType ) ) { return false ; } if ( ( this . displayName == null ) ? ( other . displayName != null ) : ! this . displayName . equals ( other . displayName ) ) { return false ; } if ( ( this . visibility == null ) ? ( other . visibility != null ) : ! this . visibility . equals ( other . visibility ) ) { return false ; } if ( this . mappings != other . mappings && ( this . mappings == null || ! this . mappings . equals ( other . mappings ) ) ) { return false ; } if ( this . order != other . order ) { return false ; } return true ; } @ Override public int hashCode ( ) { int hash = <NUM_LIT:7> ; hash = <NUM_LIT> * hash + ( int ) ( this . id ^ ( this . id > > > <NUM_LIT:32> ) ) ; hash = <NUM_LIT> * hash + ( this . corpus != null ? this . corpus . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . version != null ? this . version . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . namespace != null ? this . namespace . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . element != null ? this . element . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . visType != null ? this . visType . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . displayName != null ? this . displayName . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . visibility != null ? this . visibility . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . mappings != null ? this . mappings . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + this . order ; return hash ; } } </s>
<s> package annis . resolver ; import annis . resolver . ResolverEntry . ElementType ; import java . io . Serializable ; import javax . xml . bind . annotation . XmlRootElement ; @ XmlRootElement public class SingleResolverRequest implements Serializable { private String corpusName ; private String namespace ; private ResolverEntry . ElementType type ; public SingleResolverRequest ( ) { } public SingleResolverRequest ( String corpusName , String namespace , ElementType type ) { this . corpusName = corpusName ; this . namespace = namespace ; this . type = type ; } public String getCorpusName ( ) { return corpusName ; } public String getNamespace ( ) { return namespace ; } public ElementType getType ( ) { return type ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final SingleResolverRequest other = ( SingleResolverRequest ) obj ; if ( ! this . corpusName . equals ( other . corpusName ) ) { return false ; } if ( ( this . namespace == null ) ? ( other . namespace != null ) : ! this . namespace . equals ( other . namespace ) ) { return false ; } if ( this . type != other . type ) { return false ; } return true ; } @ Override public int hashCode ( ) { int hash = <NUM_LIT:7> ; hash = <NUM_LIT> * hash + ( this . corpusName != null ? this . corpusName . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . namespace != null ? this . namespace . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . type != null ? this . type . hashCode ( ) : <NUM_LIT:0> ) ; return hash ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public class RightOverlap extends Join { public RightOverlap ( QueryNode target ) { super ( target ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public class LeftOverlap extends Join { public LeftOverlap ( QueryNode target ) { super ( target ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class Sibling extends Dominance { public Sibling ( QueryNode target ) { super ( target ) ; } public Sibling ( QueryNode target , String name ) { super ( target , name ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) + "<STR_LIT:U+0020(>" + name + "<STR_LIT:)>" ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public class PointingRelation extends RankTableJoin { public PointingRelation ( QueryNode target , String name ) { this ( target , name , <NUM_LIT:0> , <NUM_LIT:0> ) ; } public PointingRelation ( QueryNode target , String name , int distance ) { this ( target , name , distance , distance ) ; } public PointingRelation ( QueryNode target , String name , int minDistance , int maxDistance ) { super ( target , name , minDistance , maxDistance ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) + "<STR_LIT:U+0020(>" + name + "<STR_LIT:U+002CU+0020>" + minDistance + "<STR_LIT:U+002CU+0020>" + maxDistance + "<STR_LIT:)>" ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class RightDominance extends Dominance { public RightDominance ( QueryNode target ) { super ( target ) ; } public RightDominance ( QueryNode target , String name ) { super ( target , name , <NUM_LIT:1> ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) + "<STR_LIT:U+0020(>" + name + "<STR_LIT:)>" ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public class Identical extends Join { public Identical ( QueryNode target ) { super ( target ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public class Dominance extends RankTableJoin { public Dominance ( QueryNode target ) { this ( target , null ) ; } public Dominance ( QueryNode target , String name ) { this ( target , name , <NUM_LIT:0> , <NUM_LIT:0> ) ; } public Dominance ( QueryNode target , int distance ) { this ( target , null , distance ) ; } public Dominance ( QueryNode target , String name , int distance ) { this ( target , name , distance , distance ) ; } public Dominance ( QueryNode target , int minDistance , int maxDistance ) { this ( target , null , minDistance , maxDistance ) ; } public Dominance ( QueryNode target , String name , int minDistance , int maxDistance ) { super ( target , name , minDistance , maxDistance ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) + "<STR_LIT:U+0020(>" + name + "<STR_LIT:U+002CU+0020>" + minDistance + "<STR_LIT:U+002CU+0020>" + maxDistance + "<STR_LIT:)>" ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public class SameSpan extends Join { public SameSpan ( QueryNode target ) { super ( target ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public class LeftAlignment extends Join { public LeftAlignment ( QueryNode target ) { super ( target ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public class RightAlignment extends Join { public RightAlignment ( QueryNode target ) { super ( target ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public class Precedence extends RangedJoin { private String segmentationName ; public Precedence ( QueryNode target ) { this ( target , <NUM_LIT:0> , <NUM_LIT:0> ) ; } public Precedence ( QueryNode target , String segmentationName ) { this ( target , <NUM_LIT:0> , <NUM_LIT:0> , segmentationName ) ; } public Precedence ( QueryNode target , int distance ) { this ( target , distance , distance ) ; } public Precedence ( QueryNode target , int distance , String segmentationName ) { this ( target , distance , distance , segmentationName ) ; } public Precedence ( QueryNode target , int minDistance , int maxDistance ) { this ( target , minDistance , maxDistance , null ) ; } public Precedence ( QueryNode target , int minDistance , int maxDistance , String segmentationName ) { super ( target , minDistance , maxDistance ) ; this . segmentationName = segmentationName ; } public String getSegmentationName ( ) { return segmentationName ; } public void setSegmentationName ( String segmentationName ) { this . segmentationName = segmentationName ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) + "<STR_LIT:U+0020(>" + segmentationName + "<STR_LIT:U+0020>" + minDistance + "<STR_LIT:U+002CU+0020>" + maxDistance + "<STR_LIT:)>" ; } @ Override public int hashCode ( ) { int hash = <NUM_LIT:7> ; return hash ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final Precedence other = ( Precedence ) obj ; if ( ( this . segmentationName == null ) ? ( other . segmentationName != null ) : ! this . segmentationName . equals ( other . segmentationName ) ) { return false ; } return super . equals ( obj ) ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class LeftDominance extends Dominance { public LeftDominance ( QueryNode target ) { super ( target ) ; } public LeftDominance ( QueryNode target , String name ) { super ( target , name , <NUM_LIT:1> ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) + "<STR_LIT:U+0020(>" + name + "<STR_LIT:)>" ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public class Inclusion extends Join { public Inclusion ( QueryNode target ) { super ( target ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public abstract class RankTableJoin extends RangedJoin { protected String name ; public RankTableJoin ( QueryNode target , String name , int minDistance , int maxDistance ) { super ( target , minDistance , maxDistance ) ; this . name = name ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; import annis . model . DataObject ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public abstract class Join extends DataObject { protected QueryNode target ; public Join ( QueryNode target ) { this . target = target ; } public QueryNode getTarget ( ) { return target ; } public void setTarget ( QueryNode target ) { this . target = target ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public abstract class RangedJoin extends Join { protected int minDistance ; protected int maxDistance ; public RangedJoin ( QueryNode target , int minDistance , int maxDistance ) { super ( target ) ; this . minDistance = minDistance ; this . maxDistance = maxDistance ; } public int getMinDistance ( ) { return minDistance ; } public int getMaxDistance ( ) { return maxDistance ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public class CommonAncestor extends Dominance { public CommonAncestor ( QueryNode target ) { super ( target ) ; } public CommonAncestor ( QueryNode target , String name ) { super ( target , name ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) + "<STR_LIT:U+0020(>" + name + "<STR_LIT:)>" ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; @ Deprecated public class DirectDominance extends Join { public DirectDominance ( QueryNode target ) { super ( target ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) ; } } </s>
<s> package annis . sqlgen . model ; import annis . model . QueryNode ; public class Overlap extends Join { public Overlap ( QueryNode target ) { super ( target ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + target . getId ( ) ; } } </s>
<s> package annis . utils ; import annis . service . objects . AnnisResultImpl ; import annis . model . AnnisNode ; import annis . model . Annotation ; import annis . model . AnnotationGraph ; import annis . model . Edge ; import annis . model . Edge . EdgeType ; import annis . service . ifaces . AnnisResultSet ; import de . hu_berlin . german . korpling . saltnpepper . salt . graph . Node ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . SaltProject ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SCorpusGraph ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SDocument ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SDataSourceSequence ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SDocumentGraph ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SDominanceRelation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SPointingRelation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SSpanningRelation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . STYPE_NAME ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SToken ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SAnnotation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SFeature ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SNode ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SRelation ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Set ; import static annis . model . AnnisConstants . * ; import annis . service . objects . AnnisResultSetImpl ; import org . apache . commons . lang3 . StringUtils ; import org . eclipse . emf . common . util . BasicEList ; import org . eclipse . emf . common . util . EList ; public class LegacyGraphConverter { public static AnnisResultSet convertToResultSet ( SaltProject p ) { List < AnnotationGraph > annotationGraphs = convertToAOM ( p ) ; AnnisResultSetImpl annisResultSet = new AnnisResultSetImpl ( ) ; for ( AnnotationGraph annotationGraph : annotationGraphs ) { annisResultSet . add ( new AnnisResultImpl ( annotationGraph ) ) ; } return annisResultSet ; } public static List < AnnotationGraph > convertToAOM ( SaltProject p ) { List < AnnotationGraph > result = new ArrayList < AnnotationGraph > ( ) ; for ( SCorpusGraph corpusGraph : p . getSCorpusGraphs ( ) ) { for ( SDocument doc : corpusGraph . getSDocuments ( ) ) { result . add ( convertToAnnotationGraph ( doc ) ) ; } } return result ; } public static AnnotationGraph convertToAnnotationGraph ( SDocument document ) { AnnotationGraph result = null ; List < String > matchedIDs = new ArrayList < String > ( ) ; SFeature featMatchedIDs = document . getSFeature ( ANNIS_NS , FEAT_MATCHEDIDS ) ; if ( featMatchedIDs != null && featMatchedIDs . getSValueSTEXT ( ) != null ) { matchedIDs = Arrays . asList ( StringUtils . split ( featMatchedIDs . getSValueSTEXT ( ) , '<CHAR_LIT:U+002C>' ) ) ; } SDocumentGraph docGraph = document . getSDocumentGraph ( ) ; result = convertToAnnotationGraph ( docGraph , matchedIDs ) ; return result ; } public static AnnotationGraph convertToAnnotationGraph ( SDocumentGraph docGraph , List < String > matchedIDs ) { Set < String > matchSet = new HashSet < String > ( matchedIDs ) ; AnnotationGraph annoGraph = new AnnotationGraph ( ) ; annoGraph . setDocumentName ( docGraph . getSDocument ( ) . getSName ( ) ) ; Map < Node , AnnisNode > allNodes = new HashMap < Node , AnnisNode > ( ) ; for ( SNode sNode : docGraph . getSNodes ( ) ) { SFeature featInternalID = sNode . getSFeature ( ANNIS_NS , FEAT_INTERNALID ) ; if ( featInternalID != null ) { long internalID = featInternalID . getSValueSNUMERIC ( ) ; AnnisNode aNode = new AnnisNode ( internalID ) ; for ( SAnnotation sAnno : sNode . getSAnnotations ( ) ) { aNode . addNodeAnnotation ( new Annotation ( sAnno . getSNS ( ) , sAnno . getSName ( ) , sAnno . getSValueSTEXT ( ) ) ) ; } aNode . setName ( sNode . getSName ( ) ) ; aNode . setNamespace ( sNode . getSLayers ( ) . get ( <NUM_LIT:0> ) . getSName ( ) ) ; if ( sNode instanceof SToken ) { BasicEList < STYPE_NAME > textualRelation = new BasicEList < STYPE_NAME > ( ) ; textualRelation . add ( STYPE_NAME . STEXT_OVERLAPPING_RELATION ) ; EList < SDataSourceSequence > seqList = docGraph . getOverlappedDSSequences ( sNode , textualRelation ) ; if ( seqList != null ) { SDataSourceSequence seq = seqList . get ( <NUM_LIT:0> ) ; aNode . setSpannedText ( ( ( String ) seq . getSSequentialDS ( ) . getSData ( ) ) . substring ( seq . getSStart ( ) , seq . getSEnd ( ) ) ) ; aNode . setToken ( true ) ; aNode . setTokenIndex ( sNode . getSFeature ( ANNIS_NS , FEAT_TOKENINDEX ) . getSValueSNUMERIC ( ) ) ; } } else { aNode . setToken ( false ) ; aNode . setTokenIndex ( null ) ; } aNode . setCorpus ( sNode . getSFeature ( ANNIS_NS , FEAT_CORPUSREF ) . getSValueSNUMERIC ( ) ) ; aNode . setTextId ( sNode . getSFeature ( ANNIS_NS , FEAT_TEXTREF ) . getSValueSNUMERIC ( ) ) ; aNode . setLeft ( sNode . getSFeature ( ANNIS_NS , FEAT_LEFT ) . getSValueSNUMERIC ( ) ) ; aNode . setLeftToken ( sNode . getSFeature ( ANNIS_NS , FEAT_LEFTTOKEN ) . getSValueSNUMERIC ( ) ) ; aNode . setRight ( sNode . getSFeature ( ANNIS_NS , FEAT_RIGHT ) . getSValueSNUMERIC ( ) ) ; aNode . setRightToken ( sNode . getSFeature ( ANNIS_NS , FEAT_RIGHTTOKEN ) . getSValueSNUMERIC ( ) ) ; if ( matchSet . contains ( aNode . getName ( ) ) ) { aNode . setMatchedNodeInQuery ( ( long ) matchedIDs . indexOf ( aNode . getName ( ) ) + <NUM_LIT:1> ) ; annoGraph . getMatchedNodeIds ( ) . add ( aNode . getId ( ) ) ; } else { aNode . setMatchedNodeInQuery ( null ) ; } annoGraph . addNode ( aNode ) ; allNodes . put ( sNode , aNode ) ; } } for ( SRelation rel : docGraph . getSRelations ( ) ) { SFeature featPre = rel . getSFeature ( ANNIS_NS , FEAT_INTERNALID ) ; SFeature featComponentID = rel . getSFeature ( ANNIS_NS , FEAT_COMPONENTID ) ; if ( featPre != null ) { Edge aEdge = new Edge ( ) ; aEdge . setSource ( allNodes . get ( rel . getSource ( ) ) ) ; aEdge . setDestination ( allNodes . get ( rel . getTarget ( ) ) ) ; aEdge . setEdgeType ( EdgeType . UNKNOWN ) ; aEdge . setPre ( featPre . getSValueSNUMERIC ( ) ) ; aEdge . setComponentID ( featComponentID . getSValueSNUMERIC ( ) ) ; aEdge . setNamespace ( rel . getSLayers ( ) . get ( <NUM_LIT:0> ) . getSName ( ) ) ; aEdge . setName ( ( rel . getSTypes ( ) != null && rel . getSTypes ( ) . size ( ) > <NUM_LIT:0> ) ? rel . getSTypes ( ) . get ( <NUM_LIT:0> ) : null ) ; if ( rel instanceof SDominanceRelation ) { aEdge . setEdgeType ( EdgeType . DOMINANCE ) ; } else if ( rel instanceof SPointingRelation ) { aEdge . setEdgeType ( EdgeType . POINTING_RELATION ) ; } else if ( rel instanceof SSpanningRelation ) { aEdge . setEdgeType ( EdgeType . COVERAGE ) ; } for ( SAnnotation sAnno : rel . getSAnnotations ( ) ) { aEdge . addAnnotation ( new Annotation ( sAnno . getSNS ( ) , sAnno . getSName ( ) , sAnno . getSValueSTEXT ( ) ) ) ; } annoGraph . addEdge ( aEdge ) ; aEdge . getDestination ( ) . addIncomingEdge ( aEdge ) ; if ( aEdge . getSource ( ) != null ) { aEdge . getSource ( ) . addOutgoingEdge ( aEdge ) ; } } } return annoGraph ; } } </s>
<s> package annis . visualizers ; public interface LoadableVisualizer { public void addOnLoadCallBack ( Callback callback ) ; public void clearCallbacks ( ) ; public boolean isLoaded ( ) ; public interface Callback { public void visualizerLoaded ( LoadableVisualizer origin ) ; } } </s>
<s> package annis . exceptions ; public class AnnisException extends RuntimeException { public AnnisException ( ) { super ( ) ; } public AnnisException ( String message ) { super ( message ) ; } public AnnisException ( Throwable cause ) { super ( cause ) ; } public AnnisException ( String message , Throwable cause ) { super ( message , cause ) ; } } </s>
<s> package annis . exceptions ; public class AnnisMappingException extends AnnisException { public AnnisMappingException ( ) { super ( ) ; } public AnnisMappingException ( String message , Throwable cause ) { super ( message , cause ) ; } public AnnisMappingException ( String message ) { super ( message ) ; } public AnnisMappingException ( Throwable cause ) { super ( cause ) ; } } </s>
<s> package annis . exceptions ; public class AnnisCorpusAccessException extends AnnisException { public AnnisCorpusAccessException ( ) { super ( ) ; } public AnnisCorpusAccessException ( String message , Throwable cause ) { super ( message , cause ) ; } public AnnisCorpusAccessException ( String message ) { super ( message ) ; } public AnnisCorpusAccessException ( Throwable cause ) { super ( cause ) ; } } </s>
<s> package annis . exceptions ; public class AnnisQLSyntaxException extends AnnisException { public AnnisQLSyntaxException ( ) { super ( ) ; } public AnnisQLSyntaxException ( String message ) { super ( message ) ; } } </s>
<s> package annis . exceptions ; public class AnnisQLSemanticsException extends AnnisException { public AnnisQLSemanticsException ( ) { super ( ) ; } public AnnisQLSemanticsException ( String message ) { super ( message ) ; } } </s>
<s> package annis ; import de . hu_berlin . german . korpling . saltnpepper . salt . graph . Edge ; import de . hu_berlin . german . korpling . saltnpepper . salt . graph . GRAPH_TRAVERSE_TYPE ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . SaltProject ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SCorpus ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SCorpusGraph ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SDocument ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SDocumentGraph ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SOrderRelation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . STextualDS ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . STextualRelation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . SToken ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SAnnotation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SGraphTraverseHandler ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SNode ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SRelation ; import java . io . UnsupportedEncodingException ; import java . net . URI ; import java . net . URLDecoder ; import java . util . * ; import org . apache . commons . lang3 . StringUtils ; import org . eclipse . emf . common . util . BasicEList ; import org . eclipse . emf . common . util . EList ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class CommonHelper { private final static Logger log = LoggerFactory . getLogger ( CommonHelper . class ) ; public static boolean containsRTLText ( String str ) { for ( int i = <NUM_LIT:0> ; i < str . length ( ) ; i ++ ) { char cc = str . charAt ( i ) ; if ( cc >= <NUM_LIT> && cc <= <NUM_LIT> ) { return true ; } else if ( cc >= <NUM_LIT> && cc <= <NUM_LIT> ) { return true ; } else if ( cc >= <NUM_LIT> && cc <= <NUM_LIT> ) { return true ; } } return false ; } public static List < SNode > getSortedSegmentationNodes ( String segName , SDocumentGraph graph ) { List < SNode > token = new ArrayList < SNode > ( ) ; if ( segName == null ) { token . addAll ( graph . getSortedSTokenByText ( ) ) ; } else { Set < SNode > startNodes = new LinkedHashSet < SNode > ( ) ; Map < SNode , SOrderRelation > outRelationForNode = new HashMap < SNode , SOrderRelation > ( ) ; for ( SOrderRelation rel : graph . getSOrderRelations ( ) ) { if ( rel . getSTypes ( ) . contains ( segName ) ) { SNode node = rel . getSSource ( ) ; outRelationForNode . put ( node , rel ) ; EList < Edge > inEdgesForSource = graph . getInEdges ( node . getSId ( ) ) ; boolean hasInOrderEdge = false ; for ( Edge e : inEdgesForSource ) { if ( e instanceof SOrderRelation ) { hasInOrderEdge = true ; break ; } } if ( ! hasInOrderEdge ) { startNodes . add ( rel . getSSource ( ) ) ; } } } for ( SNode s : startNodes ) { SNode current = s ; while ( current != null ) { token . add ( current ) ; if ( outRelationForNode . containsKey ( current ) ) { current = outRelationForNode . get ( current ) . getSTarget ( ) ; } else { current = null ; } } } } return token ; } public static Set < String > getTokenAnnotationLevelSet ( SDocumentGraph graph ) { Set < String > result = new TreeSet < String > ( ) ; if ( graph != null ) { for ( SToken n : graph . getSTokens ( ) ) { for ( SAnnotation anno : n . getSAnnotations ( ) ) { result . add ( anno . getQName ( ) ) ; } } } return result ; } public static Set < String > getTokenAnnotationLevelSet ( SaltProject p ) { Set < String > result = new TreeSet < String > ( ) ; for ( SCorpusGraph corpusGraphs : p . getSCorpusGraphs ( ) ) { for ( SDocument doc : corpusGraphs . getSDocuments ( ) ) { SDocumentGraph g = doc . getSDocumentGraph ( ) ; result . addAll ( getTokenAnnotationLevelSet ( g ) ) ; } } return result ; } public static Set < String > getOrderingTypes ( SaltProject p ) { Set < String > result = new TreeSet < String > ( ) ; for ( SCorpusGraph corpusGraphs : p . getSCorpusGraphs ( ) ) { for ( SDocument doc : corpusGraphs . getSDocuments ( ) ) { SDocumentGraph g = doc . getSDocumentGraph ( ) ; if ( g != null ) { EList < SOrderRelation > orderRelations = g . getSOrderRelations ( ) ; if ( orderRelations != null ) { for ( SOrderRelation rel : orderRelations ) { result . addAll ( rel . getSTypes ( ) ) ; } } } } } return result ; } public static String getSpannedText ( SToken tok ) { SDocumentGraph graph = tok . getSDocumentGraph ( ) ; EList < Edge > edges = graph . getOutEdges ( tok . getSId ( ) ) ; for ( Edge e : edges ) { if ( e instanceof STextualRelation ) { STextualRelation textRel = ( STextualRelation ) e ; return textRel . getSTextualDS ( ) . getSText ( ) . substring ( textRel . getSStart ( ) , textRel . getSEnd ( ) ) ; } } return "<STR_LIT>" ; } public static List < String > getCorpusPath ( SCorpusGraph corpusGraph , SDocument doc ) { final List < String > result = new LinkedList < String > ( ) ; result . add ( doc . getSName ( ) ) ; SCorpus c = corpusGraph . getSCorpus ( doc ) ; BasicEList < SCorpus > cAsList = new BasicEList < SCorpus > ( ) ; cAsList . add ( c ) ; corpusGraph . traverse ( cAsList , GRAPH_TRAVERSE_TYPE . BOTTOM_UP_DEPTH_FIRST , "<STR_LIT>" , new SGraphTraverseHandler ( ) { @ Override public void nodeReached ( GRAPH_TRAVERSE_TYPE traversalType , String traversalId , SNode currNode , SRelation edge , SNode fromNode , long order ) { result . add ( currNode . getSName ( ) ) ; } @ Override public void nodeLeft ( GRAPH_TRAVERSE_TYPE traversalType , String traversalId , SNode currNode , SRelation edge , SNode fromNode , long order ) { } @ Override public boolean checkConstraint ( GRAPH_TRAVERSE_TYPE traversalType , String traversalId , SRelation edge , SNode currNode , long order ) { return true ; } } ) ; return result ; } public static List < String > getCorpusPath ( URI uri ) { String rawPath = StringUtils . strip ( uri . getRawPath ( ) , "<STR_LIT>" ) ; String [ ] path = rawPath . split ( "<STR_LIT:/>" ) ; ArrayList < String > result = new ArrayList < String > ( path . length ) ; for ( int i = <NUM_LIT:0> ; i < path . length ; i ++ ) { try { result . add ( URLDecoder . decode ( path [ i ] , "<STR_LIT:UTF-8>" ) ) ; } catch ( UnsupportedEncodingException ex ) { log . error ( null , ex ) ; result . add ( path [ i ] ) ; } } return result ; } } </s>
<s> package annis ; import annis . exceptions . AnnisQLSyntaxException ; import annis . utils . Utils ; import ch . qos . logback . classic . LoggerContext ; import ch . qos . logback . classic . PatternLayout ; import ch . qos . logback . classic . encoder . PatternLayoutEncoder ; import ch . qos . logback . classic . filter . ThresholdFilter ; import ch . qos . logback . classic . joran . JoranConfigurator ; import ch . qos . logback . core . ConsoleAppender ; import ch . qos . logback . core . joran . spi . JoranException ; import ch . qos . logback . core . util . StatusPrinter ; import java . io . File ; import java . io . IOException ; import java . io . PrintStream ; import java . lang . reflect . InvocationTargetException ; import java . lang . reflect . Method ; import java . util . * ; import org . apache . commons . lang3 . StringUtils ; import jline . console . ConsoleReader ; import jline . console . completer . StringsCompleter ; import jline . console . history . FileHistory ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import org . slf4j . bridge . SLF4JBridgeHandler ; import org . springframework . context . support . GenericXmlApplicationContext ; import org . springframework . core . env . MutablePropertySources ; import org . springframework . core . io . support . ResourcePropertySource ; public abstract class AnnisBaseRunner { private static final Logger log = LoggerFactory . getLogger ( AnnisBaseRunner . class ) ; private static String annisHomePath ; protected PrintStream out = System . out ; private FileHistory history ; private String helloMessage ; private String prompt ; public static AnnisBaseRunner getInstance ( String beanName , String ... contextLocations ) { return getInstance ( beanName , true , contextLocations ) ; } public static AnnisBaseRunner getInstance ( String beanName , boolean logToConsole , String ... contextLocations ) { return ( AnnisBaseRunner ) getBean ( beanName , logToConsole , contextLocations ) ; } public static Object getBean ( String beanName , boolean logToConsole , String ... contextLocations ) { checkForAnnisHome ( ) ; setupLogging ( logToConsole ) ; GenericXmlApplicationContext ctx = new GenericXmlApplicationContext ( ) ; MutablePropertySources sources = ctx . getEnvironment ( ) . getPropertySources ( ) ; try { sources . addFirst ( new ResourcePropertySource ( "<STR_LIT>" + Utils . getAnnisFile ( "<STR_LIT>" ) . getAbsolutePath ( ) ) ) ; } catch ( IOException ex ) { log . error ( "<STR_LIT>" , ex ) ; } ctx . load ( contextLocations ) ; ctx . refresh ( ) ; return ctx . getBean ( beanName ) ; } public void run ( String [ ] args ) { try { if ( args . length == <NUM_LIT:0> ) { runInteractive ( ) ; return ; } else { for ( String cmd : args ) { String [ ] split = cmd . split ( "<STR_LIT>" , <NUM_LIT:2> ) ; System . out . println ( "<STR_LIT>" + cmd + "<STR_LIT:'>" ) ; runCommand ( split [ <NUM_LIT:0> ] , split . length >= <NUM_LIT:2> ? split [ <NUM_LIT:1> ] : "<STR_LIT>" ) ; } } } catch ( AnnisRunnerException e ) { log . error ( "<STR_LIT>" , e ) ; error ( "<STR_LIT>" + e . getMessage ( ) ) ; } catch ( Throwable e ) { log . warn ( "<STR_LIT>" , e ) ; error ( e ) ; } } protected void runInteractive ( ) throws IOException { System . out . println ( helloMessage ) ; System . out . println ( ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( ) ; ConsoleReader console = new ConsoleReader ( ) ; File annisDir = new File ( System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ) ; if ( ! annisDir . mkdirs ( ) ) { log . warn ( "<STR_LIT>" + annisDir . getAbsolutePath ( ) ) ; } history = new FileHistory ( new File ( System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ) ) ; console . setHistory ( history ) ; console . setHistoryEnabled ( true ) ; console . setBellEnabled ( true ) ; List < String > commands = detectAvailableCommands ( ) ; Collections . sort ( commands ) ; console . addCompleter ( new StringsCompleter ( commands ) ) ; String line ; prompt = "<STR_LIT>" ; while ( ( line = console . readLine ( prompt + "<STR_LIT:U+0020>" ) ) != null ) { try { String command = line . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:0> ] ; if ( "<STR_LIT>" . equalsIgnoreCase ( command ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( StringUtils . join ( commands , "<STR_LIT:n>" ) ) ; } else { String args = StringUtils . join ( Arrays . asList ( line . split ( "<STR_LIT:U+0020>" ) ) . subList ( <NUM_LIT:1> , line . split ( "<STR_LIT:U+0020>" ) . length ) , "<STR_LIT:U+0020>" ) ; runCommand ( command , args ) ; } } catch ( IndexOutOfBoundsException e ) { continue ; } catch ( UsageException e ) { error ( e ) ; } } } protected void error ( Throwable e ) { error ( e . getMessage ( ) ) ; } protected void error ( String error ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + error ) ; } protected List < String > detectAvailableCommands ( ) { LinkedList < String > result = new LinkedList < String > ( ) ; Method [ ] methods = getClass ( ) . getMethods ( ) ; for ( Method m : methods ) { if ( m . getName ( ) . startsWith ( "<STR_LIT>" ) ) { String commandName = m . getName ( ) . substring ( "<STR_LIT>" . length ( ) ) ; if ( commandName . length ( ) > <NUM_LIT:1> ) { commandName = commandName . substring ( <NUM_LIT:0> , <NUM_LIT:1> ) . toLowerCase ( ) + commandName . substring ( <NUM_LIT:1> ) ; result . add ( commandName ) ; } } } return result ; } protected void runCommand ( String command , String args ) { String methodName = "<STR_LIT>" + command . substring ( <NUM_LIT:0> , <NUM_LIT:1> ) . toUpperCase ( ) + command . substring ( <NUM_LIT:1> ) ; log . debug ( "<STR_LIT>" + methodName ) ; try { long start = new Date ( ) . getTime ( ) ; Method commandMethod = getClass ( ) . getMethod ( methodName , String . class ) ; commandMethod . invoke ( this , args ) ; System . out . println ( "<STR_LIT>" + ( new Date ( ) . getTime ( ) - start ) + "<STR_LIT>" ) ; if ( history != null ) { history . flush ( ) ; } } catch ( InvocationTargetException e ) { Throwable cause = e . getCause ( ) ; try { throw cause ; } catch ( AnnisQLSyntaxException ee ) { error ( ee . getMessage ( ) ) ; } catch ( Throwable ee ) { log . error ( "<STR_LIT>" , ee ) ; error ( "<STR_LIT>" + ee . getMessage ( ) ) ; } } catch ( IllegalAccessException e ) { log . error ( "<STR_LIT>" , e ) ; throw new AnnisRunnerException ( "<STR_LIT>" + methodName , e ) ; } catch ( SecurityException e ) { log . error ( "<STR_LIT>" , e ) ; error ( e ) ; } catch ( NoSuchMethodException e ) { throw new UsageException ( "<STR_LIT>" + command ) ; } catch ( IOException e ) { log . error ( "<STR_LIT>" , e ) ; } } private static void checkForAnnisHome ( ) { annisHomePath = System . getProperty ( "<STR_LIT>" ) ; if ( annisHomePath == null ) { System . out . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } File file = new File ( annisHomePath ) ; if ( ! file . exists ( ) || ! file . isDirectory ( ) ) { System . out . println ( "<STR_LIT>" + annisHomePath + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:2> ) ; } } public static void setupLogging ( boolean console ) { LoggerContext loggerContext = ( LoggerContext ) LoggerFactory . getILoggerFactory ( ) ; JoranConfigurator jc = new JoranConfigurator ( ) ; jc . setContext ( loggerContext ) ; loggerContext . reset ( ) ; try { jc . doConfigure ( System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ) ; } catch ( JoranException ex ) { System . out . println ( ex . getMessage ( ) ) ; } ConsoleAppender consoleAppender = new ConsoleAppender ( ) ; consoleAppender . setContext ( loggerContext ) ; consoleAppender . setName ( "<STR_LIT>" ) ; PatternLayoutEncoder consoleEncoder = new PatternLayoutEncoder ( ) ; consoleEncoder . setContext ( loggerContext ) ; consoleEncoder . setPattern ( "<STR_LIT>" ) ; consoleEncoder . start ( ) ; ThresholdFilter consoleFilter = new ThresholdFilter ( ) ; consoleFilter . setLevel ( console ? "<STR_LIT>" : "<STR_LIT>" ) ; consoleFilter . start ( ) ; consoleAppender . setEncoder ( consoleEncoder ) ; consoleAppender . addFilter ( consoleFilter ) ; consoleAppender . setTarget ( "<STR_LIT>" ) ; consoleAppender . start ( ) ; ch . qos . logback . classic . Logger logbackLogger = loggerContext . getLogger ( Logger . ROOT_LOGGER_NAME ) ; logbackLogger . addAppender ( consoleAppender ) ; SLF4JBridgeHandler . removeHandlersForRootLogger ( ) ; ; SLF4JBridgeHandler . install ( ) ; } public static String getAnnisHome ( ) { return annisHomePath ; } public String getHelloMessage ( ) { return helloMessage ; } public void setHelloMessage ( String helloMessage ) { this . helloMessage = helloMessage ; } public String getPrompt ( ) { return prompt ; } public void setPrompt ( String prompt ) { this . prompt = prompt ; } public PrintStream getOut ( ) { return out ; } public void setOut ( PrintStream out ) { this . out = out ; } } </s>
<s> package annis ; @ Deprecated public class FindHelper { } </s>
<s> package annis . administration ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . apache . commons . cli . CommandLineParser ; import org . apache . commons . cli . Option ; import org . apache . commons . cli . Options ; import org . apache . commons . cli . ParseException ; import org . apache . commons . cli . PosixParser ; import org . springframework . core . io . ClassPathResource ; import org . springframework . core . io . Resource ; import annis . AnnisBaseRunner ; import annis . UsageException ; import annis . corpuspathsearch . Search ; import annis . utils . Utils ; import java . io . File ; import java . util . LinkedList ; import org . apache . commons . cli . CommandLine ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class AnnisAdminRunner extends AnnisBaseRunner { private static final Logger log = LoggerFactory . getLogger ( AnnisAdminRunner . class ) ; private CorpusAdministration corpusAdministration ; public static void main ( String [ ] args ) { AnnisBaseRunner . getInstance ( "<STR_LIT>" , "<STR_LIT>" + Utils . getAnnisFile ( "<STR_LIT>" ) . getAbsolutePath ( ) ) . run ( args ) ; } @ Override public void run ( String [ ] args ) { if ( args . length == <NUM_LIT:0> ) { throw new UsageException ( "<STR_LIT>" ) ; } String command = args [ <NUM_LIT:0> ] ; List < String > commandArgs = Arrays . asList ( args ) . subList ( <NUM_LIT:1> , args . length ) ; if ( "<STR_LIT>" . equals ( command ) || "<STR_LIT>" . equals ( command ) ) { usage ( null ) ; } else if ( "<STR_LIT>" . equals ( command ) ) { doInit ( commandArgs ) ; } else if ( "<STR_LIT>" . equals ( command ) ) { doImport ( commandArgs ) ; } else if ( "<STR_LIT>" . equals ( command ) ) { doDelete ( commandArgs ) ; } else if ( "<STR_LIT:list>" . equals ( command ) ) { doList ( ) ; } else if ( "<STR_LIT>" . equals ( command ) ) { doStats ( ) ; } else if ( "<STR_LIT>" . equals ( command ) ) { doIndexes ( ) ; } else { throw new UsageException ( "<STR_LIT>" + command ) ; } } static class OptionBuilder { private Options options ; public OptionBuilder ( ) { options = new Options ( ) ; } public OptionBuilder addParameter ( String opt , String longOpt , String description ) { options . addOption ( opt , longOpt , true , description ) ; return this ; } public OptionBuilder addLongParameter ( String longOpt , String description ) { options . addOption ( null , longOpt , true , description ) ; return this ; } public OptionBuilder addRequiredParameter ( String opt , String longOpt , String description ) { Option option = new Option ( opt , longOpt , true , description ) ; option . setRequired ( true ) ; options . addOption ( option ) ; return this ; } public OptionBuilder addToggle ( String opt , String longOpt , boolean hasArg , String description ) { options . addOption ( opt , longOpt , false , description ) ; return this ; } public Options createOptions ( ) { return options ; } } private void doInit ( List < String > commandArgs ) { Options options = new OptionBuilder ( ) . addParameter ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) . addLongParameter ( "<STR_LIT>" , "<STR_LIT>" ) . addRequiredParameter ( "<STR_LIT:d>" , "<STR_LIT>" , "<STR_LIT>" ) . addRequiredParameter ( "<STR_LIT>" , "<STR_LIT:user>" , "<STR_LIT>" ) . addRequiredParameter ( "<STR_LIT:p>" , "<STR_LIT:password>" , "<STR_LIT>" ) . addParameter ( "<STR_LIT:D>" , "<STR_LIT>" , "<STR_LIT>" ) . addParameter ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) . addParameter ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) . addParameter ( "<STR_LIT:m>" , "<STR_LIT>" , "<STR_LIT>" + "<STR_LIT>" ) . createOptions ( ) ; CommandLineParser parser = new PosixParser ( ) ; CommandLine cmdLine = null ; try { cmdLine = parser . parse ( options , commandArgs . toArray ( new String [ ] { } ) ) ; } catch ( ParseException e ) { throw new UsageException ( e . getMessage ( ) ) ; } String host = cmdLine . getOptionValue ( "<STR_LIT>" , "<STR_LIT:localhost>" ) ; String port = cmdLine . getOptionValue ( "<STR_LIT>" , "<STR_LIT>" ) ; String database = cmdLine . getOptionValue ( "<STR_LIT>" ) ; String user = cmdLine . getOptionValue ( "<STR_LIT:user>" ) ; String password = cmdLine . getOptionValue ( "<STR_LIT:password>" ) ; String defaultDatabase = cmdLine . getOptionValue ( "<STR_LIT>" , "<STR_LIT>" ) ; String superUser = cmdLine . getOptionValue ( "<STR_LIT>" , "<STR_LIT>" ) ; String superPassword = cmdLine . getOptionValue ( "<STR_LIT>" ) ; boolean migrateCorpora = cmdLine . hasOption ( "<STR_LIT>" ) ; List < Map < String , Object > > existingCorpora = new LinkedList < Map < String , Object > > ( ) ; if ( migrateCorpora ) { try { existingCorpora = corpusAdministration . listCorpusStats ( ) ; } catch ( Exception ex ) { log . warn ( "<STR_LIT>" + "<STR_LIT>" , ex ) ; migrateCorpora = false ; } } corpusAdministration . initializeDatabase ( host , port , database , user , password , defaultDatabase , superUser , superPassword ) ; if ( migrateCorpora && existingCorpora . size ( ) > <NUM_LIT:0> ) { String corpusRoot = cmdLine . getOptionValue ( "<STR_LIT>" ) ; Search search = null ; if ( corpusRoot != null && ! "<STR_LIT>" . equals ( corpusRoot ) ) { File rootCorpusPath = new File ( corpusRoot ) ; if ( rootCorpusPath . isDirectory ( ) ) { LinkedList < File > l = new LinkedList < File > ( ) ; l . add ( rootCorpusPath ) ; search = new Search ( l ) ; } } for ( Map < String , Object > corpusStat : existingCorpora ) { String corpusName = ( String ) corpusStat . get ( "<STR_LIT:name>" ) ; String migratePath = ( String ) corpusStat . get ( "<STR_LIT>" ) ; if ( migratePath == null ) { if ( search == null ) { log . error ( "<STR_LIT>" ) ; search = new Search ( new LinkedList < File > ( ) ) ; } else if ( ! search . isWasSearched ( ) ) { log . info ( "<STR_LIT>" + "<STR_LIT>" ) ; search . startSearch ( ) ; } if ( search . getCorpusPaths ( ) . containsKey ( corpusName ) ) { migratePath = search . getCorpusPaths ( ) . get ( corpusName ) . getParentFile ( ) . getAbsolutePath ( ) ; } } if ( migratePath == null || ! ( new File ( migratePath ) . isDirectory ( ) ) ) { log . warn ( "<STR_LIT>" + corpusName + "<STR_LIT>" + "<STR_LIT>" ) ; } else { log . info ( "<STR_LIT>" + corpusName ) ; corpusAdministration . importCorpora ( migratePath ) ; } } } } private void doImport ( List < String > commandArgs ) { if ( commandArgs . isEmpty ( ) ) { throw new UsageException ( "<STR_LIT>" ) ; } corpusAdministration . importCorpora ( commandArgs ) ; } private void doDelete ( List < String > commandArgs ) { if ( commandArgs . isEmpty ( ) ) { throw new UsageException ( "<STR_LIT>" ) ; } List < Long > ids = new ArrayList < Long > ( ) ; for ( String id : commandArgs ) { try { ids . add ( Long . parseLong ( id ) ) ; } catch ( NumberFormatException e ) { throw new UsageException ( "<STR_LIT>" + id ) ; } } corpusAdministration . deleteCorpora ( ids ) ; } private void doList ( ) { List < Map < String , Object > > stats = corpusAdministration . listCorpusStats ( ) ; if ( stats . isEmpty ( ) ) { System . out . println ( "<STR_LIT>" ) ; return ; } printTable ( stats ) ; } private void doStats ( ) { printTable ( corpusAdministration . listTableStats ( ) ) ; } private void doIndexes ( ) { for ( String indexDefinition : corpusAdministration . listUsedIndexes ( ) ) { System . out . println ( indexDefinition + "<STR_LIT:;>" ) ; } for ( String indexDefinition : corpusAdministration . listUnusedIndexes ( ) ) { System . out . println ( "<STR_LIT>" + indexDefinition + "<STR_LIT:;>" ) ; } } private void usage ( String error ) { Resource resource = new ClassPathResource ( "<STR_LIT>" ) ; BufferedReader reader = null ; try { reader = new BufferedReader ( new InputStreamReader ( resource . getInputStream ( ) , "<STR_LIT:UTF-8>" ) ) ; for ( String line = reader . readLine ( ) ; line != null ; line = reader . readLine ( ) ) { System . out . println ( line ) ; } } catch ( IOException e ) { log . warn ( "<STR_LIT>" + e . getMessage ( ) ) ; } finally { if ( reader != null ) { try { reader . close ( ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } } } if ( error != null ) { error ( error ) ; } } private void printTable ( List < Map < String , Object > > table ) { Map < String , Object > first = table . get ( <NUM_LIT:0> ) ; List < String > columnNames = new ArrayList < String > ( first . keySet ( ) ) ; Map < String , Integer > columnSize = new HashMap < String , Integer > ( ) ; for ( String column : columnNames ) { columnSize . put ( column , column . length ( ) ) ; } for ( Map < String , Object > row : table ) { for ( Map . Entry < String , Object > e : row . entrySet ( ) ) { String column = e . getKey ( ) ; final Object value = e . getValue ( ) ; if ( value == null ) { continue ; } int length = value . toString ( ) . length ( ) ; if ( columnSize . get ( column ) < length ) { columnSize . put ( column , length ) ; } } } StringBuffer sb = new StringBuffer ( ) ; for ( String column : columnNames ) { sb . append ( pad ( column , columnSize . get ( column ) ) ) ; sb . append ( "<STR_LIT>" ) ; } sb . setLength ( sb . length ( ) - "<STR_LIT>" . length ( ) ) ; System . out . println ( sb ) ; for ( Map < String , Object > row : table ) { sb = new StringBuffer ( ) ; for ( String column : columnNames ) { sb . append ( pad ( row . get ( column ) , columnSize . get ( column ) ) ) ; sb . append ( "<STR_LIT>" ) ; } sb . setLength ( sb . length ( ) - "<STR_LIT>" . length ( ) ) ; System . out . println ( sb ) ; } } private String pad ( Object o , int length ) { String s = o != null ? o . toString ( ) : "<STR_LIT>" ; if ( s . length ( ) > length ) { return s ; } StringBuilder padded = new StringBuilder ( ) ; for ( int i = <NUM_LIT:0> ; i < length - s . length ( ) ; ++ i ) { padded . append ( "<STR_LIT:U+0020>" ) ; } padded . append ( o ) ; return padded . toString ( ) ; } public CorpusAdministration getCorpusAdministration ( ) { return corpusAdministration ; } public void setCorpusAdministration ( CorpusAdministration administration ) { this . corpusAdministration = administration ; } } </s>
<s> package annis . administration ; import annis . AnnisRunnerException ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class FileAccessException extends AnnisRunnerException { public FileAccessException ( ) { super ( ) ; } public FileAccessException ( String message , Throwable cause ) { super ( message , cause ) ; } public FileAccessException ( String message ) { super ( message ) ; } public FileAccessException ( Throwable cause ) { super ( cause ) ; } } </s>
<s> package annis . administration ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileWriter ; import java . io . IOException ; import java . util . Arrays ; import java . util . List ; import java . util . Map ; import javax . sql . DataSource ; import org . postgresql . Driver ; import org . springframework . jdbc . datasource . SimpleDriverDataSource ; import org . springframework . transaction . annotation . Transactional ; import annis . AnnisRunnerException ; import annis . exceptions . AnnisException ; import org . apache . commons . io . output . FileWriterWithEncoding ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class CorpusAdministration { private AdministrationDao administrationDao ; private static final Logger log = LoggerFactory . getLogger ( CorpusAdministration . class ) ; public CorpusAdministration ( ) { } protected DataSource createDataSource ( String host , String port , String database , String user , String password ) { String url = "<STR_LIT>" + host + "<STR_LIT::>" + port + "<STR_LIT:/>" + database ; return new SimpleDriverDataSource ( new Driver ( ) , url , user , password ) ; } @ Transactional ( readOnly = false ) public void deleteCorpora ( List < Long > ids ) { List < Long > corpora = administrationDao . listToplevelCorpora ( ) ; for ( long id : ids ) { if ( ! corpora . contains ( id ) ) { throw new AnnisRunnerException ( "<STR_LIT>" + id ) ; } } log . info ( "<STR_LIT>" + ids ) ; administrationDao . deleteCorpora ( ids ) ; log . info ( "<STR_LIT>" + ids ) ; } public void initializeDatabase ( String host , String port , String database , String user , String password , String defaultDatabase , String superUser , String superPassword ) { log . info ( "<STR_LIT>" ) ; log . info ( "<STR_LIT>" ) ; administrationDao . setDataSource ( createDataSource ( host , port , defaultDatabase , superUser , superPassword ) ) ; administrationDao . dropDatabase ( database ) ; administrationDao . dropUser ( user ) ; administrationDao . createUser ( user , password ) ; administrationDao . createDatabase ( database ) ; administrationDao . setDataSource ( createDataSource ( host , port , database , superUser , superPassword ) ) ; administrationDao . setupDatabase ( ) ; administrationDao . setDataSource ( createDataSource ( host , port , database , user , password ) ) ; administrationDao . createSchema ( ) ; administrationDao . createSchemaIndexes ( ) ; administrationDao . populateSchema ( ) ; writeDatabasePropertiesFile ( host , port , database , user , password ) ; } public void importCorpora ( List < String > paths ) { for ( String path : paths ) { log . info ( "<STR_LIT>" + path ) ; administrationDao . importCorpus ( path ) ; log . info ( "<STR_LIT>" + path ) ; } } public boolean checkDatabaseSchemaVersion ( ) { try { administrationDao . checkDatabaseSchemaVersion ( ) ; } catch ( AnnisException ex ) { return false ; } return true ; } public void importCorpora ( String ... paths ) { importCorpora ( Arrays . asList ( paths ) ) ; } public List < Map < String , Object > > listCorpusStats ( ) { return administrationDao . listCorpusStats ( ) ; } public List < Map < String , Object > > listTableStats ( ) { return administrationDao . listTableStats ( ) ; } public List < String > listUsedIndexes ( ) { return administrationDao . listUsedIndexes ( ) ; } public List < String > listUnusedIndexes ( ) { return administrationDao . listUnusedIndexes ( ) ; } protected void writeDatabasePropertiesFile ( String host , String port , String database , String user , String password ) { File file = new File ( System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" , "<STR_LIT>" ) ; try { BufferedWriter writer = new BufferedWriter ( new FileWriterWithEncoding ( file , "<STR_LIT:UTF-8>" ) ) ; writer . write ( "<STR_LIT>" ) ; writer . write ( "<STR_LIT>" ) ; writer . write ( "<STR_LIT>" + host + "<STR_LIT::>" + port + "<STR_LIT:/>" + database + "<STR_LIT:n>" ) ; writer . write ( "<STR_LIT>" + user + "<STR_LIT:n>" ) ; writer . write ( "<STR_LIT>" + password + "<STR_LIT:n>" ) ; writer . close ( ) ; } catch ( IOException e ) { log . error ( "<STR_LIT>" , e ) ; throw new FileAccessException ( e ) ; } log . info ( "<STR_LIT>" + file . getAbsolutePath ( ) ) ; } public AdministrationDao getAdministrationDao ( ) { return administrationDao ; } public void setAdministrationDao ( AdministrationDao administrationDao ) { this . administrationDao = administrationDao ; } } </s>
<s> package annis . administration ; import annis . AnnisRunnerException ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class DatabaseAccessException extends AnnisRunnerException { public DatabaseAccessException ( ) { super ( ) ; } public DatabaseAccessException ( String message , Throwable cause ) { super ( message , cause ) ; } public DatabaseAccessException ( String message ) { super ( message ) ; } public DatabaseAccessException ( Throwable cause ) { super ( cause ) ; } } </s>
<s> package annis . administration ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class ApAdministrationDao extends DefaultAdministrationDao { private static final Logger log = LoggerFactory . getLogger ( ApAdministrationDao . class ) ; @ Override public void populateSchema ( ) { super . populateSchema ( ) ; log . info ( "<STR_LIT>" ) ; executeSqlFromScript ( getDbLayout ( ) + "<STR_LIT>" ) ; } } </s>
<s> package annis . administration ; import annis . exceptions . AnnisException ; import java . util . List ; import java . util . Map ; import javax . sql . DataSource ; import org . springframework . jdbc . core . namedparam . MapSqlParameterSource ; public interface AdministrationDao { public void setDataSource ( DataSource dataSource ) ; public void dropDatabase ( String database ) ; public List < Long > listToplevelCorpora ( ) ; public void deleteCorpora ( List < Long > ids ) ; public void dropUser ( String username ) ; public void createUser ( String username , String password ) ; public void createDatabase ( String database ) ; public void setupDatabase ( ) ; public void createSchema ( ) ; public void populateSchema ( ) ; public void createSchemaIndexes ( ) ; public void importCorpus ( String path ) ; public List < Map < String , Object > > listCorpusStats ( ) ; public List < Map < String , Object > > listTableStats ( ) ; public List < String > listUsedIndexes ( ) ; public List < String > listUnusedIndexes ( ) ; public String getDatabaseSchemaVersion ( ) ; public boolean checkDatabaseSchemaVersion ( ) throws AnnisException ; public boolean executeSqlFromScript ( String script ) ; public boolean executeSqlFromScript ( String script , MapSqlParameterSource args ) ; } </s>
<s> package annis . administration ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class SfAdministrationDao extends DefaultAdministrationDao { private static final Logger log = LoggerFactory . getLogger ( AdministrationDao . class ) ; @ Override public void populateSchema ( ) { super . populateSchema ( ) ; log . info ( "<STR_LIT>" ) ; executeSqlFromScript ( getDbLayout ( ) + "<STR_LIT>" ) ; } @ Override void analyzeFacts ( long corpusID ) { log . info ( "<STR_LIT>" + corpusID ) ; getJdbcTemplate ( ) . getJdbcOperations ( ) . execute ( "<STR_LIT>" + corpusID ) ; log . info ( "<STR_LIT>" + corpusID ) ; getJdbcTemplate ( ) . getJdbcOperations ( ) . execute ( "<STR_LIT>" + corpusID ) ; log . info ( "<STR_LIT>" ) ; getJdbcTemplate ( ) . getJdbcOperations ( ) . execute ( "<STR_LIT>" ) ; log . info ( "<STR_LIT>" ) ; getJdbcTemplate ( ) . getJdbcOperations ( ) . execute ( "<STR_LIT>" ) ; } } </s>
<s> package annis . administration ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . sql . PreparedStatement ; import java . sql . SQLException ; import java . util . Map ; import javax . activation . MimetypesFileTypeMap ; import org . apache . commons . io . FilenameUtils ; import org . slf4j . LoggerFactory ; import org . springframework . dao . DataAccessException ; import org . springframework . jdbc . core . PreparedStatementCallback ; public class MediaImportPreparedStatementCallbackImpl implements PreparedStatementCallback < Boolean > { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( MediaImportPreparedStatementCallbackImpl . class ) ; private FileInputStream fileStream ; private File file ; private String mimeType ; private long corpusRef ; public MediaImportPreparedStatementCallbackImpl ( String absolutePath , long corpusRef , Map < String , String > mimeTypeMapping ) { try { this . file = new File ( absolutePath ) ; fileStream = new FileInputStream ( file ) ; String fileEnding = FilenameUtils . getExtension ( absolutePath ) ; if ( mimeTypeMapping . containsKey ( fileEnding ) ) { this . mimeType = mimeTypeMapping . get ( fileEnding ) ; } else { this . mimeType = new MimetypesFileTypeMap ( ) . getContentType ( file ) ; } this . corpusRef = corpusRef ; } catch ( FileNotFoundException ex ) { log . error ( null , ex ) ; } } @ Override public Boolean doInPreparedStatement ( PreparedStatement ps ) throws SQLException , DataAccessException { ps . setBinaryStream ( <NUM_LIT:1> , fileStream , ( int ) file . length ( ) ) ; ps . setLong ( <NUM_LIT:2> , this . corpusRef ) ; ps . setLong ( <NUM_LIT:3> , file . length ( ) ) ; ps . setString ( <NUM_LIT:4> , this . mimeType ) ; ps . setString ( <NUM_LIT:5> , file . getName ( ) ) ; ps . executeUpdate ( ) ; try { fileStream . close ( ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } return true ; } } </s>
<s> package annis . administration ; import annis . exceptions . AnnisException ; import java . io . * ; import java . sql . Connection ; import java . sql . ResultSet ; import java . sql . SQLException ; import java . sql . Types ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import java . util . logging . Level ; import javax . sql . DataSource ; import org . apache . commons . io . FilenameUtils ; import org . apache . commons . io . filefilter . DirectoryFileFilter ; import org . apache . commons . io . filefilter . FileFileFilter ; import org . apache . commons . lang3 . StringUtils ; import org . postgresql . PGConnection ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import org . springframework . core . io . FileSystemResource ; import org . springframework . core . io . Resource ; import org . springframework . dao . DataAccessException ; import org . springframework . jdbc . core . JdbcOperations ; import org . springframework . jdbc . core . ResultSetExtractor ; import org . springframework . jdbc . core . namedparam . MapSqlParameterSource ; import org . springframework . jdbc . core . namedparam . NamedParameterJdbcTemplate ; import org . springframework . jdbc . core . namedparam . SqlParameterSource ; import org . springframework . jdbc . core . simple . ParameterizedSingleColumnRowMapper ; import org . springframework . jdbc . datasource . DataSourceUtils ; import org . springframework . transaction . annotation . Transactional ; public class DefaultAdministrationDao implements AdministrationDao { private static final Logger log = LoggerFactory . getLogger ( AdministrationDao . class ) ; private String externalFilesPath ; private String scriptPath ; private NamedParameterJdbcTemplate jdbcTemplate ; private DataSource dataSource ; private boolean temporaryStagingArea ; private String schemaVersion ; private Map < String , String > mimeTypeMapping ; private static final String FILE_RESOLVER_VIS_MAP = "<STR_LIT>" ; private String [ ] importedTables = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:text>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , FILE_RESOLVER_VIS_MAP } ; private String [ ] tablesToCopyManually = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:text>" , FILE_RESOLVER_VIS_MAP , "<STR_LIT>" , "<STR_LIT>" } ; private String [ ] createdTables = { "<STR_LIT>" , "<STR_LIT>" } ; private String dbLayout ; @ Override public void dropDatabase ( String database ) { String sql = "<STR_LIT>" ; SqlParameterSource args = makeArgs ( ) . addValue ( "<STR_LIT>" , database ) ; int count = jdbcTemplate . queryForInt ( sql , args ) ; if ( count != <NUM_LIT:0> ) { log . debug ( "<STR_LIT>" ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + database ) ; } } @ Override public void dropUser ( String username ) { String sql = "<STR_LIT>" ; SqlParameterSource args = makeArgs ( ) . addValue ( "<STR_LIT:username>" , username ) ; int count = jdbcTemplate . queryForInt ( sql , args ) ; if ( count != <NUM_LIT:0> ) { log . debug ( "<STR_LIT>" ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + username ) ; } } @ Override public void createUser ( String username , String password ) { log . info ( "<STR_LIT>" + username ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + username + "<STR_LIT>" + password + "<STR_LIT:'>" ) ; } @ Override public void createDatabase ( String database ) { log . info ( "<STR_LIT>" + database + "<STR_LIT>" ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + database + "<STR_LIT>" ) ; } @ Override public void setupDatabase ( ) { installPlPgSql ( ) ; createFunctionUniqueToplevelCorpusName ( ) ; } protected void installPlPgSql ( ) { log . info ( "<STR_LIT>" ) ; try { jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" ) ; } catch ( Exception ex ) { log . warn ( "<STR_LIT>" + ex . getMessage ( ) ) ; } } protected void createFunctionUniqueToplevelCorpusName ( ) { log . info ( "<STR_LIT>" ) ; executeSqlFromScript ( "<STR_LIT>" ) ; } @ Override public void createSchema ( ) { log . info ( "<STR_LIT>" + dbLayout + "<STR_LIT:)>" ) ; executeSqlFromScript ( dbLayout + "<STR_LIT>" ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + "<STR_LIT>" + StringUtils . replace ( getSchemaVersion ( ) , "<STR_LIT:'>" , "<STR_LIT>" ) + "<STR_LIT>" ) ; } @ Override public void createSchemaIndexes ( ) { log . info ( "<STR_LIT>" + dbLayout + "<STR_LIT:)>" ) ; executeSqlFromScript ( dbLayout + "<STR_LIT>" ) ; } @ Override public void populateSchema ( ) { log . info ( "<STR_LIT>" ) ; bulkloadTableFromResource ( "<STR_LIT>" , new FileSystemResource ( new File ( scriptPath , "<STR_LIT>" ) ) ) ; executeSqlFromScript ( "<STR_LIT>" ) ; } @ Override @ Transactional ( readOnly = true ) public String getDatabaseSchemaVersion ( ) { try { Map < String , String > map = new HashMap < String , String > ( ) ; List < Map < String , Object > > result = jdbcTemplate . queryForList ( "<STR_LIT>" , map ) ; String schema = result . size ( ) > <NUM_LIT:0> ? ( String ) result . get ( <NUM_LIT:0> ) . get ( "<STR_LIT:value>" ) : "<STR_LIT>" ; return schema ; } catch ( DataAccessException ex ) { String error = "<STR_LIT>" + "<STR_LIT>" ; log . error ( error ) ; } return "<STR_LIT>" ; } @ Override public boolean checkDatabaseSchemaVersion ( ) throws AnnisException { String dbSchemaVersion = getDatabaseSchemaVersion ( ) ; if ( getSchemaVersion ( ) != null && ! getSchemaVersion ( ) . equalsIgnoreCase ( dbSchemaVersion ) ) { String error = "<STR_LIT>" + dbSchemaVersion + "<STR_LIT>" ; log . error ( error ) ; throw new AnnisException ( error ) ; } return true ; } @ Override @ Transactional ( readOnly = false ) public void importCorpus ( String path ) { checkDatabaseSchemaVersion ( ) ; createStagingArea ( temporaryStagingArea ) ; bulkImport ( path ) ; createStagingAreaIndexes ( ) ; computeTopLevelCorpus ( ) ; analyzeStagingTables ( ) ; computeLeftTokenRightToken ( ) ; adjustRankPrePost ( ) ; long corpusID = updateIds ( ) ; importBinaryData ( path ) ; extendStagingText ( corpusID ) ; computeRealRoot ( ) ; computeLevel ( ) ; computeCorpusStatistics ( path ) ; updateCorpusStatsId ( corpusID ) ; applyConstraints ( ) ; analyzeStagingTables ( ) ; insertCorpus ( ) ; computeCorpusPath ( corpusID ) ; createAnnotations ( corpusID ) ; createFacts ( corpusID ) ; updateCorpusStatistic ( corpusID ) ; if ( temporaryStagingArea ) { dropStagingArea ( ) ; } analyzeFacts ( corpusID ) ; } protected void dropIndexes ( ) { log . info ( "<STR_LIT>" ) ; for ( String index : listIndexesOnTables ( allTables ( ) ) ) { log . debug ( "<STR_LIT>" + index ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + index ) ; } } void createStagingArea ( boolean useTemporary ) { log . info ( "<STR_LIT>" ) ; MapSqlParameterSource args = makeArgs ( ) . addValue ( "<STR_LIT>" , useTemporary ? "<STR_LIT>" : "<STR_LIT>" ) ; executeSqlFromScript ( "<STR_LIT>" , args ) ; } void bulkImport ( String path ) { log . info ( "<STR_LIT>" ) ; for ( String table : importedTables ) { if ( table . equalsIgnoreCase ( FILE_RESOLVER_VIS_MAP ) ) { try { JdbcOperations sqlOps = jdbcTemplate . getJdbcOperations ( ) ; File resolver_vis_tab = new File ( path , table + "<STR_LIT>" ) ; BufferedReader bReader = new BufferedReader ( new InputStreamReader ( new FileInputStream ( resolver_vis_tab ) , "<STR_LIT:UTF-8>" ) ) ; String firstLine = bReader . readLine ( ) ; bReader . close ( ) ; int cols = <NUM_LIT:9> ; if ( firstLine != null ) { String [ ] entries = firstLine . split ( "<STR_LIT:t>" ) ; cols = entries . length ; log . debug ( "<STR_LIT>" , entries , cols ) ; } switch ( cols ) { case <NUM_LIT:8> : StringBuilder sb = new StringBuilder ( ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sqlOps . execute ( sb . toString ( ) ) ; bulkloadTableFromResource ( "<STR_LIT>" , new FileSystemResource ( resolver_vis_tab ) ) ; sb = new StringBuilder ( ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( tableInStagingArea ( FILE_RESOLVER_VIS_MAP ) ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT:U+0020(>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT:)>" ) ; sb . append ( "<STR_LIT:n>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) ; sqlOps . execute ( sb . toString ( ) ) ; sqlOps . execute ( "<STR_LIT>" ) ; break ; case <NUM_LIT:9> : bulkloadTableFromResource ( tableInStagingArea ( table ) , new FileSystemResource ( new File ( path , table + "<STR_LIT>" ) ) ) ; break ; default : log . error ( "<STR_LIT>" ) ; throw new RuntimeException ( ) ; } } catch ( IOException e ) { log . error ( "<STR_LIT>" , table + "<STR_LIT>" , e ) ; } catch ( FileAccessException e ) { log . error ( "<STR_LIT>" , table + "<STR_LIT>" , e ) ; } } else if ( table . equalsIgnoreCase ( "<STR_LIT>" ) ) { bulkImportNode ( path ) ; } else { bulkloadTableFromResource ( tableInStagingArea ( table ) , new FileSystemResource ( new File ( path , table + "<STR_LIT>" ) ) ) ; } } } private void bulkImportNode ( String path ) { try { File nodeTabFile = new File ( path , "<STR_LIT>" ) ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( new FileInputStream ( nodeTabFile ) , "<STR_LIT:UTF-8>" ) ) ; String firstLine = reader . readLine ( ) ; reader . close ( ) ; int columnNumber = firstLine == null ? <NUM_LIT> : firstLine . split ( "<STR_LIT:t>" ) . length ; if ( columnNumber == <NUM_LIT> ) { bulkloadTableFromResource ( tableInStagingArea ( "<STR_LIT>" ) , new FileSystemResource ( nodeTabFile ) ) ; } else if ( columnNumber == <NUM_LIT:10> ) { jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; bulkloadTableFromResource ( "<STR_LIT>" , new FileSystemResource ( nodeTabFile ) ) ; log . info ( "<STR_LIT>" ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + tableInStagingArea ( "<STR_LIT>" ) + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } else { throw new RuntimeException ( "<STR_LIT>" + "<STR_LIT>" + columnNumber ) ; } } catch ( IOException ex ) { log . error ( null , ex ) ; } } void createStagingAreaIndexes ( ) { log . info ( "<STR_LIT>" ) ; executeSqlFromScript ( "<STR_LIT>" ) ; } void computeTopLevelCorpus ( ) { log . info ( "<STR_LIT>" ) ; executeSqlFromScript ( "<STR_LIT>" ) ; } void importBinaryData ( String path ) { log . info ( "<STR_LIT>" ) ; File extData = new File ( path + "<STR_LIT>" ) ; if ( extData . canRead ( ) && extData . isDirectory ( ) ) { File [ ] documents = extData . listFiles ( ( FileFilter ) DirectoryFileFilter . DIRECTORY ) ; for ( File doc : documents ) { if ( doc . isDirectory ( ) && doc . canRead ( ) ) { File [ ] dataFiles = doc . listFiles ( ( FileFilter ) FileFileFilter . FILE ) ; for ( File data : dataFiles ) { String extension = FilenameUtils . getExtension ( data . getName ( ) ) ; try { if ( mimeTypeMapping . containsKey ( extension ) ) { log . info ( "<STR_LIT>" + data . getCanonicalPath ( ) + "<STR_LIT>" ) ; String sqlScript = "<STR_LIT>" ; long corpusID = jdbcTemplate . getJdbcOperations ( ) . queryForLong ( sqlScript , doc . getName ( ) ) ; importSingleFile ( data . getCanonicalPath ( ) , corpusID ) ; } else { log . warn ( "<STR_LIT>" + data . getCanonicalPath ( ) + "<STR_LIT>" ) ; } } catch ( IOException ex ) { log . error ( "<STR_LIT>" , ex ) ; } } } } } } @ Deprecated private void importBinaryDataFromExtFileAnnotations ( String path ) { log . info ( "<STR_LIT>" ) ; String extFilePattern = "<STR_LIT>" ; String selectSql = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; List < String [ ] > list = jdbcTemplate . getJdbcOperations ( ) . query ( selectSql , new ResultSetExtractor < List < String [ ] > > ( ) { @ Override public List < String [ ] > extractData ( ResultSet rs ) throws SQLException , DataAccessException { ArrayList < String [ ] > result = new ArrayList < String [ ] > ( ) ; while ( rs . next ( ) ) { String [ ] tmp = { rs . getString ( "<STR_LIT:value>" ) , rs . getString ( "<STR_LIT>" ) } ; result . add ( tmp ) ; } return result ; } } ) ; for ( String [ ] externalData : list ) { assert externalData . length > <NUM_LIT:1> ; String filename = externalData [ <NUM_LIT:0> ] . replaceFirst ( extFilePattern , "<STR_LIT>" ) ; log . info ( "<STR_LIT>" + filename + "<STR_LIT>" ) ; MediaImportPreparedStatementCallbackImpl preStat = new MediaImportPreparedStatementCallbackImpl ( path + "<STR_LIT>" + filename , Long . parseLong ( externalData [ <NUM_LIT:1> ] ) , mimeTypeMapping ) ; String sqlScript = "<STR_LIT>" ; jdbcTemplate . getJdbcOperations ( ) . execute ( sqlScript , preStat ) ; String updateValueSql = "<STR_LIT>" ; SqlParameterSource updateArgs = makeArgs ( ) . addValue ( "<STR_LIT:id>" , Types . BIGINT ) . addValue ( "<STR_LIT>" , externalData [ <NUM_LIT:0> ] , Types . VARCHAR ) ; jdbcTemplate . update ( updateValueSql , updateArgs ) ; } } private void importSingleFile ( String path , long corpusRef ) { MediaImportPreparedStatementCallbackImpl preStat = new MediaImportPreparedStatementCallbackImpl ( path , corpusRef , mimeTypeMapping ) ; String sqlScript = "<STR_LIT>" ; jdbcTemplate . getJdbcOperations ( ) . execute ( sqlScript , preStat ) ; } void extendStagingText ( long toplevelID ) { log . info ( "<STR_LIT>" ) ; ; executeSqlFromScript ( "<STR_LIT>" , makeArgs ( ) . addValue ( "<STR_LIT>" , toplevelID ) ) ; } void computeLeftTokenRightToken ( ) { log . info ( "<STR_LIT>" ) ; executeSqlFromScript ( "<STR_LIT>" ) ; } void computeRealRoot ( ) { log . info ( "<STR_LIT>" ) ; executeSqlFromScript ( "<STR_LIT>" ) ; } void computeLevel ( ) { log . info ( "<STR_LIT>" ) ; executeSqlFromScript ( "<STR_LIT>" ) ; log . info ( "<STR_LIT>" ) ; executeSqlFromScript ( "<STR_LIT>" ) ; } void computeCorpusStatistics ( String path ) { File f = new File ( path ) ; String absolutePath = path ; try { absolutePath = f . getCanonicalPath ( ) ; } catch ( IOException ex ) { log . error ( "<STR_LIT>" , ex ) ; } log . info ( "<STR_LIT>" ) ; MapSqlParameterSource args = makeArgs ( ) . addValue ( "<STR_LIT>" , absolutePath ) ; executeSqlFromScript ( "<STR_LIT>" , args ) ; } void updateCorpusStatistic ( long corpusID ) { MapSqlParameterSource args = makeArgs ( ) . addValue ( "<STR_LIT>" , corpusID ) ; log . info ( "<STR_LIT>" ) ; executeSqlFromScript ( "<STR_LIT>" , args ) ; } void computeCorpusPath ( long corpusID ) { MapSqlParameterSource args = makeArgs ( ) . addValue ( "<STR_LIT>" , corpusID ) ; log . info ( "<STR_LIT>" + corpusID ) ; executeSqlFromScript ( "<STR_LIT>" , args ) ; } protected void adjustRankPrePost ( ) { log . info ( "<STR_LIT>" ) ; executeSqlFromScript ( "<STR_LIT>" ) ; log . info ( "<STR_LIT>" ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + tableInStagingArea ( "<STR_LIT>" ) ) ; } long updateIds ( ) { log . info ( "<STR_LIT>" ) ; int numOfEntries = jdbcTemplate . getJdbcOperations ( ) . queryForInt ( "<STR_LIT>" ) ; long recentCorpusId = <NUM_LIT:0> ; if ( numOfEntries > <NUM_LIT:0> ) { recentCorpusId = jdbcTemplate . getJdbcOperations ( ) . queryForLong ( "<STR_LIT>" ) ; log . info ( "<STR_LIT>" + recentCorpusId ) ; } MapSqlParameterSource args = makeArgs ( ) . addValue ( "<STR_LIT>" , recentCorpusId ) ; executeSqlFromScript ( "<STR_LIT>" , args ) ; log . info ( "<STR_LIT>" ) ; long result = jdbcTemplate . getJdbcOperations ( ) . queryForLong ( "<STR_LIT>" ) ; log . info ( "<STR_LIT>" + result ) ; return result ; } void updateCorpusStatsId ( long corpusId ) { log . info ( "<STR_LIT>" ) ; jdbcTemplate . getJdbcOperations ( ) . update ( "<STR_LIT>" + corpusId ) ; } void applyConstraints ( ) { log . info ( "<STR_LIT>" ) ; executeSqlFromScript ( "<STR_LIT>" ) ; } void insertCorpus ( ) { log . info ( "<STR_LIT>" ) ; for ( String table : tablesToCopyManually ) { int numOfEntries = jdbcTemplate . getJdbcOperations ( ) . queryForInt ( "<STR_LIT>" + tableInStagingArea ( table ) ) ; if ( numOfEntries > <NUM_LIT:0> ) { StringBuilder sql = new StringBuilder ( ) ; if ( table . equalsIgnoreCase ( FILE_RESOLVER_VIS_MAP ) ) { sql . append ( "<STR_LIT>" ) ; sql . append ( table ) ; sql . append ( "<STR_LIT>" ) ; sql . append ( "<STR_LIT>" ) ; sql . append ( tableInStagingArea ( table ) ) . append ( "<STR_LIT:)>" ) ; } else { sql . append ( "<STR_LIT>" ) ; sql . append ( table ) ; sql . append ( "<STR_LIT>" ) ; sql . append ( tableInStagingArea ( table ) ) . append ( "<STR_LIT:)>" ) ; } jdbcTemplate . getJdbcOperations ( ) . execute ( sql . toString ( ) ) ; } } } void dropStagingArea ( ) { log . info ( "<STR_LIT>" ) ; List < String > tables = importedAndCreatedTables ( ) ; Collections . reverse ( tables ) ; for ( String table : tables ) { jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + tableInStagingArea ( table ) ) ; } } void dropMaterializedTables ( ) { log . info ( "<STR_LIT>" ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" ) ; } void analyzeStagingTables ( ) { for ( String t : importedTables ) { log . info ( "<STR_LIT>" + t ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + tableInStagingArea ( t ) ) ; } } void createAnnotations ( long corpusID ) { MapSqlParameterSource args = makeArgs ( ) . addValue ( "<STR_LIT>" , corpusID ) ; log . info ( "<STR_LIT>" + corpusID ) ; executeSqlFromScript ( "<STR_LIT>" , args ) ; log . info ( "<STR_LIT>" + corpusID ) ; executeSqlFromScript ( "<STR_LIT>" , args ) ; } void analyzeFacts ( long corpusID ) { log . info ( "<STR_LIT>" + corpusID ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + corpusID ) ; log . info ( "<STR_LIT>" ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" ) ; } void createFacts ( long corpusID ) { MapSqlParameterSource args = makeArgs ( ) . addValue ( "<STR_LIT>" , corpusID ) ; log . info ( "<STR_LIT>" + corpusID ) ; executeSqlFromScript ( dbLayout + "<STR_LIT>" , args ) ; clusterFacts ( corpusID ) ; log . info ( "<STR_LIT>" + corpusID + "<STR_LIT:)>" ) ; executeSqlFromScript ( dbLayout + "<STR_LIT>" , args ) ; } void clusterFacts ( long corpusID ) { MapSqlParameterSource args = makeArgs ( ) . addValue ( "<STR_LIT>" , corpusID ) ; log . info ( "<STR_LIT>" + corpusID ) ; if ( ! executeSqlFromScript ( dbLayout + "<STR_LIT>" , args ) ) { executeSqlFromScript ( "<STR_LIT>" , args ) ; } } @ Override public List < Long > listToplevelCorpora ( ) { String sql = "<STR_LIT>" ; return jdbcTemplate . getJdbcOperations ( ) . query ( sql , ParameterizedSingleColumnRowMapper . newInstance ( Long . class ) ) ; } @ Transactional ( readOnly = false ) @ Override public void deleteCorpora ( List < Long > ids ) { for ( long l : ids ) { log . debug ( "<STR_LIT>" + l ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + l ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + l ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + l ) ; log . debug ( "<STR_LIT>" + l ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + l ) ; log . debug ( "<STR_LIT>" + l ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( "<STR_LIT>" + l ) ; } log . debug ( "<STR_LIT>" + ids ) ; executeSqlFromScript ( "<STR_LIT>" , makeArgs ( ) . addValue ( "<STR_LIT>" , StringUtils . join ( ids , "<STR_LIT:U+002CU+0020>" ) ) ) ; } @ Override public List < Map < String , Object > > listCorpusStats ( ) { return jdbcTemplate . getJdbcOperations ( ) . queryForList ( "<STR_LIT>" ) ; } @ Override public List < Map < String , Object > > listTableStats ( ) { return jdbcTemplate . getJdbcOperations ( ) . queryForList ( "<STR_LIT>" ) ; } @ Override public List < String > listUsedIndexes ( ) { log . info ( "<STR_LIT>" ) ; return listIndexDefinitions ( true ) ; } @ Override public List < String > listUnusedIndexes ( ) { log . info ( "<STR_LIT>" ) ; return listIndexDefinitions ( false ) ; } private List < String > importedAndCreatedTables ( ) { List < String > tables = new ArrayList < String > ( ) ; tables . addAll ( Arrays . asList ( importedTables ) ) ; tables . addAll ( Arrays . asList ( createdTables ) ) ; return tables ; } private List < String > allTables ( ) { List < String > tables = new ArrayList < String > ( ) ; tables . addAll ( Arrays . asList ( importedTables ) ) ; tables . addAll ( Arrays . asList ( createdTables ) ) ; return tables ; } private String tableInStagingArea ( String table ) { return "<STR_LIT:_>" + table ; } private MapSqlParameterSource makeArgs ( ) { return new MapSqlParameterSource ( ) ; } private ParameterizedSingleColumnRowMapper < String > stringRowMapper ( ) { return ParameterizedSingleColumnRowMapper . newInstance ( String . class ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private String readSqlFromResource ( Resource resource , MapSqlParameterSource args ) { Map < String , Object > parameters = args != null ? args . getValues ( ) : new HashMap ( ) ; BufferedReader reader = null ; try { StringBuilder sqlBuf = new StringBuilder ( ) ; reader = new BufferedReader ( new InputStreamReader ( new FileInputStream ( resource . getFile ( ) ) , "<STR_LIT:UTF-8>" ) ) ; for ( String line = reader . readLine ( ) ; line != null ; line = reader . readLine ( ) ) { sqlBuf . append ( line ) . append ( "<STR_LIT:n>" ) ; } String sql = sqlBuf . toString ( ) ; for ( Entry < String , Object > placeHolderEntry : parameters . entrySet ( ) ) { String key = placeHolderEntry . getKey ( ) ; String value = placeHolderEntry . getValue ( ) . toString ( ) ; log . debug ( "<STR_LIT>" + key + "<STR_LIT>" + value ) ; sql = sql . replaceAll ( key , value ) ; } return sql ; } catch ( IOException e ) { log . error ( "<STR_LIT>" , e ) ; throw new FileAccessException ( "<STR_LIT>" , e ) ; } finally { if ( reader != null ) { try { reader . close ( ) ; } catch ( IOException ex ) { java . util . logging . Logger . getLogger ( DefaultAdministrationDao . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } } } @ Override public boolean executeSqlFromScript ( String script ) { return executeSqlFromScript ( script , null ) ; } @ Override public boolean executeSqlFromScript ( String script , MapSqlParameterSource args ) { File fScript = new File ( scriptPath , script ) ; if ( fScript . canRead ( ) && fScript . isFile ( ) ) { Resource resource = new FileSystemResource ( fScript ) ; log . debug ( "<STR_LIT>" + resource . getFilename ( ) ) ; String sql = readSqlFromResource ( resource , args ) ; jdbcTemplate . getJdbcOperations ( ) . execute ( sql ) ; return true ; } else { log . debug ( "<STR_LIT>" + fScript . getName ( ) + "<STR_LIT>" ) ; return false ; } } private void bulkloadTableFromResource ( String table , Resource resource ) { log . debug ( "<STR_LIT>" + resource . getFilename ( ) + "<STR_LIT>" + table + "<STR_LIT:'>" ) ; String sql = "<STR_LIT>" + table + "<STR_LIT>" ; try { Connection con = DataSourceUtils . getConnection ( dataSource ) ; PGConnection pgCon = ( PGConnection ) con ; pgCon . getCopyAPI ( ) . copyIn ( sql , resource . getInputStream ( ) ) ; DataSourceUtils . releaseConnection ( con , dataSource ) ; } catch ( SQLException e ) { throw new DatabaseAccessException ( e ) ; } catch ( IOException e ) { throw new FileAccessException ( e ) ; } } private List < String > listIndexesOnTables ( List < String > tables ) { String sql = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; SqlParameterSource args = makeArgs ( ) . addValue ( "<STR_LIT>" , tables ) ; return jdbcTemplate . query ( sql , args , stringRowMapper ( ) ) ; } private List < String > listIndexDefinitions ( boolean used ) { return listIndexDefinitions ( used , allTables ( ) ) ; } public List < String > listIndexDefinitions ( boolean used , List < String > tables ) { String scansOp = used ? "<STR_LIT>" : "<STR_LIT:=>" ; String sql = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + scansOp + "<STR_LIT>" ; SqlParameterSource args = makeArgs ( ) . addValue ( "<STR_LIT>" , listIndexesOnTables ( tables ) ) ; return jdbcTemplate . query ( sql , args , stringRowMapper ( ) ) ; } private List < String > quotedArray ( String ... values ) { List < String > result = new ArrayList < String > ( ) ; for ( String value : values ) { result . add ( "<STR_LIT:'>" + value + "<STR_LIT:'>" ) ; } return result ; } public List < String > listIndexDefinitions ( String ... tables ) { String template = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String sql = template . replaceAll ( "<STR_LIT>" , StringUtils . join ( quotedArray ( tables ) , "<STR_LIT:U+002CU+0020>" ) ) ; return jdbcTemplate . getJdbcOperations ( ) . query ( sql , new ParameterizedSingleColumnRowMapper < String > ( ) ) ; } public List < String > listUsedIndexes ( String ... tables ) { String template = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String sql = template . replaceAll ( "<STR_LIT>" , StringUtils . join ( quotedArray ( tables ) , "<STR_LIT:U+002CU+0020>" ) ) ; return jdbcTemplate . getJdbcOperations ( ) . query ( sql , new ParameterizedSingleColumnRowMapper < String > ( ) ) ; } public boolean resetStatistics ( ) { try { jdbcTemplate . getJdbcOperations ( ) . queryForList ( "<STR_LIT>" ) ; return true ; } catch ( DataAccessException e ) { return false ; } } @ Override public void setDataSource ( DataSource dataSource ) { this . dataSource = dataSource ; jdbcTemplate = new NamedParameterJdbcTemplate ( dataSource ) ; } public NamedParameterJdbcTemplate getJdbcTemplate ( ) { return jdbcTemplate ; } public String getScriptPath ( ) { return scriptPath ; } public void setScriptPath ( String scriptPath ) { this . scriptPath = scriptPath ; } public String getExternalFilesPath ( ) { return externalFilesPath ; } public void setExternalFilesPath ( String externalFilesPath ) { this . externalFilesPath = externalFilesPath ; } public String getDbLayout ( ) { return dbLayout ; } public void setDbLayout ( String dbLayout ) { this . dbLayout = dbLayout ; } public boolean isTemporaryStagingArea ( ) { return temporaryStagingArea ; } public void setTemporaryStagingArea ( boolean temporaryStagingArea ) { this . temporaryStagingArea = temporaryStagingArea ; } public String getSchemaVersion ( ) { return schemaVersion ; } public void setSchemaVersion ( String schemaVersion ) { this . schemaVersion = schemaVersion ; } public Map < String , String > getMimeTypeMapping ( ) { return mimeTypeMapping ; } public void setMimeTypeMapping ( Map < String , String > mimeTypeMapping ) { this . mimeTypeMapping = mimeTypeMapping ; } } </s>
<s> package annis . dao ; import annis . model . QueryAnnotation ; import annis . ql . parser . QueryData ; import annis . sqlgen . SubQueryCorpusSelectionStrategy ; import java . util . List ; import org . springframework . jdbc . core . simple . ParameterizedSingleColumnRowMapper ; import org . springframework . jdbc . core . simple . SimpleJdbcDaoSupport ; public class MetaDataFilter extends SimpleJdbcDaoSupport { private SubQueryCorpusSelectionStrategy subQueryCorpusSelectionStrategy ; public List < Long > getDocumentsForMetadata ( QueryData queryData ) { List < Long > corpusList = queryData . getCorpusList ( ) ; if ( ! corpusList . isEmpty ( ) ) { List < QueryAnnotation > metaData = queryData . getMetaData ( ) ; if ( ! metaData . isEmpty ( ) ) { String documentsWithMetaDataSql = subQueryCorpusSelectionStrategy . buildSubQuery ( corpusList , metaData ) ; List < Long > documents = getSimpleJdbcTemplate ( ) . query ( documentsWithMetaDataSql , ParameterizedSingleColumnRowMapper . newInstance ( Long . class ) ) ; return documents ; } } return null ; } public SubQueryCorpusSelectionStrategy getSubQueryCorpusSelectionStrategy ( ) { return subQueryCorpusSelectionStrategy ; } public void setSubQueryCorpusSelectionStrategy ( SubQueryCorpusSelectionStrategy subQueryCorpusSelectionStrategy ) { this . subQueryCorpusSelectionStrategy = subQueryCorpusSelectionStrategy ; } } </s>
<s> package annis . dao ; import java . util . List ; import org . apache . commons . lang3 . StringUtils ; import org . springframework . jdbc . core . JdbcTemplate ; import org . springframework . jdbc . core . simple . ParameterizedSingleColumnRowMapper ; public class CountExtractor { private String matchedNodesViewName ; public String explain ( JdbcTemplate jdbcTemplate , boolean analyze ) { ParameterizedSingleColumnRowMapper < String > planRowMapper = new ParameterizedSingleColumnRowMapper < String > ( ) ; List < String > plan = jdbcTemplate . query ( ( analyze ? "<STR_LIT>" : "<STR_LIT>" ) + "<STR_LIT:n>" + getCountQuery ( jdbcTemplate ) , planRowMapper ) ; return StringUtils . join ( plan , "<STR_LIT:n>" ) ; } public int queryCount ( JdbcTemplate jdbcTemplate ) { return jdbcTemplate . queryForInt ( getCountQuery ( jdbcTemplate ) ) ; } private String getCountQuery ( JdbcTemplate jdbcTemplate ) { StringBuilder sql = new StringBuilder ( ) ; sql . append ( "<STR_LIT>" ) ; sql . append ( matchedNodesViewName ) ; sql . append ( "<STR_LIT>" ) ; return sql . toString ( ) ; } public String getMatchedNodesViewName ( ) { return matchedNodesViewName ; } public void setMatchedNodesViewName ( String matchedNodesViewName ) { this . matchedNodesViewName = matchedNodesViewName ; } } </s>
<s> package annis . dao ; import java . util . List ; import annis . model . Annotation ; import java . util . LinkedList ; public class AnnotatedSpan { private long id ; private String coveredText ; private List < Annotation > annotations ; private List < Annotation > metadata ; public AnnotatedSpan ( long id , String coveredText , List < Annotation > annotations ) { this ( id , coveredText , annotations , new LinkedList < Annotation > ( ) ) ; } public AnnotatedSpan ( long id , String coveredText , List < Annotation > annotations , List < Annotation > metadata ) { super ( ) ; this . id = id ; this . coveredText = coveredText ; this . annotations = annotations ; this . metadata = metadata ; } public long getId ( ) { return id ; } public void setId ( long id ) { this . id = id ; } public String getCoveredText ( ) { return coveredText ; } public void setCoveredText ( String coveredText ) { this . coveredText = coveredText ; } public List < Annotation > getAnnotations ( ) { return annotations ; } public void setAnnotations ( List < Annotation > annotations ) { this . annotations = annotations ; } public List < Annotation > getMetadata ( ) { return metadata ; } public void setMetadata ( List < Annotation > metadata ) { this . metadata = metadata ; } } </s>
<s> package annis . dao ; import java . sql . ResultSet ; import java . sql . SQLException ; import org . springframework . jdbc . core . simple . ParameterizedRowMapper ; public class DocumentNameMapRow implements ParameterizedRowMapper < String > { @ Override public String mapRow ( ResultSet rs , int rowNum ) throws SQLException { return rs . getString ( "<STR_LIT>" ) ; } } </s>
<s> package annis . dao ; import annis . exceptions . AnnisException ; import annis . service . objects . Match ; import java . util . HashMap ; import java . util . List ; import java . util . Properties ; import annis . model . Annotation ; import annis . ql . parser . QueryData ; import annis . resolver . ResolverEntry ; import annis . resolver . SingleResolverRequest ; import annis . service . objects . AnnisAttribute ; import annis . service . objects . AnnisBinary ; import annis . service . objects . AnnisCorpus ; import annis . sqlgen . SqlGenerator ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . SaltProject ; import java . util . Map ; import org . springframework . jdbc . core . ResultSetExtractor ; public interface AnnisDao { public SaltProject retrieveAnnotationGraph ( long textId ) ; public SaltProject retrieveAnnotationGraph ( String toplevelCorpusName , String documentName ) ; public List < AnnisCorpus > listCorpora ( ) ; public List < AnnisAttribute > listAnnotations ( List < Long > corpusList , boolean listValues , boolean onlyMostFrequentValues ) ; public List < Annotation > listCorpusAnnotations ( String toplevelCorpusName ) ; public List < Annotation > listCorpusAnnotations ( String toplevelCorpusName , String documentName ) ; public AnnisBinary getBinary ( String toplevelCorpusName , String corpusName , int offset , int length ) ; public List < ResolverEntry > getResolverEntries ( SingleResolverRequest request ) ; public QueryData parseAQL ( String aql , List < Long > corpusList ) ; int count ( QueryData queryData ) ; List < Match > find ( QueryData queryData ) ; SaltProject graph ( QueryData queryData ) ; SaltProject annotate ( QueryData queryData ) ; String explain ( SqlGenerator < QueryData , ? > generator , QueryData queryData , final boolean analyze ) ; List < AnnotatedMatch > matrix ( QueryData queryData ) ; public < T > T executeQueryFunction ( QueryData queryData , final SqlGenerator < QueryData , T > generator ) ; public < T > T executeQueryFunction ( QueryData queryData , final SqlGenerator < QueryData , T > generator , final ResultSetExtractor < T > extractor ) ; public HashMap < Long , Properties > getCorpusConfiguration ( ) ; public void setCorpusConfiguration ( HashMap < Long , Properties > corpusConfiguration ) ; void setTimeout ( int milliseconds ) ; int getTimeout ( ) ; public List < String > mapCorpusIdsToNames ( List < Long > ids ) ; public List < Long > mapCorpusNamesToIds ( List < String > corpusNames ) ; public Map < String , String > getCorpusConfiguration ( String corpusName ) ; public boolean checkDatabaseVersion ( ) throws AnnisException ; } </s>
<s> package annis . dao ; import annis . resolver . ResolverEntry ; import annis . resolver . SingleResolverRequest ; import java . sql . Connection ; import java . sql . PreparedStatement ; import java . sql . ResultSet ; import java . sql . SQLException ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . ListIterator ; import java . util . Properties ; import java . util . Set ; import org . springframework . dao . DataAccessException ; import org . springframework . jdbc . core . PreparedStatementCreator ; import org . springframework . jdbc . core . ResultSetExtractor ; public class ResolverDaoHelper implements ResultSetExtractor , PreparedStatementCreator { public ResolverDaoHelper ( ) { } @ Override public PreparedStatement createPreparedStatement ( Connection cnctn ) throws SQLException { String select = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String defaultFromWhere = "<STR_LIT>" ; String firstUnion = select + defaultFromWhere + "<STR_LIT>" + "<STR_LIT>" ; String secondUnion = select + defaultFromWhere + "<STR_LIT>" + "<STR_LIT:?>" + "<STR_LIT>" + "<STR_LIT:?>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:?>" + "<STR_LIT>" + "<STR_LIT:?>" + "<STR_LIT>" ; String thirdUnion = select + defaultFromWhere + "<STR_LIT>" + "<STR_LIT:?>" + "<STR_LIT>" + "<STR_LIT:?>" + "<STR_LIT>" + "<STR_LIT:?>" + "<STR_LIT:n>" ; String fourthUnion = select + defaultFromWhere + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:?>" + "<STR_LIT:n>" ; StringBuilder result = new StringBuilder ( ) ; result . append ( firstUnion ) ; result . append ( "<STR_LIT>" ) ; result . append ( secondUnion ) ; result . append ( "<STR_LIT>" ) ; result . append ( thirdUnion ) ; result . append ( "<STR_LIT>" ) ; result . append ( fourthUnion ) ; result . append ( "<STR_LIT>" ) ; return cnctn . prepareStatement ( result . toString ( ) ) ; } public void fillPreparedStatement ( SingleResolverRequest resolverRequest , PreparedStatement stmt ) throws SQLException { stmt . setString ( <NUM_LIT:1> , resolverRequest . getNamespace ( ) ) ; stmt . setString ( <NUM_LIT:2> , resolverRequest . getType ( ) . name ( ) ) ; stmt . setString ( <NUM_LIT:3> , resolverRequest . getNamespace ( ) ) ; stmt . setString ( <NUM_LIT:4> , resolverRequest . getCorpusName ( ) ) ; stmt . setString ( <NUM_LIT:5> , resolverRequest . getNamespace ( ) ) ; stmt . setString ( <NUM_LIT:6> , resolverRequest . getType ( ) . name ( ) ) ; stmt . setString ( <NUM_LIT:7> , resolverRequest . getCorpusName ( ) ) ; stmt . setString ( <NUM_LIT:8> , resolverRequest . getCorpusName ( ) ) ; } @ Override public List < ResolverEntry > extractData ( ResultSet rs ) throws SQLException , DataAccessException { List < ResolverEntry > result = new LinkedList < ResolverEntry > ( ) ; Set < RemoveIndexElement > removeEntries = new HashSet < RemoveIndexElement > ( ) ; while ( rs . next ( ) ) { Properties mappings = new Properties ( ) ; String mappingsAsString = rs . getString ( "<STR_LIT>" ) ; if ( mappingsAsString != null ) { String [ ] entries = mappingsAsString . split ( "<STR_LIT:;>" ) ; for ( String e : entries ) { String [ ] keyvalue = e . split ( "<STR_LIT::>" , <NUM_LIT:2> ) ; if ( keyvalue . length == <NUM_LIT:2> ) { mappings . put ( keyvalue [ <NUM_LIT:0> ] . trim ( ) , keyvalue [ <NUM_LIT:1> ] . trim ( ) ) ; } } } String element = rs . getString ( "<STR_LIT>" ) ; ResolverEntry e = new ResolverEntry ( rs . getLong ( "<STR_LIT:id>" ) , rs . getString ( "<STR_LIT>" ) , rs . getString ( "<STR_LIT:version>" ) , rs . getString ( "<STR_LIT>" ) , element == null ? null : ResolverEntry . ElementType . valueOf ( element ) , rs . getString ( "<STR_LIT>" ) , rs . getString ( "<STR_LIT>" ) , rs . getString ( "<STR_LIT>" ) , mappings , rs . getInt ( "<STR_LIT>" ) ) ; if ( "<STR_LIT>" . equals ( e . getVisibility ( ) ) ) { RemoveIndexElement r = new RemoveIndexElement ( e ) ; removeEntries . add ( r ) ; } else { result . add ( e ) ; } } ListIterator < ResolverEntry > it = result . listIterator ( ) ; while ( it . hasNext ( ) ) { ResolverEntry entry = it . next ( ) ; RemoveIndexElement idx = new RemoveIndexElement ( entry ) ; if ( removeEntries . contains ( idx ) ) { it . remove ( ) ; } } return result ; } private static class RemoveIndexElement { public String namespace ; public ResolverEntry . ElementType element ; public String vis_type ; public String display_name ; public RemoveIndexElement ( ) { } public RemoveIndexElement ( ResolverEntry e ) { namespace = e . getNamespace ( ) ; element = e . getElement ( ) ; vis_type = e . getVisType ( ) ; display_name = e . getDisplayName ( ) ; } @ Override public int hashCode ( ) { int hash = <NUM_LIT:5> ; hash = <NUM_LIT> * hash + ( this . namespace != null ? this . namespace . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . element != null ? this . element . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . vis_type != null ? this . vis_type . hashCode ( ) : <NUM_LIT:0> ) ; hash = <NUM_LIT> * hash + ( this . display_name != null ? this . display_name . hashCode ( ) : <NUM_LIT:0> ) ; return hash ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final RemoveIndexElement other = ( RemoveIndexElement ) obj ; if ( ( this . namespace == null ) ? ( other . namespace != null ) : ! this . namespace . equals ( other . namespace ) ) { return false ; } if ( this . element != other . element ) { return false ; } if ( ( this . vis_type == null ) ? ( other . vis_type != null ) : ! this . vis_type . equals ( other . vis_type ) ) { return false ; } if ( ( this . display_name == null ) ? ( other . display_name != null ) : ! this . display_name . equals ( other . display_name ) ) { return false ; } return true ; } } } </s>
<s> package annis . dao ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class AnnotatedMatch extends ArrayList < AnnotatedSpan > { public AnnotatedMatch ( ) { super ( ) ; } public AnnotatedMatch ( List < AnnotatedSpan > spans ) { this ( ) ; addAll ( spans ) ; } public AnnotatedMatch ( AnnotatedSpan ... spans ) { this ( Arrays . asList ( spans ) ) ; } } </s>
<s> package annis . dao ; import java . util . ArrayList ; import java . util . List ; import org . apache . commons . lang3 . StringUtils ; import org . apache . commons . lang3 . Validate ; import org . springframework . jdbc . core . simple . ParameterizedSingleColumnRowMapper ; import static annis . sqlgen . SqlConstraints . sqlString ; public class ListCorpusByNameDaoHelper extends ParameterizedSingleColumnRowMapper < Long > { public String createSql ( List < String > corpusNames ) { Validate . notEmpty ( corpusNames , "<STR_LIT>" ) ; List < String > corpusNamesSqlStrings = new ArrayList < String > ( ) ; for ( String corpus : corpusNames ) { corpusNamesSqlStrings . add ( sqlString ( corpus ) ) ; } StringBuilder sb = new StringBuilder ( ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( StringUtils . join ( corpusNamesSqlStrings , "<STR_LIT:U+002CU+0020>" ) ) ; sb . append ( "<STR_LIT>" ) ; return sb . toString ( ) ; } } </s>
<s> package annis . dao ; import org . springframework . jdbc . core . JdbcTemplate ; import annis . ql . parser . QueryData ; public interface SqlSessionModifier { void modifySqlSession ( JdbcTemplate simpleJdbcTemplate , QueryData queryData ) ; } </s>
<s> package annis . dao ; import annis . exceptions . AnnisException ; import annis . service . objects . Match ; import java . io . File ; import java . io . IOException ; import java . io . UnsupportedEncodingException ; import java . security . NoSuchAlgorithmException ; import java . sql . PreparedStatement ; import java . sql . ResultSet ; import java . sql . SQLException ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . Properties ; import java . util . TreeMap ; import org . springframework . dao . DataAccessException ; import org . springframework . jdbc . core . JdbcTemplate ; import org . springframework . jdbc . core . simple . ParameterizedSingleColumnRowMapper ; import org . springframework . jdbc . core . simple . SimpleJdbcDaoSupport ; import org . springframework . transaction . annotation . Transactional ; import annis . model . Annotation ; import annis . ql . node . Start ; import annis . ql . parser . AnnisParser ; import annis . ql . parser . QueryAnalysis ; import annis . ql . parser . QueryData ; import annis . resolver . ResolverEntry ; import annis . resolver . SingleResolverRequest ; import annis . service . objects . AnnisBinary ; import annis . service . objects . AnnisAttribute ; import annis . service . objects . AnnisCorpus ; import annis . sqlgen . AnnotateSqlGenerator ; import annis . sqlgen . ByteHelper ; import annis . sqlgen . CountSqlGenerator ; import annis . sqlgen . FindSqlGenerator ; import annis . sqlgen . ListAnnotationsSqlHelper ; import annis . sqlgen . ListCorpusAnnotationsSqlHelper ; import annis . sqlgen . ListCorpusSqlHelper ; import annis . sqlgen . MatrixSqlGenerator ; import annis . sqlgen . SaltAnnotateExtractor ; import annis . sqlgen . SqlGenerator ; import annis . utils . Utils ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . SaltProject ; import java . io . FileInputStream ; import java . sql . Connection ; import java . sql . DatabaseMetaData ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import org . springframework . jdbc . core . ResultSetExtractor ; public class SpringAnnisDao extends SimpleJdbcDaoSupport implements AnnisDao , SqlSessionModifier { private FindSqlGenerator findSqlGenerator ; private CountSqlGenerator countSqlGenerator ; private AnnotateSqlGenerator < SaltProject > annotateSqlGenerator ; private SaltAnnotateExtractor saltAnnotateExtractor ; private MatrixSqlGenerator matrixSqlGenerator ; private AnnotateSqlGenerator < SaltProject > graphSqlGenerator ; private int timeout ; private Map < Long , String > corpusNamesById ; @ Override @ Transactional public SaltProject graph ( QueryData data ) { return executeQueryFunction ( data , graphSqlGenerator , saltAnnotateExtractor ) ; } public AnnotateSqlGenerator getGraphSqlGenerator ( ) { return graphSqlGenerator ; } public void setGraphSqlGenerator ( AnnotateSqlGenerator graphSqlGenerator ) { this . graphSqlGenerator = graphSqlGenerator ; } private static final class ExplainSqlGenerator implements SqlGenerator < QueryData , String > { private final boolean analyze ; private final SqlGenerator < QueryData , ? > generator ; private ExplainSqlGenerator ( SqlGenerator < QueryData , ? > generator , boolean analyze ) { this . generator = generator ; this . analyze = analyze ; } @ Override public String toSql ( QueryData queryData ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "<STR_LIT>" ) ; if ( analyze ) { sb . append ( "<STR_LIT>" ) ; } sb . append ( generator . toSql ( queryData ) ) ; return sb . toString ( ) ; } @ Override public String extractData ( ResultSet rs ) throws SQLException , DataAccessException { StringBuilder sb = new StringBuilder ( ) ; while ( rs . next ( ) ) { sb . append ( rs . getString ( <NUM_LIT:1> ) ) ; sb . append ( "<STR_LIT:n>" ) ; } return sb . toString ( ) ; } @ Override public String toSql ( QueryData queryData , String indent ) { return toSql ( queryData ) ; } } private static final Logger log = LoggerFactory . getLogger ( SpringAnnisDao . class ) ; private SqlGenerator sqlGenerator ; private ListCorpusSqlHelper listCorpusSqlHelper ; private ListAnnotationsSqlHelper listAnnotationsSqlHelper ; private ListCorpusAnnotationsSqlHelper listCorpusAnnotationsSqlHelper ; private List < SqlSessionModifier > sqlSessionModifiers ; private CountExtractor countExtractor ; private ParameterizedSingleColumnRowMapper < String > planRowMapper ; private ListCorpusByNameDaoHelper listCorpusByNameDaoHelper ; private AnnotateSqlGenerator graphExtractor ; private MetaDataFilter metaDataFilter ; private QueryAnalysis queryAnalysis ; private AnnisParser aqlParser ; private HashMap < Long , Properties > corpusConfiguration ; private ByteHelper byteHelper ; public SpringAnnisDao ( ) { planRowMapper = new ParameterizedSingleColumnRowMapper < String > ( ) ; sqlSessionModifiers = new ArrayList < SqlSessionModifier > ( ) ; } public void init ( ) { parseCorpusConfiguration ( ) ; } @ Override public < T > T executeQueryFunction ( QueryData queryData , final SqlGenerator < QueryData , T > generator ) { return executeQueryFunction ( queryData , generator , generator ) ; } @ Override public List < String > mapCorpusIdsToNames ( List < Long > ids ) { List < String > names = new ArrayList < String > ( ) ; if ( corpusNamesById == null ) { corpusNamesById = new TreeMap < Long , String > ( ) ; List < AnnisCorpus > corpora = listCorpora ( ) ; for ( AnnisCorpus corpus : corpora ) { corpusNamesById . put ( corpus . getId ( ) , corpus . getName ( ) ) ; } } for ( Long id : ids ) { names . add ( corpusNamesById . get ( id ) ) ; } return names ; } @ Transactional @ Override public < T > T executeQueryFunction ( QueryData queryData , final SqlGenerator < QueryData , T > generator , final ResultSetExtractor < T > extractor ) { JdbcTemplate jdbcTemplate = getJdbcTemplate ( ) ; queryData . setCorpusConfiguration ( corpusConfiguration ) ; queryData . setDocuments ( metaDataFilter . getDocumentsForMetadata ( queryData ) ) ; for ( SqlSessionModifier sqlSessionModifier : sqlSessionModifiers ) { sqlSessionModifier . modifySqlSession ( jdbcTemplate , queryData ) ; } return jdbcTemplate . query ( generator . toSql ( queryData ) , extractor ) ; } @ Override public void modifySqlSession ( JdbcTemplate jdbcTemplate , QueryData queryData ) { if ( timeout > <NUM_LIT:0> ) { jdbcTemplate . update ( "<STR_LIT>" + timeout ) ; } } @ Transactional ( readOnly = true ) @ Override public List < Match > find ( QueryData queryData ) { return executeQueryFunction ( queryData , findSqlGenerator ) ; } @ Transactional ( readOnly = true ) @ Override public int count ( QueryData queryData ) { return executeQueryFunction ( queryData , countSqlGenerator ) ; } @ Override @ Transactional ( readOnly = true ) public SaltProject annotate ( QueryData queryData ) { return executeQueryFunction ( queryData , annotateSqlGenerator , saltAnnotateExtractor ) ; } @ Transactional ( readOnly = true ) @ Override public List < AnnotatedMatch > matrix ( QueryData queryData ) { return executeQueryFunction ( queryData , matrixSqlGenerator ) ; } @ Override @ Transactional ( readOnly = true ) public String explain ( SqlGenerator < QueryData , ? > generator , QueryData queryData , final boolean analyze ) { return executeQueryFunction ( queryData , new ExplainSqlGenerator ( generator , analyze ) ) ; } @ Override public QueryData parseAQL ( String aql , List < Long > corpusList ) { Start statement = aqlParser . parse ( aql ) ; return queryAnalysis . analyzeQuery ( statement , corpusList ) ; } @ Override @ Transactional ( readOnly = true ) public List < AnnisCorpus > listCorpora ( ) { return ( List < AnnisCorpus > ) getJdbcTemplate ( ) . query ( listCorpusSqlHelper . createSqlQuery ( ) , listCorpusSqlHelper ) ; } @ Override @ Transactional ( readOnly = true ) public List < AnnisAttribute > listAnnotations ( List < Long > corpusList , boolean listValues , boolean onlyMostFrequentValues ) { return ( List < AnnisAttribute > ) getJdbcTemplate ( ) . query ( listAnnotationsSqlHelper . createSqlQuery ( corpusList , listValues , onlyMostFrequentValues ) , listAnnotationsSqlHelper ) ; } @ Override @ Transactional ( readOnly = true ) public SaltProject retrieveAnnotationGraph ( long textId ) { SaltProject p = annotateSqlGenerator . queryAnnotationGraph ( getJdbcTemplate ( ) , textId ) ; return p ; } @ Override @ Transactional ( readOnly = true ) public SaltProject retrieveAnnotationGraph ( String toplevelCorpusName , String documentName ) { SaltProject p = annotateSqlGenerator . queryAnnotationGraph ( getJdbcTemplate ( ) , toplevelCorpusName , documentName ) ; return p ; } @ Override @ Transactional ( readOnly = true ) public List < Annotation > listCorpusAnnotations ( String toplevelCorpusName ) { final String sql = listCorpusAnnotationsSqlHelper . createSqlQuery ( toplevelCorpusName , toplevelCorpusName ) ; final List < Annotation > corpusAnnotations = ( List < Annotation > ) getJdbcTemplate ( ) . query ( sql , listCorpusAnnotationsSqlHelper ) ; return corpusAnnotations ; } @ Override @ Transactional ( readOnly = true ) public List < Annotation > listCorpusAnnotations ( String toplevelCorpusName , String documentName ) { final String sql = listCorpusAnnotationsSqlHelper . createSqlQuery ( toplevelCorpusName , documentName ) ; final List < Annotation > corpusAnnotations = ( List < Annotation > ) getJdbcTemplate ( ) . query ( sql , listCorpusAnnotationsSqlHelper ) ; return corpusAnnotations ; } @ Override @ Transactional ( readOnly = true ) public List < Long > mapCorpusNamesToIds ( List < String > corpusNames ) { final String sql = listCorpusByNameDaoHelper . createSql ( corpusNames ) ; final List < Long > result = getJdbcTemplate ( ) . query ( sql , listCorpusByNameDaoHelper ) ; return result ; } @ Override @ Transactional ( readOnly = true ) public List < ResolverEntry > getResolverEntries ( SingleResolverRequest request ) { try { ResolverDaoHelper helper = new ResolverDaoHelper ( ) ; PreparedStatement stmt = helper . createPreparedStatement ( getConnection ( ) ) ; helper . fillPreparedStatement ( request , stmt ) ; List < ResolverEntry > result = helper . extractData ( stmt . executeQuery ( ) ) ; return result ; } catch ( SQLException ex ) { log . error ( "<STR_LIT>" , ex ) ; return new LinkedList < ResolverEntry > ( ) ; } } @ Override public Map < String , String > getCorpusConfiguration ( String corpusName ) { Map < String , String > result = new TreeMap < String , String > ( ) ; if ( System . getProperty ( "<STR_LIT>" ) != null ) { File confFolder = new File ( System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ) ; if ( confFolder . isDirectory ( ) ) { File conf = null ; try { conf = new File ( confFolder , Utils . calculateSHAHash ( corpusName ) ) ; } catch ( NoSuchAlgorithmException ex ) { log . warn ( null , ex ) ; } catch ( UnsupportedEncodingException ex ) { log . warn ( null , ex ) ; } if ( conf == null || ! conf . isFile ( ) ) { conf = new File ( confFolder , corpusName + "<STR_LIT>" ) ; } if ( conf . isFile ( ) ) { Properties p = new Properties ( ) ; FileInputStream confStream = null ; try { confStream = new FileInputStream ( conf ) ; p . load ( confStream ) ; for ( Map . Entry < Object , Object > e : p . entrySet ( ) ) { result . put ( e . getKey ( ) . toString ( ) , e . getValue ( ) . toString ( ) ) ; } } catch ( IOException ex ) { log . warn ( "<STR_LIT>" + conf . getAbsolutePath ( ) , ex ) ; } finally { if ( confStream != null ) { try { confStream . close ( ) ; } catch ( IOException ex ) { log . warn ( null , ex ) ; } } } } } } return result ; } private void parseCorpusConfiguration ( ) { corpusConfiguration = new HashMap < Long , Properties > ( ) ; try { List < AnnisCorpus > corpora = listCorpora ( ) ; for ( AnnisCorpus c : corpora ) { Properties p = new Properties ( ) ; Map < String , String > map = getCorpusConfiguration ( c . getName ( ) ) ; for ( Map . Entry < String , String > e : map . entrySet ( ) ) { p . setProperty ( e . getKey ( ) , e . getValue ( ) ) ; } corpusConfiguration . put ( c . getId ( ) , p ) ; } } catch ( org . springframework . jdbc . CannotGetJdbcConnectionException ex ) { log . warn ( "<STR_LIT>" ) ; } } @ Override public boolean checkDatabaseVersion ( ) throws AnnisException { Connection conn = null ; try { conn = getJdbcTemplate ( ) . getDataSource ( ) . getConnection ( ) ; DatabaseMetaData meta = conn . getMetaData ( ) ; log . info ( "<STR_LIT>" + meta . getDatabaseMajorVersion ( ) + "<STR_LIT>" + meta . getDatabaseMinorVersion ( ) + "<STR_LIT>" + meta . getDatabaseProductVersion ( ) + "<STR_LIT>" + meta . getDatabaseProductName ( ) ) ; } catch ( SQLException ex ) { log . error ( "<STR_LIT>" , ex ) ; } finally { if ( conn != null ) { try { conn . close ( ) ; } catch ( SQLException ex ) { log . error ( null , ex ) ; } } } return false ; } public AnnisParser getAqlParser ( ) { return aqlParser ; } public void setAqlParser ( AnnisParser aqlParser ) { this . aqlParser = aqlParser ; } public SqlGenerator getSqlGenerator ( ) { return sqlGenerator ; } public void setSqlGenerator ( SqlGenerator sqlGenerator ) { this . sqlGenerator = sqlGenerator ; } public ParameterizedSingleColumnRowMapper < String > getPlanRowMapper ( ) { return planRowMapper ; } public void setPlanRowMapper ( ParameterizedSingleColumnRowMapper < String > planRowMapper ) { this . planRowMapper = planRowMapper ; } public ListCorpusSqlHelper getListCorpusSqlHelper ( ) { return listCorpusSqlHelper ; } public void setListCorpusSqlHelper ( ListCorpusSqlHelper listCorpusHelper ) { this . listCorpusSqlHelper = listCorpusHelper ; } public ListAnnotationsSqlHelper getListAnnotationsSqlHelper ( ) { return listAnnotationsSqlHelper ; } public void setListAnnotationsSqlHelper ( ListAnnotationsSqlHelper listNodeAnnotationsSqlHelper ) { this . listAnnotationsSqlHelper = listNodeAnnotationsSqlHelper ; } public ListCorpusAnnotationsSqlHelper getListCorpusAnnotationsSqlHelper ( ) { return listCorpusAnnotationsSqlHelper ; } public void setListCorpusAnnotationsSqlHelper ( ListCorpusAnnotationsSqlHelper listCorpusAnnotationsHelper ) { this . listCorpusAnnotationsSqlHelper = listCorpusAnnotationsHelper ; } public List < SqlSessionModifier > getSqlSessionModifiers ( ) { return sqlSessionModifiers ; } public void setSqlSessionModifiers ( List < SqlSessionModifier > sqlSessionModifiers ) { this . sqlSessionModifiers = sqlSessionModifiers ; } public FindSqlGenerator getFindSqlGenerator ( ) { return findSqlGenerator ; } public void setFindSqlGenerator ( FindSqlGenerator findSqlGenerator ) { this . findSqlGenerator = findSqlGenerator ; } public QueryAnalysis getQueryAnalysis ( ) { return queryAnalysis ; } public void setQueryAnalysis ( QueryAnalysis queryAnalysis ) { this . queryAnalysis = queryAnalysis ; } public ListCorpusByNameDaoHelper getListCorpusByNameDaoHelper ( ) { return listCorpusByNameDaoHelper ; } public void setListCorpusByNameDaoHelper ( ListCorpusByNameDaoHelper listCorpusByNameDaoHelper ) { this . listCorpusByNameDaoHelper = listCorpusByNameDaoHelper ; } public CountExtractor getCountExtractor ( ) { return countExtractor ; } public void setCountExtractor ( CountExtractor countExtractor ) { this . countExtractor = countExtractor ; } public AnnotateSqlGenerator getGraphExtractor ( ) { return graphExtractor ; } public void setGraphExtractor ( AnnotateSqlGenerator graphExtractor ) { this . graphExtractor = graphExtractor ; } public MetaDataFilter getMetaDataFilter ( ) { return metaDataFilter ; } public void setMetaDataFilter ( MetaDataFilter metaDataFilter ) { this . metaDataFilter = metaDataFilter ; } public CountSqlGenerator getCountSqlGenerator ( ) { return countSqlGenerator ; } public void setCountSqlGenerator ( CountSqlGenerator countSqlGenerator ) { this . countSqlGenerator = countSqlGenerator ; } @ Override public HashMap < Long , Properties > getCorpusConfiguration ( ) { return corpusConfiguration ; } @ Override public void setCorpusConfiguration ( HashMap < Long , Properties > corpusConfiguration ) { this . corpusConfiguration = corpusConfiguration ; } @ Override public int getTimeout ( ) { return timeout ; } @ Override public void setTimeout ( int timeout ) { this . timeout = timeout ; } public MatrixSqlGenerator getMatrixSqlGenerator ( ) { return matrixSqlGenerator ; } public void setMatrixSqlGenerator ( MatrixSqlGenerator matrixSqlGenerator ) { this . matrixSqlGenerator = matrixSqlGenerator ; } public SaltAnnotateExtractor getSaltAnnotateExtractor ( ) { return saltAnnotateExtractor ; } public void setSaltAnnotateExtractor ( SaltAnnotateExtractor saltAnnotateExtractor ) { this . saltAnnotateExtractor = saltAnnotateExtractor ; } public ByteHelper getByteHelper ( ) { return byteHelper ; } public void setByteHelper ( ByteHelper byteHelper ) { this . byteHelper = byteHelper ; } @ Override public AnnisBinary getBinary ( String toplevelCorpusName , String corpusName , int offset , int length ) { return ( AnnisBinary ) getJdbcTemplate ( ) . query ( ByteHelper . SQL , byteHelper . getArgs ( toplevelCorpusName , corpusName , offset , length ) , ByteHelper . getArgTypes ( ) , byteHelper ) ; } public AnnotateSqlGenerator < SaltProject > getAnnotateSqlGenerator ( ) { return annotateSqlGenerator ; } public void setAnnotateSqlGenerator ( AnnotateSqlGenerator < SaltProject > annotateSqlGenerator ) { this . annotateSqlGenerator = annotateSqlGenerator ; } } </s>
<s> package annis . dao ; import java . sql . ResultSet ; @ Deprecated public interface ResultSetConverter < T > { public T convertResultSet ( ResultSet resultSet ) ; } </s>
<s> package annis . dao ; import annis . administration . AdministrationDao ; import org . springframework . jdbc . core . JdbcTemplate ; import annis . ql . parser . QueryData ; public class ScriptFileSqlSessionModifier implements SqlSessionModifier { private String scriptFile ; private AdministrationDao administrationDao ; public void modifySqlSession ( JdbcTemplate jdbcTemplate , QueryData queryData ) { administrationDao . executeSqlFromScript ( scriptFile ) ; } public String getScriptFile ( ) { return scriptFile ; } public void setScriptFile ( String scriptFile ) { this . scriptFile = scriptFile ; } public AdministrationDao getAdministrationDao ( ) { return administrationDao ; } public void setAdministrationDao ( AdministrationDao administrationDao ) { this . administrationDao = administrationDao ; } } </s>
<s> package annis . dao ; import org . springframework . jdbc . core . JdbcTemplate ; import annis . ql . parser . QueryData ; public class TimeOutSqlSessionModifier implements SqlSessionModifier { private int timeout ; public void modifySqlSession ( JdbcTemplate jdbcTemplate , QueryData queryData ) { if ( timeout > <NUM_LIT:0> ) jdbcTemplate . update ( "<STR_LIT>" + timeout ) ; } public int getTimeout ( ) { return timeout ; } public void setTimeout ( int timeout ) { this . timeout = timeout ; } } </s>
<s> package annis . dao ; import java . util . List ; import annis . model . Annotation ; import annis . sqlgen . NodeSqlAdapter ; public interface CorpusSelectionStrategy { boolean usesViews ( ) ; void registerNodeAdapter ( NodeSqlAdapter adapter ) ; String createViewSql ( ) ; String whereClauseForNode ( String docRefColumn ) ; String viewName ( String table ) ; void addMetaAnnotations ( List < Annotation > annotations ) ; } </s>
<s> package annis ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class MemoryUsage { private static final Logger log = LoggerFactory . getLogger ( MemoryUsage . class ) ; public static void logMemoryUsage ( ) { Runtime runtime = Runtime . getRuntime ( ) ; String total = String . valueOf ( runtime . totalMemory ( ) / <NUM_LIT> ) + "<STR_LIT>" ; String free = String . valueOf ( runtime . freeMemory ( ) / <NUM_LIT> ) + "<STR_LIT>" ; String max = String . valueOf ( runtime . maxMemory ( ) / <NUM_LIT> ) + "<STR_LIT>" ; log . debug ( "<STR_LIT>" + total + "<STR_LIT>" + free + "<STR_LIT>" + max ) ; } } </s>
<s> package annis ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Date ; import java . util . LinkedList ; import java . util . Set ; import org . apache . commons . lang3 . StringUtils ; import org . apache . commons . lang3 . Validate ; import annis . dao . AnnisDao ; import annis . dao . AnnotatedMatch ; import annis . service . objects . Match ; import annis . dao . MetaDataFilter ; import annis . model . Annotation ; import annis . model . QueryAnnotation ; import annis . model . QueryNode ; import annis . ql . parser . AnnisParser ; import annis . ql . parser . QueryAnalysis ; import annis . ql . parser . QueryData ; import annis . service . objects . AnnisAttribute ; import annis . service . objects . AnnisCorpus ; import annis . sqlgen . * ; import annis . sqlgen . AnnotateQueryData ; import annis . sqlgen . AnnotateSqlGenerator ; import annis . sqlgen . LimitOffsetQueryData ; import annis . sqlgen . SqlGenerator ; import annis . utils . Utils ; import au . com . bytecode . opencsv . CSVWriter ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . SaltProject ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SCorpusGraph ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SDocument ; import java . io . * ; import java . net . URISyntaxException ; import java . util . List ; import java . util . TreeSet ; import javax . xml . bind . JAXBContext ; import javax . xml . bind . JAXBException ; import org . apache . commons . io . output . FileWriterWithEncoding ; import org . codehaus . jackson . map . AnnotationIntrospector ; import org . codehaus . jackson . map . DeserializationConfig ; import org . codehaus . jackson . map . ObjectMapper ; import org . codehaus . jackson . map . SerializationConfig ; import org . codehaus . jackson . xc . JaxbAnnotationIntrospector ; import org . eclipse . emf . common . util . URI ; import org . eclipse . emf . ecore . resource . Resource ; import org . eclipse . emf . ecore . xmi . impl . XMIResourceImpl ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class AnnisRunner extends AnnisBaseRunner { private static final Logger log = LoggerFactory . getLogger ( AnnisRunner . class ) ; private SqlGenerator < QueryData , List < Match > > findSqlGenerator ; private SqlGenerator < QueryData , Integer > countSqlGenerator ; private AnnotateSqlGenerator < SaltProject > annotateSqlGenerator ; private SqlGenerator < QueryData , List < AnnotatedMatch > > matrixSqlGenerator ; private AnnotateSqlGenerator graphSqlGenerator ; private AnnisDao annisDao ; private AnnisParser annisParser ; private QueryAnalysis aqlAnalysis ; private int context ; private int matchLimit ; private QueryAnalysis queryAnalysis ; private int limit = <NUM_LIT:10> ; private int offset ; private int left = <NUM_LIT:5> ; private int right = <NUM_LIT:5> ; private String segmentationLayer = null ; private List < Long > corpusList ; private boolean clearCaches ; private MetaDataFilter metaDataFilter ; public AnnotateSqlGenerator getGraphSqlGenerator ( ) { return graphSqlGenerator ; } public void setGraphSqlGenerator ( AnnotateSqlGenerator graphSqlGenerator ) { this . graphSqlGenerator = graphSqlGenerator ; } public enum OS { linux , other } private static class Benchmark { private String functionCall ; private QueryData queryData ; private long avgTimeInMilliseconds ; private long bestTimeInMilliseconds ; private long worstTimeInMilliseconds ; private String sql ; private String plan ; private int runs ; private int errors ; public Benchmark ( String functionCall , QueryData queryData ) { super ( ) ; this . functionCall = functionCall ; this . queryData = queryData ; } } private List < AnnisRunner . Benchmark > benchmarks ; private static final int SEQUENTIAL_RUNS = <NUM_LIT:5> ; public static void main ( String [ ] args ) { String path = Utils . getAnnisFile ( "<STR_LIT>" ) . getAbsolutePath ( ) ; AnnisBaseRunner . getInstance ( "<STR_LIT>" , "<STR_LIT>" + path ) . run ( args ) ; } public AnnisRunner ( ) { corpusList = new LinkedList < Long > ( ) ; benchmarks = new ArrayList < AnnisRunner . Benchmark > ( ) ; } public void doDebug ( String ignore ) { doDoc ( "<STR_LIT>" ) ; } public void doParse ( String annisQuery ) { out . println ( annisParser . dumpTree ( annisQuery ) ) ; } public void doSql ( String funcCall ) { String doSqlFunctionName = "<STR_LIT>" + funcCall . split ( "<STR_LIT>" , <NUM_LIT:2> ) [ <NUM_LIT:0> ] ; SqlGenerator < QueryData , ? > gen = getGeneratorForQueryFunction ( funcCall ) ; String annisQuery = getAnnisQueryFromFunctionCall ( funcCall ) ; QueryData queryData = analyzeQuery ( annisQuery , doSqlFunctionName ) ; out . println ( "<STR_LIT>" + left + "<STR_LIT>" + right + "<STR_LIT>" + limit + "<STR_LIT>" + offset ) ; out . println ( gen . toSql ( queryData ) ) ; } public void doExplain ( String functionCall , boolean analyze ) { SqlGenerator < QueryData , ? > generator = getGeneratorForQueryFunction ( functionCall ) ; String function = getAnnisQueryFromFunctionCall ( functionCall ) ; String annisQuery = getAnnisQueryFromFunctionCall ( functionCall ) ; QueryData queryData = analyzeQuery ( annisQuery , function ) ; out . println ( "<STR_LIT>" + left + "<STR_LIT>" + right + "<STR_LIT>" + limit + "<STR_LIT>" + offset ) ; out . println ( annisDao . explain ( generator , queryData , analyze ) ) ; } public void doPlan ( String functionCall ) { doExplain ( functionCall , false ) ; } public void doAnalyze ( String functionCall ) { doExplain ( functionCall , true ) ; } private SqlGenerator < QueryData , ? > getGeneratorForQueryFunction ( String funcCall ) { String [ ] split = funcCall . split ( "<STR_LIT:U+0020>" , <NUM_LIT:2> ) ; Validate . isTrue ( split . length == <NUM_LIT:2> , "<STR_LIT>" ) ; String function = split [ <NUM_LIT:0> ] ; SqlGenerator < QueryData , ? > generator = null ; if ( "<STR_LIT:count>" . equals ( function ) ) { generator = countSqlGenerator ; } else if ( "<STR_LIT>" . equals ( function ) ) { generator = findSqlGenerator ; } else if ( "<STR_LIT>" . equals ( function ) ) { generator = annotateSqlGenerator ; } else if ( "<STR_LIT>" . equals ( function ) ) { generator = matrixSqlGenerator ; } else if ( "<STR_LIT>" . equals ( function ) ) { generator = getGraphSqlGenerator ( ) ; } Validate . notNull ( generator , "<STR_LIT>" + function ) ; return generator ; } private String getAnnisQueryFromFunctionCall ( String functionCall ) { String [ ] split = functionCall . split ( "<STR_LIT:U+0020>" , <NUM_LIT:2> ) ; Validate . isTrue ( split . length == <NUM_LIT:2> , "<STR_LIT>" ) ; return split [ <NUM_LIT:1> ] ; } public void doRecord ( String dummy ) { out . println ( "<STR_LIT>" ) ; benchmarks . clear ( ) ; } public void doBenchmark ( String benchmarkCount ) { int count = Integer . parseInt ( benchmarkCount ) ; out . println ( "<STR_LIT>" + benchmarks . size ( ) + "<STR_LIT>" + count + "<STR_LIT>" ) ; AnnisRunner . OS currentOS = AnnisRunner . OS . other ; try { currentOS = AnnisRunner . OS . valueOf ( System . getProperty ( "<STR_LIT>" ) . toLowerCase ( ) ) ; } catch ( IllegalArgumentException ex ) { } List < AnnisRunner . Benchmark > session = new ArrayList < AnnisRunner . Benchmark > ( ) ; for ( AnnisRunner . Benchmark benchmark : benchmarks ) { if ( clearCaches ) { resetCaches ( currentOS ) ; } SqlGenerator < QueryData , ? > generator = getGeneratorForQueryFunction ( benchmark . functionCall ) ; benchmark . sql = getGeneratorForQueryFunction ( benchmark . functionCall ) . toSql ( benchmark . queryData ) ; out . println ( "<STR_LIT>" + benchmark . functionCall ) ; out . println ( benchmark . sql ) ; try { benchmark . plan = annisDao . explain ( generator , benchmark . queryData , false ) ; out . println ( "<STR_LIT>" + benchmark . functionCall ) ; out . println ( benchmark . plan ) ; } catch ( RuntimeException e ) { out . println ( "<STR_LIT>" + benchmark . functionCall ) ; } benchmark . bestTimeInMilliseconds = Long . MAX_VALUE ; benchmark . worstTimeInMilliseconds = Long . MIN_VALUE ; out . println ( "<STR_LIT>" + SEQUENTIAL_RUNS + "<STR_LIT>" ) ; String options = benchmarkOptions ( benchmark . queryData ) ; for ( int i = <NUM_LIT:0> ; i < SEQUENTIAL_RUNS ; ++ i ) { if ( i > <NUM_LIT:0> ) { out . print ( "<STR_LIT:U+002CU+0020>" ) ; } long start = new Date ( ) . getTime ( ) ; try { annisDao . executeQueryFunction ( benchmark . queryData , generator ) ; } catch ( RuntimeException e ) { } long end = new Date ( ) . getTime ( ) ; long runtime = end - start ; benchmark . bestTimeInMilliseconds = Math . min ( benchmark . bestTimeInMilliseconds , runtime ) ; benchmark . worstTimeInMilliseconds = Math . max ( benchmark . worstTimeInMilliseconds , runtime ) ; out . print ( runtime + "<STR_LIT>" ) ; } out . println ( ) ; out . println ( benchmark . bestTimeInMilliseconds + "<STR_LIT>" + benchmark . functionCall + ( "<STR_LIT>" . equals ( options ) ? "<STR_LIT:'>" : "<STR_LIT>" + options ) ) ; session . addAll ( Collections . nCopies ( count , benchmark ) ) ; } if ( clearCaches ) { resetCaches ( currentOS ) ; } Collections . shuffle ( session ) ; out . println ( ) ; out . println ( "<STR_LIT>" ) ; for ( AnnisRunner . Benchmark benchmark : session ) { if ( benchmark . errors >= <NUM_LIT:3> ) { continue ; } boolean error = false ; SqlGenerator < QueryData , ? > generator = getGeneratorForQueryFunction ( benchmark . functionCall ) ; long start = new Date ( ) . getTime ( ) ; try { annisDao . executeQueryFunction ( benchmark . queryData , generator ) ; } catch ( RuntimeException e ) { error = true ; } long end = new Date ( ) . getTime ( ) ; long runtime = end - start ; benchmark . avgTimeInMilliseconds += runtime ; ++ benchmark . runs ; if ( error ) { ++ benchmark . errors ; } String options = benchmarkOptions ( benchmark . queryData ) ; out . println ( runtime + "<STR_LIT>" + benchmark . functionCall + ( "<STR_LIT>" . equals ( options ) ? "<STR_LIT:'>" : "<STR_LIT>" + options ) + ( error ? "<STR_LIT>" : "<STR_LIT>" ) ) ; } out . println ( ) ; out . println ( "<STR_LIT>" ) ; for ( AnnisRunner . Benchmark benchmark : benchmarks ) { benchmark . avgTimeInMilliseconds = Math . round ( ( double ) benchmark . avgTimeInMilliseconds / ( double ) benchmark . runs ) ; String options = benchmarkOptions ( benchmark . queryData ) ; out . println ( benchmark . avgTimeInMilliseconds + "<STR_LIT>" + benchmark . runs + "<STR_LIT>" + ( benchmark . errors > <NUM_LIT:0> ? "<STR_LIT:U+002CU+0020>" + benchmark . errors + "<STR_LIT>" : "<STR_LIT:)>" ) + "<STR_LIT>" + benchmark . functionCall + ( "<STR_LIT>" . equals ( options ) ? "<STR_LIT:'>" : "<STR_LIT>" + options ) ) ; } out . println ( ) ; out . println ( "<STR_LIT>" ) ; for ( AnnisRunner . Benchmark benchmark : benchmarks ) { String options = benchmarkOptions ( benchmark . queryData ) ; out . println ( benchmark . worstTimeInMilliseconds + "<STR_LIT>" + ( benchmark . errors > <NUM_LIT:0> ? "<STR_LIT:?>" + benchmark . errors + "<STR_LIT>" : "<STR_LIT:)>" ) + "<STR_LIT>" + benchmark . functionCall + ( "<STR_LIT>" . equals ( options ) ? "<STR_LIT:'>" : "<STR_LIT>" + options ) ) ; } out . println ( ) ; out . println ( "<STR_LIT>" ) ; for ( AnnisRunner . Benchmark benchmark : benchmarks ) { String options = benchmarkOptions ( benchmark . queryData ) ; out . println ( benchmark . bestTimeInMilliseconds + "<STR_LIT>" + ( benchmark . errors > <NUM_LIT:0> ? "<STR_LIT:?>" + benchmark . errors + "<STR_LIT>" : "<STR_LIT:)>" ) + "<STR_LIT>" + benchmark . functionCall + ( "<STR_LIT>" . equals ( options ) ? "<STR_LIT:'>" : "<STR_LIT>" + options ) ) ; } out . println ( ) ; try { CSVWriter csv = new CSVWriter ( new FileWriterWithEncoding ( new File ( "<STR_LIT>" ) , "<STR_LIT:UTF-8>" ) ) ; String [ ] header = new String [ ] { "<STR_LIT>" , "<STR_LIT:query>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; csv . writeNext ( header ) ; for ( AnnisRunner . Benchmark benchmark : benchmarks ) { String [ ] line = new String [ <NUM_LIT:5> ] ; line [ <NUM_LIT:0> ] = StringUtils . join ( benchmark . queryData . getCorpusList ( ) , "<STR_LIT:U+002C>" ) ; line [ <NUM_LIT:1> ] = benchmark . functionCall ; line [ <NUM_LIT:2> ] = "<STR_LIT>" + benchmark . avgTimeInMilliseconds ; line [ <NUM_LIT:3> ] = "<STR_LIT>" + Math . abs ( benchmark . bestTimeInMilliseconds - benchmark . avgTimeInMilliseconds ) ; line [ <NUM_LIT:4> ] = "<STR_LIT>" + Math . abs ( benchmark . avgTimeInMilliseconds - benchmark . worstTimeInMilliseconds ) ; csv . writeNext ( line ) ; } csv . close ( ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } } public String benchmarkOptions ( QueryData queryData ) { List < Long > corpusList = queryData . getCorpusList ( ) ; List < QueryAnnotation > metaData = queryData . getMetaData ( ) ; Set < Object > extensions = queryData . getExtensions ( ) ; List < String > fields = new ArrayList < String > ( ) ; if ( ! corpusList . isEmpty ( ) ) { fields . add ( "<STR_LIT>" + corpusList ) ; } if ( ! metaData . isEmpty ( ) ) { fields . add ( "<STR_LIT>" + metaData ) ; } for ( Object extension : extensions ) { String toString = extension . toString ( ) ; if ( ! "<STR_LIT>" . equals ( toString ) ) { fields . add ( toString ) ; } } return StringUtils . join ( fields , "<STR_LIT:U+002CU+0020>" ) ; } private void resetCaches ( AnnisRunner . OS currentOS ) { switch ( currentOS ) { case linux : try { log . info ( "<STR_LIT>" ) ; log . debug ( "<STR_LIT>" ) ; Runtime . getRuntime ( ) . exec ( "<STR_LIT>" ) . waitFor ( ) ; File dropCaches = new File ( "<STR_LIT>" ) ; if ( dropCaches . canWrite ( ) ) { log . debug ( "<STR_LIT>" ) ; Writer w = new FileWriterWithEncoding ( dropCaches , "<STR_LIT:UTF-8>" ) ; w . write ( "<STR_LIT:3>" ) ; w . close ( ) ; } else { log . warn ( "<STR_LIT>" ) ; } File postgresScript = new File ( "<STR_LIT>" ) ; if ( postgresScript . exists ( ) && postgresScript . isFile ( ) ) { log . debug ( "<STR_LIT>" ) ; Runtime . getRuntime ( ) . exec ( postgresScript . getAbsolutePath ( ) + "<STR_LIT>" ) . waitFor ( ) ; } else { log . warn ( "<STR_LIT>" ) ; } } catch ( Exception ex ) { log . error ( null , ex ) ; } break ; default : log . warn ( "<STR_LIT>" ) ; } } public void doSet ( String callToSet ) { String [ ] split = callToSet . split ( "<STR_LIT:U+0020>" , <NUM_LIT:3> ) ; Validate . isTrue ( split . length > <NUM_LIT:0> , "<STR_LIT>" + callToSet ) ; String setting = split [ <NUM_LIT:0> ] ; String value = null ; boolean show = split . length == <NUM_LIT:1> && setting . startsWith ( "<STR_LIT:?>" ) ; if ( show ) { setting = setting . substring ( <NUM_LIT:1> ) ; } else { Validate . isTrue ( split . length == <NUM_LIT:3> && "<STR_LIT>" . toLowerCase ( ) . equals ( split [ <NUM_LIT:1> ] ) , "<STR_LIT>" + callToSet ) ; value = split [ <NUM_LIT:2> ] ; } if ( "<STR_LIT>" . equals ( setting ) ) { if ( show ) { value = String . valueOf ( limit ) ; } else { limit = Integer . parseInt ( value ) ; } } else if ( "<STR_LIT>" . equals ( setting ) ) { if ( show ) { value = String . valueOf ( offset ) ; } else { offset = Integer . parseInt ( value ) ; } } else if ( "<STR_LIT>" . equals ( setting ) ) { if ( show ) { value = String . valueOf ( left ) ; } else { left = Integer . parseInt ( value ) ; } } else if ( "<STR_LIT>" . equals ( setting ) ) { if ( show ) { value = String . valueOf ( right ) ; } else { right = Integer . parseInt ( value ) ; } } else if ( "<STR_LIT>" . equals ( setting ) ) { if ( show ) { if ( left != right ) { value = "<STR_LIT>" ; } else { value = String . valueOf ( left ) ; } } else { left = Integer . parseInt ( value ) ; right = left ; } } else if ( "<STR_LIT>" . equals ( setting ) ) { if ( show ) { value = String . valueOf ( annisDao . getTimeout ( ) ) ; } else { annisDao . setTimeout ( Integer . parseInt ( value ) ) ; } } else if ( "<STR_LIT>" . equals ( setting ) ) { if ( show ) { value = String . valueOf ( clearCaches ) ; } else { clearCaches = Boolean . parseBoolean ( value ) ; } } else if ( "<STR_LIT>" . equals ( setting ) ) { corpusList . clear ( ) ; if ( ! "<STR_LIT:all>" . equals ( value ) ) { String [ ] list = value . split ( "<STR_LIT:U+0020>" ) ; for ( String corpus : list ) { corpusList . add ( Long . parseLong ( corpus ) ) ; } } } else if ( "<STR_LIT>" . equals ( setting ) ) { if ( show ) { value = segmentationLayer ; } else { segmentationLayer = value ; } } else { out . println ( "<STR_LIT>" + setting ) ; } out . println ( setting + "<STR_LIT::U+0020>" + value ) ; } public void doShow ( String setting ) { doSet ( "<STR_LIT:?>" + setting ) ; } private QueryData analyzeQuery ( String annisQuery , String queryFunction ) { QueryData queryData ; log . debug ( "<STR_LIT>" + queryFunction + "<STR_LIT>" ) ; if ( queryFunction != null && ! queryFunction . matches ( "<STR_LIT>" ) ) { queryData = annisDao . parseAQL ( annisQuery , corpusList ) ; } else { queryData = extractSaltIds ( annisQuery ) ; } queryData . setCorpusConfiguration ( annisDao . getCorpusConfiguration ( ) ) ; queryData . setDocuments ( metaDataFilter . getDocumentsForMetadata ( queryData ) ) ; if ( queryFunction != null && queryFunction . matches ( "<STR_LIT>" ) ) { queryData . addExtension ( new AnnotateQueryData ( left , right , segmentationLayer ) ) ; queryData . addExtension ( new LimitOffsetQueryData ( offset , limit ) ) ; } else if ( queryFunction != null && queryFunction . matches ( "<STR_LIT>" ) ) { queryData . addExtension ( new AnnotateQueryData ( left , right , segmentationLayer ) ) ; } if ( annisQuery != null ) { benchmarks . add ( new AnnisRunner . Benchmark ( queryFunction + "<STR_LIT:U+0020>" + annisQuery , queryData ) ) ; } out . println ( "<STR_LIT>" + queryData . getCorpusList ( ) ) ; return queryData ; } public void doCount ( String annisQuery ) { out . println ( annisDao . count ( analyzeQuery ( annisQuery , "<STR_LIT:count>" ) ) ) ; } public void doMatrix ( String annisQuery ) { List < AnnotatedMatch > matches = annisDao . matrix ( analyzeQuery ( annisQuery , "<STR_LIT>" ) ) ; if ( matches . isEmpty ( ) ) { out . println ( "<STR_LIT>" ) ; } else { WekaHelper helper = new WekaHelper ( ) ; out . println ( helper . exportAsArff ( matches ) ) ; } } public void doFind ( String annisQuery ) { List < Match > matches = annisDao . find ( analyzeQuery ( annisQuery , "<STR_LIT>" ) ) ; JAXBContext jc = null ; try { jc = JAXBContext . newInstance ( annis . service . objects . Match . class ) ; } catch ( JAXBException ex ) { log . error ( "<STR_LIT>" , ex ) ; } for ( int i = <NUM_LIT:0> ; i < matches . size ( ) ; i ++ ) { try { jc . createMarshaller ( ) . marshal ( matches . get ( i ) , out ) ; } catch ( JAXBException ex ) { log . error ( "<STR_LIT>" , ex ) ; } out . println ( ) ; } } public void doSubgraph ( String saltIds ) { QueryData queryData = analyzeQuery ( saltIds , "<STR_LIT>" ) ; out . println ( "<STR_LIT>" + left + "<STR_LIT>" + right + "<STR_LIT>" + limit + "<STR_LIT>" + offset ) ; SaltProject result = annisDao . graph ( queryData ) ; URI path = URI . createFileURI ( "<STR_LIT>" ) ; result . saveSaltProject_DOT ( path ) ; System . out . println ( "<STR_LIT>" ) ; } public void doAnnotate ( String annisQuery ) { QueryData queryData = analyzeQuery ( annisQuery , "<STR_LIT>" ) ; out . println ( "<STR_LIT>" + left + "<STR_LIT>" + right + "<STR_LIT>" + limit + "<STR_LIT>" + offset ) ; SaltProject result = annisDao . annotate ( queryData ) ; URI uri = URI . createFileURI ( "<STR_LIT>" ) ; result . saveSaltProject_DOT ( uri ) ; System . out . println ( "<STR_LIT>" ) ; } public void doCorpus ( String list ) { corpusList = new LinkedList < Long > ( ) ; String [ ] splits = StringUtils . split ( list , "<STR_LIT:U+0020>" ) ; for ( String split : splits ) { try { corpusList . add ( Long . parseLong ( split ) ) ; } catch ( NumberFormatException e ) { LinkedList < String > splitList = new LinkedList < String > ( ) ; splitList . add ( split ) ; corpusList . addAll ( annisDao . mapCorpusNamesToIds ( splitList ) ) ; } } if ( corpusList . isEmpty ( ) ) { setPrompt ( "<STR_LIT>" ) ; } else { setPrompt ( StringUtils . join ( corpusList , "<STR_LIT:U+002C>" ) + "<STR_LIT:>>" ) ; } } public void doList ( String unused ) { List < AnnisCorpus > corpora = annisDao . listCorpora ( ) ; printAsTable ( corpora , "<STR_LIT:id>" , "<STR_LIT:name>" , "<STR_LIT>" , "<STR_LIT>" ) ; } public void doAnnotations ( String doListValues ) { boolean listValues = "<STR_LIT>" . equals ( doListValues ) ; List < AnnisAttribute > annotations = annisDao . listAnnotations ( getCorpusList ( ) , listValues , true ) ; try { ObjectMapper om = new ObjectMapper ( ) ; AnnotationIntrospector ai = new JaxbAnnotationIntrospector ( ) ; DeserializationConfig config = om . getDeserializationConfig ( ) . withAnnotationIntrospector ( ai ) ; om . setDeserializationConfig ( config ) ; om . configure ( SerializationConfig . Feature . INDENT_OUTPUT , true ) ; System . out . println ( om . writeValueAsString ( annotations ) ) ; } catch ( IOException ex ) { log . error ( "<STR_LIT>" , ex ) ; } } public void doMeta ( String corpusId ) { LinkedList < Long > corpusIdAsList = new LinkedList < Long > ( ) ; try { corpusIdAsList . add ( Long . parseLong ( corpusId ) ) ; List < String > toplevelNames = annisDao . mapCorpusIdsToNames ( corpusIdAsList ) ; List < Annotation > corpusAnnotations = annisDao . listCorpusAnnotations ( toplevelNames . get ( <NUM_LIT:0> ) ) ; printAsTable ( corpusAnnotations , "<STR_LIT>" , "<STR_LIT:name>" , "<STR_LIT:value>" ) ; } catch ( NumberFormatException ex ) { System . out . print ( "<STR_LIT>" + corpusId ) ; } } public void doSqlText ( String textID ) { long l = Long . parseLong ( textID ) ; System . out . println ( annotateSqlGenerator . getTextQuery ( l ) ) ; } public void doText ( String textID ) { SaltProject p = annisDao . retrieveAnnotationGraph ( Long . parseLong ( textID ) ) ; System . out . println ( printSaltAsXMI ( p ) ) ; } public void doSqlDoc ( String docCall ) { String [ ] splitted = docCall . split ( "<STR_LIT>" ) ; Validate . isTrue ( splitted . length > <NUM_LIT:1> , "<STR_LIT>" ) ; System . out . println ( annotateSqlGenerator . getDocumentQuery ( splitted [ <NUM_LIT:0> ] , splitted [ <NUM_LIT:1> ] ) ) ; } public void doDoc ( String docCall ) { String [ ] splitted = docCall . split ( "<STR_LIT>" ) ; Validate . isTrue ( splitted . length > <NUM_LIT:1> , "<STR_LIT>" ) ; SaltProject p = annisDao . retrieveAnnotationGraph ( splitted [ <NUM_LIT:0> ] , splitted [ <NUM_LIT:1> ] ) ; System . out . println ( printSaltAsXMI ( p ) ) ; } public void doQuit ( String dummy ) { System . out . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } private void printAsTable ( List < ? extends Object > list , String ... fields ) { out . println ( new TableFormatter ( ) . formatAsTable ( list , fields ) ) ; } private QueryData parse ( String input ) { return annisDao . parseAQL ( input , getCorpusList ( ) ) ; } private String printSaltAsXMI ( SaltProject project ) { try { Resource resource = new XMIResourceImpl ( ) ; resource . getContents ( ) . add ( project ) ; for ( SCorpusGraph corpusGraph : project . getSCorpusGraphs ( ) ) { for ( SDocument doc : corpusGraph . getSDocuments ( ) ) { if ( doc . getSDocumentGraph ( ) != null ) { resource . getContents ( ) . add ( doc . getSDocumentGraph ( ) ) ; } } } ByteArrayOutputStream outStream = new ByteArrayOutputStream ( ) ; resource . save ( outStream , null ) ; return new String ( outStream . toByteArray ( ) , "<STR_LIT:UTF-8>" ) ; } catch ( IOException ex ) { log . error ( null , ex ) ; } return "<STR_LIT>" ; } public AnnisParser getAnnisParser ( ) { return annisParser ; } public void setAnnisParser ( AnnisParser annisParser ) { this . annisParser = annisParser ; } public AnnisDao getAnnisDao ( ) { return annisDao ; } public void setAnnisDao ( AnnisDao annisDao ) { this . annisDao = annisDao ; } public QueryAnalysis getAqlAnalysis ( ) { return aqlAnalysis ; } public void setAqlAnalysis ( QueryAnalysis aqlAnalysis ) { this . aqlAnalysis = aqlAnalysis ; } public List < Long > getCorpusList ( ) { return corpusList ; } public void setCorpusList ( List < Long > corpusList ) { this . corpusList = corpusList ; } public int getContext ( ) { return context ; } public void setContext ( int context ) { this . context = context ; } public int getMatchLimit ( ) { return matchLimit ; } public void setMatchLimit ( int matchLimit ) { this . matchLimit = matchLimit ; } public QueryAnalysis getQueryAnalysis ( ) { return queryAnalysis ; } public void setQueryAnalysis ( QueryAnalysis queryAnalysis ) { this . queryAnalysis = queryAnalysis ; } public SqlGenerator < QueryData , Integer > getCountSqlGenerator ( ) { return countSqlGenerator ; } public void setCountSqlGenerator ( SqlGenerator < QueryData , Integer > countSqlGenerator ) { this . countSqlGenerator = countSqlGenerator ; } public AnnotateSqlGenerator < SaltProject > getAnnotateSqlGenerator ( ) { return annotateSqlGenerator ; } public void setAnnotateSqlGenerator ( AnnotateSqlGenerator < SaltProject > annotateSqlGenerator ) { this . annotateSqlGenerator = annotateSqlGenerator ; } public SqlGenerator < QueryData , List < Match > > getFindSqlGenerator ( ) { return findSqlGenerator ; } public void setFindSqlGenerator ( SqlGenerator < QueryData , List < Match > > findSqlGenerator ) { this . findSqlGenerator = findSqlGenerator ; } public SqlGenerator < QueryData , List < AnnotatedMatch > > getMatrixSqlGenerator ( ) { return matrixSqlGenerator ; } public void setMatrixSqlGenerator ( SqlGenerator < QueryData , List < AnnotatedMatch > > matrixSqlGenerator ) { this . matrixSqlGenerator = matrixSqlGenerator ; } public MetaDataFilter getMetaDataFilter ( ) { return metaDataFilter ; } public void setMetaDataFilter ( MetaDataFilter metaDataFilter ) { this . metaDataFilter = metaDataFilter ; } private QueryData extractSaltIds ( String saltIds ) { QueryData queryData = new QueryData ( ) ; SaltURIs uris = new SaltURIs ( ) ; for ( String id : saltIds . split ( "<STR_LIT>" ) ) { java . net . URI uri ; try { uri = new java . net . URI ( id ) ; if ( ! "<STR_LIT>" . equals ( uri . getScheme ( ) ) || uri . getFragment ( ) == null ) { throw new URISyntaxException ( "<STR_LIT>" , uri . toString ( ) ) ; } } catch ( URISyntaxException ex ) { log . error ( null , ex ) ; continue ; } uris . add ( uri ) ; } Set < String > corpusNames = new TreeSet < String > ( ) ; List < QueryNode > pseudoNodes = new ArrayList < QueryNode > ( uris . size ( ) ) ; for ( java . net . URI u : uris ) { pseudoNodes . add ( new QueryNode ( ) ) ; corpusNames . add ( CommonHelper . getCorpusPath ( u ) . get ( <NUM_LIT:0> ) ) ; } List < Long > corpusIDs = annisDao . mapCorpusNamesToIds ( new LinkedList < String > ( corpusNames ) ) ; queryData . setCorpusList ( corpusIDs ) ; queryData . addAlternative ( pseudoNodes ) ; log . debug ( uris . toString ( ) ) ; queryData . addExtension ( uris ) ; return queryData ; } } </s>
<s> package annis ; import annis . dao . AnnotatedMatch ; import annis . dao . AnnotatedSpan ; import annis . model . Annotation ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . SortedMap ; import java . util . SortedSet ; import java . util . TreeMap ; import java . util . TreeSet ; import org . apache . commons . lang3 . StringUtils ; public class WekaHelper { public static String exportAsArff ( List < AnnotatedMatch > annotatedMatches ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT:n>" ) ; SortedMap < Integer , SortedSet < String > > columnsByNodePos = new TreeMap < Integer , SortedSet < String > > ( ) ; for ( int i = <NUM_LIT:0> ; i < annotatedMatches . size ( ) ; ++ i ) { AnnotatedMatch match = annotatedMatches . get ( i ) ; for ( int j = <NUM_LIT:0> ; j < match . size ( ) ; ++ j ) { AnnotatedSpan span = match . get ( j ) ; if ( columnsByNodePos . get ( j ) == null ) { columnsByNodePos . put ( j , new TreeSet < String > ( ) ) ; } for ( Annotation annotation : span . getAnnotations ( ) ) { columnsByNodePos . get ( j ) . add ( "<STR_LIT>" + annotation . getQualifiedName ( ) ) ; } for ( Annotation meta : span . getMetadata ( ) ) { columnsByNodePos . get ( j ) . add ( "<STR_LIT>" + meta . getQualifiedName ( ) ) ; } } } int count = columnsByNodePos . keySet ( ) . size ( ) ; for ( int j = <NUM_LIT:0> ; j < count ; ++ j ) { sb . append ( "<STR_LIT>" ) . append ( fullColumnName ( j + <NUM_LIT:1> , "<STR_LIT:id>" ) ) . append ( "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" ) . append ( fullColumnName ( j + <NUM_LIT:1> , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) ; SortedSet < String > annotationNames = columnsByNodePos . get ( j ) ; for ( String name : annotationNames ) { sb . append ( "<STR_LIT>" ) . append ( fullColumnName ( j + <NUM_LIT:1> , name ) ) . append ( "<STR_LIT>" ) ; } } sb . append ( "<STR_LIT>" ) ; for ( AnnotatedMatch match : annotatedMatches ) { List < String > line = new ArrayList < String > ( ) ; int k = <NUM_LIT:0> ; for ( ; k < match . size ( ) ; ++ k ) { AnnotatedSpan span = match . get ( k ) ; Map < String , String > valueByName = new HashMap < String , String > ( ) ; if ( span != null ) { if ( span . getAnnotations ( ) != null ) { for ( Annotation annotation : span . getAnnotations ( ) ) { valueByName . put ( "<STR_LIT>" + annotation . getQualifiedName ( ) , annotation . getValue ( ) ) ; } } if ( span . getMetadata ( ) != null ) { for ( Annotation meta : span . getMetadata ( ) ) { valueByName . put ( "<STR_LIT>" + meta . getQualifiedName ( ) , meta . getValue ( ) ) ; } } line . add ( "<STR_LIT:'>" + span . getId ( ) + "<STR_LIT:'>" ) ; line . add ( "<STR_LIT:'>" + span . getCoveredText ( ) . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) + "<STR_LIT:'>" ) ; } for ( String name : columnsByNodePos . get ( k ) ) { if ( valueByName . containsKey ( name ) ) { line . add ( "<STR_LIT:'>" + valueByName . get ( name ) . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) + "<STR_LIT:'>" ) ; } else { line . add ( "<STR_LIT>" ) ; } } } for ( int l = k ; l < count ; ++ l ) { line . add ( "<STR_LIT>" ) ; for ( int m = <NUM_LIT:0> ; m <= columnsByNodePos . get ( l ) . size ( ) ; ++ m ) { line . add ( "<STR_LIT>" ) ; } } sb . append ( StringUtils . join ( line , "<STR_LIT:U+002C>" ) ) ; sb . append ( "<STR_LIT:n>" ) ; } return sb . toString ( ) ; } private static String fullColumnName ( int i , String name ) { return "<STR_LIT:#>" + i + "<STR_LIT:_>" + name ; } } </s>
<s> package annis . sqlgen ; import java . sql . ResultSet ; import java . util . List ; public interface SolutionKey < KeyType > { public abstract List < String > generateInnerQueryColumns ( TableAccessStrategy tableAccessStrategy , int index ) ; public abstract List < String > generateOuterQueryColumns ( TableAccessStrategy tableAccessStrategy , int size ) ; public abstract KeyType retrieveKey ( ResultSet resultSet ) ; public abstract boolean isNewKey ( ) ; public abstract Integer getMatchedNodeIndex ( Object id ) ; public abstract List < String > getKeyColumns ( int size ) ; public abstract Object getNodeId ( ResultSet resultSet , TableAccessStrategy tableAccessStrategy ) ; public abstract int getKeySize ( ) ; public abstract String getCurrentKeyAsString ( ) ; } </s>
<s> package annis . sqlgen ; import static annis . sqlgen . SqlConstraints . in ; import static annis . sqlgen . TableAccessStrategy . NODE_TABLE ; import static annis . sqlgen . TableAccessStrategy . RANK_TABLE ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import annis . model . QueryNode ; import annis . ql . parser . QueryData ; import java . util . LinkedList ; public class MetaDataAndCorpusWhereClauseGenerator extends TableAccessStrategyFactory implements WhereClauseSqlGenerator < QueryData > { @ Override public Set < String > whereConditions ( QueryData queryData , List < QueryNode > alternative , String indent ) { Set < String > conditions = new HashSet < String > ( ) ; List < Long > corpusList = queryData . getCorpusList ( ) ; List < Long > documents = queryData . getDocuments ( ) ; if ( documents == null && corpusList == null ) { return new HashSet < String > ( ) ; } for ( QueryNode node : alternative ) { if ( documents != null ) { List < String > emptyList = new LinkedList < String > ( ) ; emptyList . add ( "<STR_LIT>" ) ; conditions . add ( in ( tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) , documents . isEmpty ( ) ? emptyList : documents ) ) ; } if ( corpusList != null && ! corpusList . isEmpty ( ) ) { conditions . add ( in ( tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) , corpusList ) ) ; if ( tables ( node ) . usesRankTable ( ) && ! tables ( node ) . isMaterialized ( RANK_TABLE , NODE_TABLE ) ) { conditions . add ( in ( tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , corpusList ) ) ; } } } return conditions ; } } </s>
<s> package annis . sqlgen ; import java . sql . ResultSet ; import java . sql . SQLException ; import java . util . List ; public interface CorpusPathExtractor { public List < String > extractCorpusPath ( ResultSet resultSet , String columnName ) throws SQLException ; } </s>
<s> package annis . sqlgen ; import annis . service . objects . AnnisBinary ; import java . sql . ResultSet ; import java . sql . SQLException ; import java . sql . Types ; import java . util . Arrays ; import org . slf4j . LoggerFactory ; import org . springframework . dao . DataAccessException ; import org . springframework . jdbc . core . ResultSetExtractor ; public class ByteHelper implements ResultSetExtractor < AnnisBinary > { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( ByteHelper . class ) ; private static final int [ ] ARG_TYPES = new int [ ] { Types . INTEGER , Types . INTEGER , Types . VARCHAR , Types . VARCHAR } ; public static final String SQL = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; ; public static int [ ] getArgTypes ( ) { return Arrays . copyOf ( ARG_TYPES , ARG_TYPES . length ) ; } public Object [ ] getArgs ( String toplevelCorpusName , String corpusName , int offset , int length ) { return new Object [ ] { offset , length , toplevelCorpusName , corpusName } ; } @ Override public AnnisBinary extractData ( ResultSet rs ) throws DataAccessException { AnnisBinary ab = new AnnisBinary ( ) ; try { while ( rs . next ( ) ) { ab . setBytes ( rs . getBytes ( "<STR_LIT>" ) ) ; ab . setFileName ( rs . getString ( "<STR_LIT:title>" ) ) ; ab . setCorpusName ( rs . getString ( "<STR_LIT>" ) ) ; ab . setMimeType ( rs . getString ( "<STR_LIT>" ) ) ; ab . setLength ( rs . getInt ( "<STR_LIT>" ) ) ; break ; } } catch ( SQLException ex ) { log . error ( null , ex ) ; } return ab ; } } </s>
<s> package annis . sqlgen ; import org . springframework . jdbc . core . ResultSetExtractor ; public interface SqlGenerator < QueryType , ResultType > extends ResultSetExtractor < ResultType > { String toSql ( QueryType queryData ) ; String toSql ( QueryType queryData , String indent ) ; } </s>
<s> package annis . sqlgen ; import static annis . sqlgen . SqlConstraints . bitSelect ; import static annis . sqlgen . SqlConstraints . join ; import static annis . sqlgen . SqlConstraints . isTrue ; import static annis . sqlgen . TableAccessStrategy . NODE_TABLE ; import static annis . sqlgen . TableAccessStrategy . COMPONENT_TABLE ; import static annis . sqlgen . TableAccessStrategy . EDGE_ANNOTATION_TABLE ; import static annis . sqlgen . TableAccessStrategy . RANK_TABLE ; import static annis . sqlgen . TableAccessStrategy . NODE_ANNOTATION_TABLE ; import static annis . sqlgen . TableAccessStrategy . FACTS_TABLE ; import annis . model . QueryNode ; import annis . ql . parser . QueryData ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . Set ; public class SampleWhereClause extends TableAccessStrategyFactory implements WhereClauseSqlGenerator < QueryData > { @ Override public Set < String > whereConditions ( QueryData queryData , List < QueryNode > alternative , String indent ) { Set < String > conditions = new HashSet < String > ( ) ; List < Long > corpusList = queryData . getCorpusList ( ) ; List < Long > documents = queryData . getDocuments ( ) ; for ( QueryNode node : alternative ) { conditions . addAll ( whereConditions ( node , corpusList , documents ) ) ; } return conditions ; } @ Deprecated public List < String > whereConditions ( QueryNode node , List < Long > corpusList , List < Long > documents ) { LinkedList < String > conditions = new LinkedList < String > ( ) ; TableAccessStrategy t = tables ( node ) ; if ( t . isMaterialized ( NODE_TABLE , FACTS_TABLE ) && t . isMaterialized ( NODE_ANNOTATION_TABLE , FACTS_TABLE ) && t . isMaterialized ( EDGE_ANNOTATION_TABLE , FACTS_TABLE ) && t . isMaterialized ( RANK_TABLE , FACTS_TABLE ) && t . isMaterialized ( COMPONENT_TABLE , FACTS_TABLE ) ) { if ( ! t . usesRankTable ( ) && ! t . usesComponentTable ( ) && ! t . usesNodeAnnotationTable ( ) && ! t . usesEdgeAnnotationTable ( ) ) { conditions . add ( "<STR_LIT>" ) ; conditions . add ( isTrue ( t . aliasedColumn ( FACTS_TABLE , "<STR_LIT>" ) ) ) ; } else if ( ! t . usesNodeAnnotationTable ( ) && ! t . usesEdgeAnnotationTable ( ) ) { conditions . add ( "<STR_LIT>" ) ; conditions . add ( isTrue ( t . aliasedColumn ( FACTS_TABLE , "<STR_LIT>" ) ) ) ; } else if ( ! t . usesRankTable ( ) && ! t . usesComponentTable ( ) && ! t . usesEdgeAnnotationTable ( ) ) { conditions . add ( "<STR_LIT>" ) ; conditions . add ( isTrue ( t . aliasedColumn ( FACTS_TABLE , "<STR_LIT>" ) ) ) ; } else if ( ! t . usesNodeAnnotationTable ( ) ) { conditions . add ( "<STR_LIT>" ) ; conditions . add ( isTrue ( t . aliasedColumn ( FACTS_TABLE , "<STR_LIT>" ) ) ) ; } else if ( ! t . usesEdgeAnnotationTable ( ) ) { conditions . add ( "<STR_LIT>" ) ; conditions . add ( isTrue ( t . aliasedColumn ( FACTS_TABLE , "<STR_LIT>" ) ) ) ; } } else if ( t . isMaterialized ( NODE_TABLE , NODE_ANNOTATION_TABLE ) && t . isMaterialized ( RANK_TABLE , EDGE_ANNOTATION_TABLE ) && ! t . isMaterialized ( NODE_TABLE , RANK_TABLE ) ) { if ( ! t . usesRankTable ( ) && ! t . usesComponentTable ( ) && ! t . usesNodeAnnotationTable ( ) && ! t . usesEdgeAnnotationTable ( ) ) { conditions . add ( "<STR_LIT>" ) ; conditions . add ( isTrue ( t . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) ) ; } else if ( ! t . usesNodeAnnotationTable ( ) && ! t . usesEdgeAnnotationTable ( ) ) { conditions . add ( "<STR_LIT>" ) ; conditions . add ( isTrue ( t . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) ) ) ; } } return conditions ; } } </s>
<s> package annis . sqlgen . fullfacts ; import static annis . sqlgen . SqlConstraints . sqlString ; import static annis . sqlgen . SqlConstraints . join ; import annis . model . QueryAnnotation ; import annis . model . QueryNode ; import annis . model . QueryNode . TextMatching ; import annis . ql . parser . QueryData ; import annis . sqlgen . AnnotationConditionProvider ; import annis . sqlgen . TableAccessStrategy ; import java . util . List ; public class FfAnnotateConditionProvider implements AnnotationConditionProvider { @ Override public void addAnnotationConditions ( List < String > conditions , QueryNode node , int index , QueryAnnotation annotation , String table , QueryData queryData , TableAccessStrategy tas ) { if ( annotation . getNamespace ( ) != null ) { conditions . add ( join ( "<STR_LIT:=>" , tas . aliasedColumn ( table , "<STR_LIT>" , index ) , sqlString ( annotation . getNamespace ( ) ) ) ) ; } conditions . add ( join ( "<STR_LIT:=>" , tas . aliasedColumn ( table , "<STR_LIT:name>" , index ) , sqlString ( annotation . getName ( ) ) ) ) ; if ( annotation . getValue ( ) != null ) { TextMatching textMatching = annotation . getTextMatching ( ) ; conditions . add ( join ( textMatching . sqlOperator ( ) , tas . aliasedColumn ( table , "<STR_LIT:value>" , index ) , sqlString ( annotation . getValue ( ) , textMatching ) ) ) ; } } } </s>
<s> package annis . sqlgen . fullfacts ; import annis . model . QueryNode ; import annis . ql . parser . QueryData ; import annis . sqlgen . AnnotateSqlGenerator ; import annis . sqlgen . LimitOffsetQueryData ; import annis . sqlgen . SolutionKey ; import annis . sqlgen . TableAccessStrategy ; import java . util . ArrayList ; import java . util . List ; import org . apache . commons . lang3 . StringUtils ; import org . apache . commons . lang3 . Validate ; import static annis . sqlgen . TableAccessStrategy . COMPONENT_TABLE ; import static annis . sqlgen . TableAccessStrategy . NODE_TABLE ; import static annis . sqlgen . TableAccessStrategy . RANK_TABLE ; import static annis . sqlgen . TableAccessStrategy . NODE_ANNOTATION_TABLE ; import static annis . sqlgen . TableAccessStrategy . EDGE_ANNOTATION_TABLE ; import static annis . sqlgen . SqlConstraints . sqlString ; public class FfAnnotateSqlGenerator < T > extends AnnotateSqlGenerator < T > { @ Override public String getTextQuery ( long textID ) { String template = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String sql = template . replace ( "<STR_LIT>" , String . valueOf ( textID ) ) ; return sql ; } @ Override public String getDocumentQuery ( String toplevelCorpusName , String documentName ) { String template = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; String sql = template . replace ( "<STR_LIT>" , sqlString ( toplevelCorpusName ) ) . replace ( "<STR_LIT>" , sqlString ( documentName ) ) ; return sql ; } @ Override public String selectClause ( QueryData queryData , List < QueryNode > alternative , String indent ) { String innerIndent = indent + TABSTOP ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( innerIndent ) . append ( "<STR_LIT>" ) ; sb . append ( innerIndent ) ; List < LimitOffsetQueryData > extension = queryData . getExtensions ( LimitOffsetQueryData . class ) ; Validate . isTrue ( extension . size ( ) > <NUM_LIT:0> ) ; sb . append ( innerIndent ) . append ( extension . get ( <NUM_LIT:0> ) . getOffset ( ) ) . append ( "<STR_LIT>" ) ; sb . append ( indent ) . append ( TABSTOP + "<STR_LIT>" ) ; List < String > fields = new ArrayList < String > ( ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT:id>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT:name>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; if ( isIncludeIsTokenColumn ( ) ) { addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; } addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , RANK_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , RANK_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , RANK_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , RANK_TABLE , "<STR_LIT:root>" ) ; addSelectClauseAttribute ( fields , RANK_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , COMPONENT_TABLE , "<STR_LIT:id>" ) ; addSelectClauseAttribute ( fields , COMPONENT_TABLE , "<STR_LIT:type>" ) ; addSelectClauseAttribute ( fields , COMPONENT_TABLE , "<STR_LIT:name>" ) ; addSelectClauseAttribute ( fields , COMPONENT_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_ANNOTATION_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , NODE_ANNOTATION_TABLE , "<STR_LIT:name>" ) ; addSelectClauseAttribute ( fields , NODE_ANNOTATION_TABLE , "<STR_LIT:value>" ) ; addSelectClauseAttribute ( fields , EDGE_ANNOTATION_TABLE , "<STR_LIT>" ) ; addSelectClauseAttribute ( fields , EDGE_ANNOTATION_TABLE , "<STR_LIT:name>" ) ; addSelectClauseAttribute ( fields , EDGE_ANNOTATION_TABLE , "<STR_LIT:value>" ) ; sb . append ( innerIndent ) . append ( StringUtils . join ( fields , "<STR_LIT>" + indent + TABSTOP ) ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( innerIndent ) . append ( "<STR_LIT>" ) ; if ( isIncludeDocumentNameInAnnotateQuery ( ) ) { sb . append ( "<STR_LIT>" ) ; sb . append ( innerIndent ) . append ( "<STR_LIT>" ) ; } return sb . toString ( ) ; } @ Override public String fromClause ( QueryData queryData , List < QueryNode > alternative , String indent ) { StringBuffer sb = new StringBuffer ( ) ; sb . append ( indent ) . append ( "<STR_LIT>" ) ; sb . append ( indent ) . append ( TABSTOP ) . append ( getTableJoinsInFromClauseSqlGenerator ( ) . fromClauseForNode ( null , true ) ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( indent ) . append ( TABSTOP ) . append ( TableAccessStrategy . CORPUS_TABLE ) ; return sb . toString ( ) ; } } </s>
<s> package annis . sqlgen ; import annis . model . QueryAnnotation ; import annis . model . QueryNode ; import annis . ql . parser . QueryData ; import java . util . List ; public interface AnnotationConditionProvider { public void addAnnotationConditions ( List < String > conditions , QueryNode node , int index , QueryAnnotation annotation , String table , QueryData queryData , TableAccessStrategy tas ) ; } </s>
<s> package annis . sqlgen ; public class LimitOffsetQueryData { private int offset ; private int limit ; public LimitOffsetQueryData ( int offset , int limit ) { this . offset = offset ; this . limit = limit ; } public int getLimit ( ) { return limit ; } public int getOffset ( ) { return offset ; } public boolean isPaged ( ) { return offset != <NUM_LIT:0> || limit != <NUM_LIT:0> ; } } </s>
<s> package annis . sqlgen ; import static annis . sqlgen . AbstractSqlGenerator . TABSTOP ; import static annis . sqlgen . SqlConstraints . join ; import static annis . sqlgen . TableAccessStrategy . COMPONENT_TABLE ; import static annis . sqlgen . TableAccessStrategy . EDGE_ANNOTATION_TABLE ; import static annis . sqlgen . TableAccessStrategy . NODE_ANNOTATION_TABLE ; import static annis . sqlgen . TableAccessStrategy . NODE_TABLE ; import static annis . sqlgen . TableAccessStrategy . RANK_TABLE ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import org . apache . commons . lang3 . StringUtils ; import annis . model . QueryNode ; import annis . ql . parser . QueryData ; public class TableJoinsInWhereClauseGenerator extends AbstractFromClauseGenerator implements WhereClauseSqlGenerator < QueryData > { @ Override public String fromClause ( QueryData queryData , List < QueryNode > alternative , String indent ) { List < String > tables = new ArrayList < String > ( ) ; for ( QueryNode node : alternative ) tables . add ( fromClauseForNode ( node , false ) ) ; return StringUtils . join ( tables , "<STR_LIT>" + indent + TABSTOP ) ; } @ Override public Set < String > whereConditions ( QueryData queryData , List < QueryNode > alternative , String indent ) { Set < String > conditions = new HashSet < String > ( ) ; for ( QueryNode node : alternative ) { conditions . addAll ( whereConditionsForNode ( node ) ) ; } return conditions ; } public String fromClauseForNode ( QueryNode node ) { return fromClauseForNode ( node , false ) ; } public String fromClauseForNode ( QueryNode node , boolean leftJoin ) { List < String > tables = new ArrayList < String > ( ) ; tables . add ( tableAliasDefinition ( node , NODE_TABLE , <NUM_LIT:1> ) ) ; if ( tables ( node ) . usesRankTable ( ) && ! tables ( node ) . isMaterialized ( RANK_TABLE , NODE_TABLE ) ) { tables . add ( tableAliasDefinition ( node , RANK_TABLE , <NUM_LIT:1> ) ) ; } if ( tables ( node ) . usesRankTable ( ) && ! tables ( node ) . isMaterialized ( COMPONENT_TABLE , RANK_TABLE ) ) { tables . add ( tableAliasDefinition ( node , COMPONENT_TABLE , <NUM_LIT:1> ) ) ; } if ( tables ( node ) . usesNodeAnnotationTable ( ) ) { int start = tables ( node ) . isMaterialized ( NODE_ANNOTATION_TABLE , NODE_TABLE ) ? <NUM_LIT:2> : <NUM_LIT:1> ; for ( int i = start ; i <= node . getNodeAnnotations ( ) . size ( ) ; ++ i ) { tables . add ( tableAliasDefinition ( node , NODE_ANNOTATION_TABLE , i ) ) ; } } if ( tables ( node ) . usesEdgeAnnotationTable ( ) ) { int start = tables ( node ) . isMaterialized ( EDGE_ANNOTATION_TABLE , RANK_TABLE ) ? <NUM_LIT:2> : <NUM_LIT:1> ; for ( int i = start ; i <= node . getEdgeAnnotations ( ) . size ( ) ; ++ i ) { tables . add ( tableAliasDefinition ( node , EDGE_ANNOTATION_TABLE , i ) ) ; } } return StringUtils . join ( tables , "<STR_LIT:U+002CU+0020>" ) ; } public Set < String > whereConditionsForNode ( QueryNode node ) { Set < String > conditions = new HashSet < String > ( ) ; if ( tables ( node ) . usesRankTable ( ) && ! tables ( node ) . isMaterialized ( RANK_TABLE , NODE_TABLE ) ) { conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT:id>" ) ) ) ; } if ( tables ( node ) . usesRankTable ( ) && ! tables ( node ) . isMaterialized ( COMPONENT_TABLE , RANK_TABLE ) ) { conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , tables ( node ) . aliasedColumn ( COMPONENT_TABLE , "<STR_LIT:id>" ) ) ) ; } if ( tables ( node ) . usesNodeAnnotationTable ( ) ) { int start = tables ( node ) . isMaterialized ( NODE_ANNOTATION_TABLE , NODE_TABLE ) ? <NUM_LIT:2> : <NUM_LIT:1> ; for ( int i = start ; i <= node . getNodeAnnotations ( ) . size ( ) ; ++ i ) { conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( NODE_ANNOTATION_TABLE , "<STR_LIT>" , i ) , tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT:id>" ) ) ) ; } } if ( tables ( node ) . usesEdgeAnnotationTable ( ) ) { int start = tables ( node ) . isMaterialized ( EDGE_ANNOTATION_TABLE , RANK_TABLE ) ? <NUM_LIT:2> : <NUM_LIT:1> ; for ( int i = start ; i <= node . getEdgeAnnotations ( ) . size ( ) ; ++ i ) { conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( EDGE_ANNOTATION_TABLE , "<STR_LIT>" , i ) , tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) ) ) ; } } return conditions ; } } </s>
<s> package annis . sqlgen ; import static annis . sqlgen . AbstractSqlGenerator . TABSTOP ; import static annis . sqlgen . SqlConstraints . join ; import annis . model . QueryNode ; import annis . ql . parser . QueryData ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import org . apache . commons . lang3 . StringUtils ; public class CorpusPathWhereClauseGenerator extends AbstractFromClauseGenerator implements WhereClauseSqlGenerator < QueryData > { @ Override public String fromClause ( QueryData queryData , List < QueryNode > alternative , String indent ) { List < String > tables = new ArrayList < String > ( ) ; for ( int i = <NUM_LIT:0> ; i < alternative . size ( ) ; i ++ ) { QueryNode n = alternative . get ( i ) ; tables . add ( "<STR_LIT>" + "<STR_LIT>" + ( i + <NUM_LIT:1> ) ) ; } return StringUtils . join ( tables , "<STR_LIT:U+002CU+0020>" + indent + TABSTOP ) ; } @ Override public Set < String > whereConditions ( QueryData queryData , List < QueryNode > alternative , String indent ) { Set < String > conditions = new HashSet < String > ( ) ; int i = <NUM_LIT:0> ; for ( QueryNode n : alternative ) { i ++ ; String factTable = tables ( n ) . aliasedTable ( "<STR_LIT>" , <NUM_LIT:1> ) + "<STR_LIT>" ; String corpusTable = tables ( n ) . aliasedTable ( "<STR_LIT>" , i ) + "<STR_LIT>" ; conditions . add ( join ( "<STR_LIT:=>" , factTable , corpusTable ) ) ; } return conditions ; } } </s>
<s> package annis . sqlgen ; import java . util . ArrayList ; import java . util . List ; import org . apache . commons . lang3 . StringUtils ; import org . springframework . util . Assert ; import annis . model . QueryNode ; import annis . ql . parser . QueryData ; public abstract class AbstractUnionSqlGenerator < T > extends AbstractSqlGenerator < T > { @ Override public String toSql ( QueryData queryData , String indent ) { Assert . notEmpty ( queryData . getAlternatives ( ) , "<STR_LIT>" ) ; StringBuffer sb = new StringBuffer ( ) ; sb . append ( indent ) ; List < String > alternatives = new ArrayList < String > ( ) ; for ( List < QueryNode > alternative : queryData . getAlternatives ( ) ) { alternatives . add ( createSqlForAlternative ( queryData , alternative , indent ) ) ; } sb . append ( StringUtils . join ( alternatives , "<STR_LIT:n>" + indent + "<STR_LIT>" ) ) ; appendOrderByClause ( sb , queryData , null , indent ) ; appendLimitOffsetClause ( sb , queryData , null , indent ) ; return sb . toString ( ) ; } } </s>
<s> package annis . sqlgen ; import annis . model . QueryNode ; import annis . ql . parser . QueryData ; import java . util . HashMap ; import java . util . LinkedList ; import java . util . List ; import java . util . Properties ; import org . apache . commons . lang3 . StringUtils ; import static annis . sqlgen . TableAccessStrategy . * ; import static annis . sqlgen . AbstractSqlGenerator . TABSTOP ; import static annis . sqlgen . SqlConstraints . sqlString ; public class CommonAnnotateWithClauseGenerator extends TableAccessStrategyFactory implements WithClauseSqlGenerator < QueryData > { private AnnotateInnerQuerySqlGenerator innerQuerySqlGenerator ; private IslandsPolicy islandsPolicy ; protected SolutionKey < ? > createSolutionKey ( ) { throw new UnsupportedOperationException ( "<STR_LIT>" ) ; } @ Override public List < String > withClauses ( QueryData queryData , List < QueryNode > alternative , String indent ) { List < Long > corpusList = queryData . getCorpusList ( ) ; HashMap < Long , Properties > corpusProperties = queryData . getCorpusConfiguration ( ) ; IslandsPolicy . IslandPolicies policy = getIslandsPolicy ( ) . getMostRestrictivePolicy ( corpusList , corpusProperties ) ; List < String > result = new LinkedList < String > ( ) ; List < AnnotateQueryData > ext = queryData . getExtensions ( AnnotateQueryData . class ) ; if ( ! ext . isEmpty ( ) ) { AnnotateQueryData annoQueryData = ext . get ( <NUM_LIT:0> ) ; if ( annoQueryData . getSegmentationLayer ( ) == null ) { result . add ( getMatchesWithClause ( queryData , alternative , indent ) ) ; result . add ( getSolutionFromMatchesWithClause ( queryData , policy , alternative , "<STR_LIT>" , indent ) ) ; } else { result . add ( getMatchesWithClause ( queryData , alternative , indent ) ) ; result . add ( getNearestSeqWithClause ( queryData , annoQueryData , alternative , "<STR_LIT>" , indent ) ) ; result . add ( getSolutionFromNearestSegWithClause ( queryData , annoQueryData , alternative , policy , "<STR_LIT>" , indent ) ) ; } } return result ; } protected String getMatchesWithClause ( QueryData queryData , List < QueryNode > alternative , String indent ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( indent ) . append ( "<STR_LIT>" ) ; sb . append ( indent ) . append ( "<STR_LIT>" ) ; sb . append ( indent ) . append ( getInnerQuerySqlGenerator ( ) . toSql ( queryData , indent + TABSTOP ) ) ; sb . append ( "<STR_LIT:n>" ) . append ( indent ) . append ( "<STR_LIT:)>" ) ; return sb . toString ( ) ; } protected String getSolutionFromMatchesWithClause ( QueryData queryData , IslandsPolicy . IslandPolicies islandPolicies , List < QueryNode > alternative , String matchesName , String indent ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( indent ) . append ( "<STR_LIT>" ) ; sb . append ( indent ) . append ( "<STR_LIT>" ) ; String innerIndent = indent + TABSTOP ; if ( islandPolicies == IslandsPolicy . IslandPolicies . none ) { innerIndent = indent + TABSTOP + TABSTOP ; sb . append ( indent ) . append ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } SolutionKey < ? > key = createSolutionKey ( ) ; TableAccessStrategy tas = new TableAccessStrategy ( createTableAccessStrategy ( ) ) ; tas . addTableAlias ( "<STR_LIT>" , matchesName ) ; List < String > keyColumns = key . generateOuterQueryColumns ( tas , alternative . size ( ) ) ; for ( int i = <NUM_LIT:1> ; i <= alternative . size ( ) ; i ++ ) { if ( i >= <NUM_LIT:2> ) { sb . append ( innerIndent ) . append ( "<STR_LIT>" ) ; } sb . append ( innerIndent ) . append ( "<STR_LIT>" ) . append ( StringUtils . join ( keyColumns , "<STR_LIT:U+002CU+0020>" ) ) . append ( "<STR_LIT>" ) . append ( i ) . append ( "<STR_LIT>" ) . append ( i ) . append ( "<STR_LIT>" ) . append ( i ) . append ( "<STR_LIT>" ) . append ( i ) . append ( "<STR_LIT>" ) . append ( "<STR_LIT>" ) . append ( matchesName ) . append ( "<STR_LIT:n>" ) ; } if ( islandPolicies == IslandsPolicy . IslandPolicies . none ) { sb . append ( indent ) . append ( "<STR_LIT>" ) ; } if ( islandPolicies == IslandsPolicy . IslandPolicies . none ) { sb . append ( indent ) . append ( "<STR_LIT>" ) ; } sb . append ( indent ) . append ( "<STR_LIT:)>" ) ; return sb . toString ( ) ; } protected String getNearestSeqWithClause ( QueryData queryData , AnnotateQueryData annoQueryData , List < QueryNode > alternative , String matchesName , String indent ) { String indent2 = indent + TABSTOP ; String indent3 = indent2 + TABSTOP ; SolutionKey < ? > key = createSolutionKey ( ) ; TableAccessStrategy tas = new TableAccessStrategy ( createTableAccessStrategy ( ) ) ; tas . addTableAlias ( "<STR_LIT>" , matchesName ) ; List < String > keyColumns = key . generateOuterQueryColumns ( tas , alternative . size ( ) ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( indent ) . append ( "<STR_LIT>" ) ; sb . append ( indent ) . append ( "<STR_LIT>" ) ; for ( int i = <NUM_LIT:1> ; i <= alternative . size ( ) ; i ++ ) { sb . append ( indent2 ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) ; for ( String k : keyColumns ) { sb . append ( k ) ; } sb . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT:U+0020-U+0020>" ) . append ( annoQueryData . getLeft ( ) ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( annoQueryData . getRight ( ) ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) ; String distLeft = "<STR_LIT>" + i + "<STR_LIT:U+0020-U+0020>" + tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ; String distRight = tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) + "<STR_LIT>" + i ; sb . append ( indent3 ) . append ( "<STR_LIT>" ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( distLeft ) . append ( "<STR_LIT>" ) . append ( distLeft ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( "<STR_LIT>" ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( distRight ) . append ( "<STR_LIT>" ) . append ( distRight ) . append ( "<STR_LIT>" ) ; sb . append ( indent2 ) . append ( "<STR_LIT>" ) . append ( tas . tableName ( NODE_TABLE ) ) . append ( "<STR_LIT>" ) ; sb . append ( indent2 ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( StringUtils . join ( queryData . getCorpusList ( ) , "<STR_LIT:U+002C>" ) ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT:U+0020=U+0020>" ) . append ( sqlString ( annoQueryData . getSegmentationLayer ( ) ) ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( i ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( i ) . append ( "<STR_LIT:n>" ) ; if ( i < alternative . size ( ) ) { sb . append ( "<STR_LIT:n>" ) . append ( indent2 ) . append ( "<STR_LIT>" ) . append ( "<STR_LIT>" ) ; } } sb . append ( indent ) . append ( "<STR_LIT:)>" ) ; return sb . toString ( ) ; } protected String getSolutionFromNearestSegWithClause ( QueryData queryData , AnnotateQueryData annoQueryData , List < QueryNode > alternative , IslandsPolicy . IslandPolicies islandsPolicy , String coveredName , String indent ) { TableAccessStrategy tas = createTableAccessStrategy ( ) ; String indent2 = indent + TABSTOP ; String indent3 = indent2 + TABSTOP ; List < Long > corpusList = queryData . getCorpusList ( ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( indent ) . append ( "<STR_LIT>" ) ; sb . append ( indent ) . append ( "<STR_LIT>" ) ; sb . append ( indent2 ) . append ( "<STR_LIT>" ) ; if ( islandsPolicy == IslandsPolicy . IslandPolicies . none ) { sb . append ( "<STR_LIT>" ) . append ( coveredName ) . append ( "<STR_LIT>" ) . append ( coveredName ) . append ( "<STR_LIT>" ) . append ( "<STR_LIT>" ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( "<STR_LIT>" ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( "<STR_LIT>" ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) ; } else if ( islandsPolicy == IslandsPolicy . IslandPolicies . context ) { sb . append ( coveredName ) . append ( "<STR_LIT>" ) . append ( coveredName ) . append ( "<STR_LIT>" ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) ; } else { throw new UnsupportedOperationException ( "<STR_LIT>" + islandsPolicy . toString ( ) ) ; } sb . append ( indent2 ) . append ( "<STR_LIT>" ) . append ( coveredName ) . append ( "<STR_LIT:U+002CU+0020>" ) . append ( tas . tableName ( NODE_TABLE ) ) . append ( "<STR_LIT:n>" ) ; sb . append ( indent2 ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( StringUtils . join ( corpusList , "<STR_LIT:U+002C>" ) ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT:U+0020=U+0020>" ) . append ( sqlString ( annoQueryData . getSegmentationLayer ( ) ) ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT:U+0020=U+0020>" ) . append ( coveredName ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT:U+0020=U+0020>" ) . append ( coveredName ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( coveredName ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( coveredName ) . append ( "<STR_LIT>" ) ; sb . append ( indent3 ) . append ( "<STR_LIT:(>" ) . append ( coveredName ) . append ( "<STR_LIT>" ) . append ( coveredName ) . append ( "<STR_LIT>" ) ; if ( islandsPolicy == IslandsPolicy . IslandPolicies . none ) { sb . append ( indent2 ) . append ( "<STR_LIT>" ) . append ( tas . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) ; } sb . append ( indent ) . append ( "<STR_LIT>" ) ; return sb . toString ( ) ; } public static String overlapForOneRange ( String indent , String rangeMin , String rangeMax , String textRef , TableAccessStrategy tables ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( indent ) . append ( "<STR_LIT:(>" ) ; sb . append ( tables . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( rangeMax ) . append ( "<STR_LIT>" ) . append ( tables . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT>" ) . append ( rangeMin ) . append ( "<STR_LIT>" ) . append ( tables . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) . append ( "<STR_LIT:U+0020=U+0020>" ) . append ( textRef ) ; sb . append ( "<STR_LIT:)>" ) ; return sb . toString ( ) ; } public AnnotateInnerQuerySqlGenerator getInnerQuerySqlGenerator ( ) { return innerQuerySqlGenerator ; } public void setInnerQuerySqlGenerator ( AnnotateInnerQuerySqlGenerator innerQuerySqlGenerator ) { this . innerQuerySqlGenerator = innerQuerySqlGenerator ; } public IslandsPolicy getIslandsPolicy ( ) { return islandsPolicy ; } public void setIslandsPolicy ( IslandsPolicy islandsPolicy ) { this . islandsPolicy = islandsPolicy ; } } </s>
<s> package annis . sqlgen ; import java . sql . ResultSet ; import java . sql . SQLException ; import org . springframework . jdbc . core . simple . ParameterizedRowMapper ; import annis . service . objects . AnnisCorpus ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class ListCorpusSqlHelper implements ParameterizedRowMapper < AnnisCorpus > { private static final Logger log = LoggerFactory . getLogger ( ListCorpusSqlHelper . class ) ; public String createSqlQuery ( ) { return "<STR_LIT>" ; } public AnnisCorpus mapRow ( ResultSet rs , int rowNum ) throws SQLException { AnnisCorpus corpus = new AnnisCorpus ( ) ; corpus . setId ( rs . getLong ( "<STR_LIT:id>" ) ) ; corpus . setName ( rs . getString ( "<STR_LIT:name>" ) ) ; corpus . setTextCount ( rs . getInt ( "<STR_LIT:text>" ) ) ; corpus . setTokenCount ( rs . getInt ( "<STR_LIT>" ) ) ; try { corpus . setSourcePath ( rs . getString ( "<STR_LIT>" ) ) ; } catch ( SQLException ex ) { log . debug ( null , ex ) ; } return corpus ; } } </s>
<s> package annis . sqlgen ; import java . util . ArrayList ; import java . util . List ; import org . apache . commons . lang3 . StringUtils ; import annis . model . QueryAnnotation ; import annis . model . QueryNode ; public class SubQueryCorpusSelectionStrategy { public String buildSubQuery ( List < Long > corpusList , List < QueryAnnotation > metaData ) { StringBuffer sb = new StringBuffer ( ) ; sb . append ( "<STR_LIT>" ) ; if ( ! corpusList . isEmpty ( ) ) { sb . append ( "<STR_LIT:U+002CU+0020>" ) ; sb . append ( "<STR_LIT>" ) ; } for ( int i = <NUM_LIT:1> ; i <= metaData . size ( ) ; ++ i ) { sb . append ( "<STR_LIT:U+002CU+0020>" ) ; sb . append ( "<STR_LIT>" ) ; sb . append ( i ) ; } if ( hasCorpusSelection ( corpusList , metaData ) ) sb . append ( "<STR_LIT>" ) ; List < String > conditions = new ArrayList < String > ( ) ; if ( ! corpusList . isEmpty ( ) ) { conditions . add ( "<STR_LIT>" ) ; conditions . add ( "<STR_LIT>" ) ; conditions . add ( "<STR_LIT>" . replace ( "<STR_LIT>" , StringUtils . join ( corpusList , "<STR_LIT:U+002CU+0020>" ) ) ) ; } for ( int i = <NUM_LIT:1> ; i <= metaData . size ( ) ; ++ i ) { QueryAnnotation annotation = metaData . get ( i - <NUM_LIT:1> ) ; if ( annotation . getNamespace ( ) != null ) conditions . add ( "<STR_LIT>" + i + "<STR_LIT>" + annotation . getNamespace ( ) + "<STR_LIT:'>" ) ; conditions . add ( "<STR_LIT>" + i + "<STR_LIT>" + annotation . getName ( ) + "<STR_LIT:'>" ) ; if ( annotation . getValue ( ) != null ) { String value = annotation . getValue ( ) ; if ( annotation . getTextMatching ( ) == QueryNode . TextMatching . REGEXP_EQUAL || annotation . getTextMatching ( ) == QueryNode . TextMatching . REGEXP_NOT_EQUAL ) { value = "<STR_LIT>" + value + "<STR_LIT:$>" ; } conditions . add ( "<STR_LIT>" + i + "<STR_LIT>" + annotation . getTextMatching ( ) . sqlOperator ( ) + "<STR_LIT>" + value + "<STR_LIT:'>" ) ; } conditions . add ( "<STR_LIT>" + i + "<STR_LIT>" ) ; } sb . append ( StringUtils . join ( conditions , "<STR_LIT>" ) ) ; return sb . toString ( ) ; } public boolean hasCorpusSelection ( List < Long > corpusList , List < QueryAnnotation > metaData ) { return ! ( corpusList . isEmpty ( ) && metaData . isEmpty ( ) ) ; } } </s>
<s> package annis . sqlgen ; import java . util . Collection ; import org . apache . commons . lang3 . StringEscapeUtils ; import org . apache . commons . lang3 . StringUtils ; import annis . model . QueryNode . TextMatching ; public class SqlConstraints { private static boolean disableBetweenSymmetricPredicate = false ; private static boolean disableBetweenPredicate = false ; public static String isTrue ( String lhs ) { return lhs + "<STR_LIT>" ; } public static String isFalse ( String lhs ) { return lhs + "<STR_LIT>" ; } public static String isNull ( String lhs ) { return lhs + "<STR_LIT>" ; } public static String isNotNull ( String lhs ) { return lhs + "<STR_LIT>" ; } public static String join ( String op , String lhs , String rhs ) { return lhs + "<STR_LIT:U+0020>" + op + "<STR_LIT:U+0020>" + rhs ; } public static String numberJoin ( String op , String lhs , String rhs , int offset ) { String plus = offset >= <NUM_LIT:0> ? "<STR_LIT>" : "<STR_LIT:U+0020-U+0020>" ; return join ( op , lhs , rhs ) + plus + String . valueOf ( Math . abs ( offset ) ) ; } public static String bitSelect ( String column , boolean [ ] bits ) { StringBuilder sbBits = new StringBuilder ( ) ; for ( int i = <NUM_LIT:0> ; i < bits . length ; i ++ ) { sbBits . append ( bits [ i ] ? "<STR_LIT:1>" : "<STR_LIT:0>" ) ; } return "<STR_LIT:(>" + column + "<STR_LIT>" + sbBits . toString ( ) + "<STR_LIT>" + "<STR_LIT>" + sbBits . toString ( ) + "<STR_LIT:'>" ; } public static String between ( String lhs , String rhs , int min , int max ) { if ( ( disableBetweenSymmetricPredicate || disableBetweenPredicate ) && min > max ) { int tmp = min ; min = max ; max = tmp ; } String minPlus = min >= <NUM_LIT:0> ? "<STR_LIT>" : "<STR_LIT:U+0020-U+0020>" ; String maxPlus = max >= <NUM_LIT:0> ? "<STR_LIT>" : "<STR_LIT:U+0020-U+0020>" ; if ( disableBetweenPredicate ) { return lhs + "<STR_LIT>" + rhs + minPlus + String . valueOf ( Math . abs ( min ) ) + "<STR_LIT>" + lhs + "<STR_LIT>" + rhs + maxPlus + String . valueOf ( Math . abs ( max ) ) ; } else { String betweenPredicate = disableBetweenSymmetricPredicate ? "<STR_LIT>" : "<STR_LIT>" ; return lhs + "<STR_LIT:U+0020>" + betweenPredicate + "<STR_LIT:U+0020>" + rhs + minPlus + String . valueOf ( Math . abs ( min ) ) + "<STR_LIT>" + rhs + maxPlus + String . valueOf ( Math . abs ( max ) ) ; } } public static String between ( String lhs , int min , int max ) { if ( ( disableBetweenSymmetricPredicate || disableBetweenPredicate ) && min > max ) { int tmp = min ; min = max ; max = tmp ; } if ( disableBetweenPredicate ) { return lhs + "<STR_LIT>" + min + "<STR_LIT>" + lhs + "<STR_LIT>" + max ; } else { String betweenPredicate = disableBetweenSymmetricPredicate ? "<STR_LIT>" : "<STR_LIT>" ; return lhs + "<STR_LIT:U+0020>" + betweenPredicate + "<STR_LIT:U+0020>" + min + "<STR_LIT>" + max ; } } public static String in ( String lhs , String rhs ) { return lhs + "<STR_LIT>" + rhs + "<STR_LIT:)>" ; } public static String in ( String lhs , Collection < ? > values ) { if ( values . isEmpty ( ) ) { return in ( lhs , "<STR_LIT>" ) ; } else { return in ( lhs , StringUtils . join ( values , "<STR_LIT:U+002C>" ) ) ; } } public static String sqlString ( String string ) { if ( string == null ) { return "<STR_LIT>" ; } else { return "<STR_LIT:'>" + StringUtils . replace ( string , "<STR_LIT:'>" , "<STR_LIT>" ) + "<STR_LIT:'>" ; } } public static String sqlString ( String string , TextMatching textMatching ) { if ( textMatching == TextMatching . REGEXP_EQUAL || textMatching == TextMatching . REGEXP_NOT_EQUAL ) { string = "<STR_LIT>" + string + "<STR_LIT>" ; } return sqlString ( string ) ; } public static boolean isDisableBetweenSymmetricPredicate ( ) { return disableBetweenSymmetricPredicate ; } public static void setDisableBetweenSymmetricPredicate ( boolean disableBetweenPredicate ) { SqlConstraints . disableBetweenSymmetricPredicate = disableBetweenPredicate ; } public static boolean isDisableBetweenPredicate ( ) { return disableBetweenPredicate ; } public static void setDisableBetweenPredicate ( boolean disableBetweenPredicate ) { SqlConstraints . disableBetweenPredicate = disableBetweenPredicate ; } } </s>
<s> package annis . sqlgen ; import static java . util . Arrays . asList ; import java . sql . Array ; import java . sql . ResultSet ; import java . sql . SQLException ; import java . util . Collections ; import java . util . List ; public class ArrayCorpusPathExtractor implements CorpusPathExtractor { @ Override public List < String > extractCorpusPath ( ResultSet resultSet , String columnName ) throws SQLException { Array jdbcArray = resultSet . getArray ( columnName ) ; String [ ] pathArray = ( String [ ] ) jdbcArray . getArray ( ) ; List < String > path = asList ( pathArray ) ; Collections . reverse ( path ) ; return path ; } } </s>
<s> package annis . sqlgen ; import annis . model . QueryNode ; public class DefaultTableAccessStrategy extends TableAccessStrategy { public DefaultTableAccessStrategy ( ) { super ( ) ; } public DefaultTableAccessStrategy ( QueryNode node ) { super ( node ) ; } } </s>
<s> package annis . sqlgen ; import java . util . ArrayList ; import java . util . List ; import org . apache . commons . lang3 . StringUtils ; public class AnnotateQueryData { private int left ; private int right ; private String segmentationLayer ; public AnnotateQueryData ( int left , int right ) { this ( left , right , null ) ; } public AnnotateQueryData ( int left , int right , String segmentationLayer ) { super ( ) ; this . left = left ; this . right = right ; this . segmentationLayer = segmentationLayer ; } public int getLeft ( ) { return left ; } public int getRight ( ) { return right ; } public String getSegmentationLayer ( ) { return segmentationLayer ; } @ Override public String toString ( ) { List < String > fields = new ArrayList < String > ( ) ; if ( left > <NUM_LIT:0> ) { fields . add ( "<STR_LIT>" + left ) ; } if ( right > <NUM_LIT:0> ) { fields . add ( "<STR_LIT>" + right ) ; } if ( segmentationLayer != null ) { fields . add ( "<STR_LIT>" + segmentationLayer ) ; } return StringUtils . join ( fields , "<STR_LIT:U+002CU+0020>" ) ; } } </s>
<s> package annis . sqlgen ; import static annis . model . AnnisConstants . * ; import static annis . sqlgen . TableAccessStrategy . COMPONENT_TABLE ; import static annis . sqlgen . TableAccessStrategy . EDGE_ANNOTATION_TABLE ; import static annis . sqlgen . TableAccessStrategy . NODE_ANNOTATION_TABLE ; import static annis . sqlgen . TableAccessStrategy . NODE_TABLE ; import static annis . sqlgen . TableAccessStrategy . RANK_TABLE ; import java . sql . ResultSet ; import java . sql . SQLException ; import java . util . HashMap ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import java . util . TreeMap ; import org . apache . commons . lang3 . StringUtils ; import org . apache . commons . lang3 . Validate ; import org . eclipse . emf . common . util . EList ; import org . eclipse . emf . common . util . URI ; import org . springframework . dao . DataAccessException ; import de . hu_berlin . german . korpling . saltnpepper . salt . SaltFactory ; import de . hu_berlin . german . korpling . saltnpepper . salt . graph . Edge ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . SaltProject ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . exceptions . SaltException ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SCorpus ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SCorpusGraph ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sCorpusStructure . SDocument ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCommon . sDocumentStructure . * ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SAnnotation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SFeature ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SGraph ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SLayer ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SMetaAnnotation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SNode ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SProcessingAnnotation ; import de . hu_berlin . german . korpling . saltnpepper . salt . saltCore . SRelation ; import org . slf4j . LoggerFactory ; public class SaltAnnotateExtractor implements AnnotateExtractor < SaltProject > { private static final org . slf4j . Logger log = LoggerFactory . getLogger ( SaltAnnotateExtractor . class ) ; private TableAccessStrategy outerQueryTableAccessStrategy ; private CorpusPathExtractor corpusPathExtractor ; public SaltAnnotateExtractor ( ) { } @ Override public SaltProject extractData ( ResultSet resultSet ) throws SQLException , DataAccessException { SaltProject project = SaltFactory . eINSTANCE . createSaltProject ( ) ; try { SCorpusGraph corpusGraph = null ; SDocumentGraph graph = null ; Map < RankID , SNode > nodeByPre = new HashMap < RankID , SNode > ( ) ; TreeMap < Long , String > tokenTexts = new TreeMap < Long , String > ( ) ; TreeMap < Long , SToken > tokenByIndex = new TreeMap < Long , SToken > ( ) ; TreeMap < String , TreeMap < Long , String > > nodeBySegmentationPath = new TreeMap < String , TreeMap < Long , String > > ( ) ; nodeByPre . clear ( ) ; SDocument document = null ; String [ ] keyNameList = new String [ <NUM_LIT:0> ] ; int match_index = <NUM_LIT:0> ; SolutionKey < ? > key = createSolutionKey ( ) ; while ( resultSet . next ( ) ) { key . retrieveKey ( resultSet ) ; if ( key . isNewKey ( ) ) { if ( graph != null && document != null ) { createPrimaryText ( graph , tokenTexts , tokenByIndex ) ; setMatchedIDs ( document , keyNameList ) ; addOrderingRelations ( graph , nodeBySegmentationPath ) ; } nodeByPre . clear ( ) ; tokenTexts . clear ( ) ; tokenByIndex . clear ( ) ; keyNameList = new String [ key . getKeySize ( ) ] ; Integer matchstart = resultSet . getInt ( "<STR_LIT>" ) ; corpusGraph = SaltFactory . eINSTANCE . createSCorpusGraph ( ) ; corpusGraph . setSName ( "<STR_LIT>" + ( match_index + matchstart ) ) ; project . getSCorpusGraphs ( ) . add ( corpusGraph ) ; graph = SaltFactory . eINSTANCE . createSDocumentGraph ( ) ; document = SaltFactory . eINSTANCE . createSDocument ( ) ; List < String > path = corpusPathExtractor . extractCorpusPath ( resultSet , "<STR_LIT:path>" ) ; SCorpus toplevelCorpus = SaltFactory . eINSTANCE . createSCorpus ( ) ; toplevelCorpus . setSName ( path . get ( <NUM_LIT:0> ) ) ; corpusGraph . addSNode ( toplevelCorpus ) ; Validate . isTrue ( path . size ( ) >= <NUM_LIT:2> , "<STR_LIT>" ) ; SCorpus corpus = toplevelCorpus ; for ( int i = <NUM_LIT:1> ; i < path . size ( ) - <NUM_LIT:1> ; i ++ ) { SCorpus subcorpus = SaltFactory . eINSTANCE . createSCorpus ( ) ; subcorpus . setSName ( path . get ( i ) ) ; corpusGraph . addSSubCorpus ( corpus , subcorpus ) ; corpus = subcorpus ; } document . setSName ( path . get ( path . size ( ) - <NUM_LIT:1> ) ) ; corpusGraph . addSDocument ( corpus , document ) ; document . setSDocumentGraph ( graph ) ; match_index ++ ; } SNode node = createOrFindNewNode ( resultSet , graph , tokenTexts , tokenByIndex , nodeBySegmentationPath , key , keyNameList ) ; long pre = longValue ( resultSet , RANK_TABLE , "<STR_LIT>" ) ; long componentID = longValue ( resultSet , RANK_TABLE , "<STR_LIT>" ) ; if ( ! resultSet . wasNull ( ) ) { nodeByPre . put ( new RankID ( componentID , pre ) , node ) ; createRelation ( resultSet , graph , nodeByPre , node ) ; } } if ( graph != null ) { createPrimaryText ( graph , tokenTexts , tokenByIndex ) ; setMatchedIDs ( document , keyNameList ) ; addOrderingRelations ( graph , nodeBySegmentationPath ) ; } } catch ( Exception ex ) { log . error ( "<STR_LIT>" , ex ) ; } return project ; } private void addOrderingRelations ( SDocumentGraph graph , TreeMap < String , TreeMap < Long , String > > nodeBySegmentationPath ) { for ( Map . Entry < String , TreeMap < Long , String > > e : nodeBySegmentationPath . entrySet ( ) ) { TreeMap < Long , String > nodeBySegIndex = e . getValue ( ) ; SNode lastNode = null ; for ( String nodeID : nodeBySegIndex . values ( ) ) { SNode n = graph . getSNode ( nodeID ) ; if ( lastNode != null && n != null ) { SOrderRelation orderRel = SaltFactory . eINSTANCE . createSOrderRelation ( ) ; orderRel . setSSource ( lastNode ) ; orderRel . setSTarget ( n ) ; orderRel . addSType ( e . getKey ( ) ) ; graph . addSRelation ( orderRel ) ; } lastNode = n ; } } } private void setMatchedIDs ( SDocument document , String [ ] keyNameList ) { SFeature feature = SaltFactory . eINSTANCE . createSFeature ( ) ; feature . setSNS ( ANNIS_NS ) ; feature . setSName ( FEAT_MATCHEDIDS ) ; String val = StringUtils . join ( keyNameList , "<STR_LIT:U+002C>" ) ; feature . setSValue ( val ) ; document . addSFeature ( feature ) ; } private void createPrimaryText ( SDocumentGraph graph , TreeMap < Long , String > tokenTexts , TreeMap < Long , SToken > tokenByIndex ) { STextualDS textDataSource = SaltFactory . eINSTANCE . createSTextualDS ( ) ; graph . addSNode ( textDataSource ) ; StringBuilder sbText = new StringBuilder ( ) ; Iterator < Map . Entry < Long , String > > itToken = tokenTexts . entrySet ( ) . iterator ( ) ; while ( itToken . hasNext ( ) ) { Map . Entry < Long , String > e = itToken . next ( ) ; SToken tok = tokenByIndex . get ( e . getKey ( ) ) ; STextualRelation textRel = SaltFactory . eINSTANCE . createSTextualRelation ( ) ; textRel . setSSource ( tok ) ; textRel . setSTarget ( textDataSource ) ; textRel . setSStart ( sbText . length ( ) ) ; textRel . setSEnd ( sbText . length ( ) + e . getValue ( ) . length ( ) ) ; textRel . setSTextualDS ( textDataSource ) ; graph . addSRelation ( textRel ) ; sbText . append ( e . getValue ( ) ) ; if ( itToken . hasNext ( ) ) { sbText . append ( "<STR_LIT:U+0020>" ) ; } } textDataSource . setSText ( sbText . toString ( ) ) ; } private SNode createOrFindNewNode ( ResultSet resultSet , SDocumentGraph graph , TreeMap < Long , String > tokenTexts , TreeMap < Long , SToken > tokenByIndex , TreeMap < String , TreeMap < Long , String > > nodeBySegmentationPath , SolutionKey < ? > key , String [ ] keyNameList ) throws SQLException { String name = stringValue ( resultSet , NODE_TABLE , "<STR_LIT>" ) ; long internalID = longValue ( resultSet , "<STR_LIT>" , "<STR_LIT:id>" ) ; long tokenIndex = longValue ( resultSet , NODE_TABLE , "<STR_LIT>" ) ; boolean isToken = ! resultSet . wasNull ( ) ; URI nodeURI = graph . getSElementPath ( ) ; nodeURI = nodeURI . appendFragment ( name ) ; SStructuredNode node = ( SStructuredNode ) graph . getSNode ( nodeURI . toString ( ) ) ; if ( node == null ) { if ( isToken ) { SToken tok = SaltFactory . eINSTANCE . createSToken ( ) ; node = tok ; tokenTexts . put ( tokenIndex , stringValue ( resultSet , NODE_TABLE , "<STR_LIT>" ) ) ; tokenByIndex . put ( tokenIndex , tok ) ; } else { SStructure struct = SaltFactory . eINSTANCE . createSStructure ( ) ; node = struct ; } node . setSName ( name ) ; graph . addNode ( node ) ; addLongSFeature ( node , FEAT_INTERNALID , internalID ) ; addLongSFeature ( node , resultSet , FEAT_CORPUSREF , "<STR_LIT>" , "<STR_LIT>" ) ; addLongSFeature ( node , resultSet , FEAT_TEXTREF , "<STR_LIT>" , "<STR_LIT>" ) ; addLongSFeature ( node , resultSet , FEAT_LEFT , "<STR_LIT>" , "<STR_LIT>" ) ; addLongSFeature ( node , resultSet , FEAT_LEFTTOKEN , "<STR_LIT>" , "<STR_LIT>" ) ; addLongSFeature ( node , resultSet , FEAT_RIGHT , "<STR_LIT>" , "<STR_LIT>" ) ; addLongSFeature ( node , resultSet , FEAT_RIGHTTOKEN , "<STR_LIT>" , "<STR_LIT>" ) ; addLongSFeature ( node , resultSet , FEAT_TOKENINDEX , "<STR_LIT>" , "<STR_LIT>" ) ; addLongSFeature ( node , resultSet , FEAT_SEGLEFT , "<STR_LIT>" , "<STR_LIT>" ) ; addLongSFeature ( node , resultSet , FEAT_SEGRIGHT , "<STR_LIT>" , "<STR_LIT>" ) ; addStringSFeature ( node , resultSet , FEAT_SEGNAME , "<STR_LIT>" , "<STR_LIT>" ) ; Object nodeId = key . getNodeId ( resultSet , outerQueryTableAccessStrategy ) ; Integer matchedNode = key . getMatchedNodeIndex ( nodeId ) ; if ( matchedNode != null ) { addLongSFeature ( node , FEAT_MATCHEDNODE , matchedNode ) ; keyNameList [ matchedNode - <NUM_LIT:1> ] = node . getSName ( ) ; } String namespace = stringValue ( resultSet , NODE_TABLE , "<STR_LIT>" ) ; EList < SLayer > layerList = graph . getSLayerByName ( namespace ) ; SLayer layer = ( layerList != null && layerList . size ( ) > <NUM_LIT:0> ) ? layerList . get ( <NUM_LIT:0> ) : null ; if ( layer == null ) { layer = SaltFactory . eINSTANCE . createSLayer ( ) ; layer . setSName ( namespace ) ; graph . addSLayer ( layer ) ; } node . getSLayers ( ) . add ( layer ) ; } String nodeAnnoValue = stringValue ( resultSet , NODE_ANNOTATION_TABLE , "<STR_LIT:value>" ) ; String nodeAnnoNameSpace = stringValue ( resultSet , NODE_ANNOTATION_TABLE , "<STR_LIT>" ) ; String nodeAnnoName = stringValue ( resultSet , NODE_ANNOTATION_TABLE , "<STR_LIT:name>" ) ; if ( ! resultSet . wasNull ( ) ) { String fullName = ( nodeAnnoNameSpace == null ? "<STR_LIT>" : ( nodeAnnoNameSpace + "<STR_LIT>" ) ) + nodeAnnoName ; SAnnotation anno = node . getSAnnotation ( fullName ) ; if ( anno == null ) { anno = SaltFactory . eINSTANCE . createSAnnotation ( ) ; anno . setSNS ( nodeAnnoNameSpace ) ; anno . setSName ( nodeAnnoName ) ; anno . setSValue ( nodeAnnoValue ) ; node . addSAnnotation ( anno ) ; } } String segName = stringValue ( resultSet , "<STR_LIT>" , "<STR_LIT>" ) ; if ( segName != null ) { long left = longValue ( resultSet , "<STR_LIT>" , "<STR_LIT>" ) ; long right = longValue ( resultSet , "<STR_LIT>" , "<STR_LIT>" ) ; if ( left == right ) { if ( ! nodeBySegmentationPath . containsKey ( segName ) ) { nodeBySegmentationPath . put ( segName , new TreeMap < Long , String > ( ) ) ; } nodeBySegmentationPath . get ( segName ) . put ( left , node . getSId ( ) ) ; } } return node ; } private void addLongSFeature ( SNode node , String name , long value ) throws SQLException { SFeature feat = SaltFactory . eINSTANCE . createSFeature ( ) ; feat . setSNS ( ANNIS_NS ) ; feat . setSName ( name ) ; feat . setSValue ( value ) ; node . addSFeature ( feat ) ; } private void addStringSFeature ( SNode node , String name , String value ) throws SQLException { SFeature feat = SaltFactory . eINSTANCE . createSFeature ( ) ; feat . setSNS ( ANNIS_NS ) ; feat . setSName ( name ) ; feat . setSValue ( value ) ; node . addSFeature ( feat ) ; } private void addLongSFeature ( SNode node , ResultSet resultSet , String name , String table , String tupleName ) throws SQLException { addLongSFeature ( node , name , longValue ( resultSet , table , tupleName ) ) ; } private void addStringSFeature ( SNode node , ResultSet resultSet , String name , String table , String tupleName ) throws SQLException { addStringSFeature ( node , name , stringValue ( resultSet , table , tupleName ) ) ; } private SStructuredNode recreateNode ( Class < ? extends SStructuredNode > clazz , SStructuredNode oldNode ) { if ( oldNode . getClass ( ) == clazz ) { return oldNode ; } SStructuredNode node = oldNode ; if ( clazz == SSpan . class ) { node = SaltFactory . eINSTANCE . createSSpan ( ) ; } else if ( clazz == SStructure . class ) { node = SaltFactory . eINSTANCE . createSStructure ( ) ; } else { throw new UnsupportedOperationException ( "<STR_LIT>" + clazz . getName ( ) ) ; } moveNodeProperties ( oldNode , node , oldNode . getSGraph ( ) ) ; return node ; } private void moveNodeProperties ( SStructuredNode from , SStructuredNode to , SGraph graph ) { Validate . notNull ( from ) ; Validate . notNull ( to ) ; to . setSName ( from . getSName ( ) ) ; for ( SLayer l : from . getSLayers ( ) ) { to . getSLayers ( ) . add ( l ) ; } from . getSLayers ( ) . clear ( ) ; Validate . isTrue ( graph . removeNode ( from ) ) ; graph . addNode ( to ) ; for ( SAnnotation anno : from . getSAnnotations ( ) ) { to . addSAnnotation ( anno ) ; } for ( SFeature feat : from . getSFeatures ( ) ) { if ( ! ( SaltFactory . SALT_CORE_NAMESPACE . equals ( feat . getSNS ( ) ) && SaltFactory . SALT_CORE_SFEATURES . SNAME . toString ( ) . equals ( feat . getSName ( ) ) ) ) { to . addSFeature ( feat ) ; } } for ( SProcessingAnnotation proc : from . getSProcessingAnnotations ( ) ) { to . addSProcessingAnnotation ( proc ) ; } for ( SMetaAnnotation meta : from . getSMetaAnnotations ( ) ) { to . addSMetaAnnotation ( meta ) ; } } private SRelation findExistingRelation ( SDocumentGraph graph , SNode sourceNode , SNode targetNode , String edgeName , SLayer layer ) { SRelation rel = null ; EList < Edge > existingEdges = graph . getEdges ( sourceNode . getSId ( ) , targetNode . getSId ( ) ) ; if ( existingEdges != null ) { for ( Edge e : existingEdges ) { if ( e instanceof SRelation ) { SRelation existingRel = ( SRelation ) e ; boolean noType = existingRel . getSTypes ( ) == null || existingRel . getSTypes ( ) . size ( ) == <NUM_LIT:0> ; if ( ( ( noType && edgeName == null ) || ( ! noType && existingRel . getSTypes ( ) . contains ( edgeName ) ) ) && existingRel . getSLayers ( ) . contains ( layer ) ) { rel = existingRel ; break ; } } } } return rel ; } private SRelation createNewRelation ( SDocumentGraph graph , SStructuredNode sourceNode , SNode targetNode , String edgeName , String type , long componentID , SLayer layer , long parent , long pre , Map < RankID , SNode > nodeByPre ) { SRelation rel = null ; if ( "<STR_LIT:d>" . equals ( type ) ) { SDominanceRelation domrel = SaltFactory . eINSTANCE . createSDominanceRelation ( ) ; rel = domrel ; if ( sourceNode != null && ! ( sourceNode instanceof SStructure ) ) { sourceNode = recreateNode ( SStructure . class , sourceNode ) ; nodeByPre . put ( new RankID ( componentID , parent ) , sourceNode ) ; } } else if ( "<STR_LIT:c>" . equals ( type ) ) { SSpanningRelation spanrel = SaltFactory . eINSTANCE . createSSpanningRelation ( ) ; rel = spanrel ; if ( sourceNode != null && ! ( sourceNode instanceof SSpan ) ) { sourceNode = recreateNode ( SSpan . class , sourceNode ) ; nodeByPre . put ( new RankID ( componentID , parent ) , sourceNode ) ; } } else if ( "<STR_LIT:p>" . equals ( type ) ) { SPointingRelation pointingrel = SaltFactory . eINSTANCE . createSPointingRelation ( ) ; rel = pointingrel ; } else { throw new IllegalArgumentException ( "<STR_LIT>" + type + "<STR_LIT>" ) ; } try { rel . getSLayers ( ) . add ( layer ) ; rel . addSType ( edgeName ) ; SFeature featInternalID = SaltFactory . eINSTANCE . createSFeature ( ) ; featInternalID . setSNS ( ANNIS_NS ) ; featInternalID . setSName ( FEAT_INTERNALID ) ; featInternalID . setSValue ( Long . valueOf ( pre ) ) ; rel . addSFeature ( featInternalID ) ; SFeature featComponentID = SaltFactory . eINSTANCE . createSFeature ( ) ; featComponentID . setSNS ( ANNIS_NS ) ; featComponentID . setSName ( FEAT_COMPONENTID ) ; featComponentID . setSValue ( Long . valueOf ( componentID ) ) ; rel . addSFeature ( featComponentID ) ; rel . setSSource ( nodeByPre . get ( new RankID ( componentID , parent ) ) ) ; if ( "<STR_LIT:c>" . equals ( type ) && ! ( targetNode instanceof SToken ) ) { log . warn ( "<STR_LIT>" + "<STR_LIT>" , new Object [ ] { targetNode . getSName ( ) , sourceNode . getSName ( ) , "<STR_LIT>" + pre } ) ; } else { rel . setSTarget ( targetNode ) ; graph . addSRelation ( rel ) ; } } catch ( SaltException ex ) { log . warn ( "<STR_LIT>" , ex ) ; } return rel ; } private void addEdgeAnnotations ( ResultSet resultSet , SRelation rel ) throws SQLException { String edgeAnnoValue = stringValue ( resultSet , EDGE_ANNOTATION_TABLE , "<STR_LIT:value>" ) ; String edgeAnnoNameSpace = stringValue ( resultSet , EDGE_ANNOTATION_TABLE , "<STR_LIT>" ) ; String edgeAnnoName = stringValue ( resultSet , EDGE_ANNOTATION_TABLE , "<STR_LIT:name>" ) ; if ( ! resultSet . wasNull ( ) ) { String fullName = edgeAnnoNameSpace == null ? "<STR_LIT>" : edgeAnnoNameSpace + "<STR_LIT>" + edgeAnnoName ; SAnnotation anno = rel . getSAnnotation ( fullName ) ; if ( anno == null ) { anno = SaltFactory . eINSTANCE . createSAnnotation ( ) ; anno . setSNS ( edgeAnnoNameSpace == null ? "<STR_LIT>" : edgeAnnoNameSpace ) ; anno . setSName ( edgeAnnoName ) ; anno . setSValue ( edgeAnnoValue ) ; rel . addSAnnotation ( anno ) ; } } } private SRelation createRelation ( ResultSet resultSet , SDocumentGraph graph , Map < RankID , SNode > nodeByPre , SNode targetNode ) throws SQLException { long parent = longValue ( resultSet , RANK_TABLE , "<STR_LIT>" ) ; if ( resultSet . wasNull ( ) ) { return null ; } long pre = longValue ( resultSet , RANK_TABLE , "<STR_LIT>" ) ; long componentID = longValue ( resultSet , RANK_TABLE , "<STR_LIT>" ) ; String edgeNamespace = stringValue ( resultSet , COMPONENT_TABLE , "<STR_LIT>" ) ; String edgeName = stringValue ( resultSet , COMPONENT_TABLE , "<STR_LIT:name>" ) ; String type = stringValue ( resultSet , COMPONENT_TABLE , "<STR_LIT:type>" ) ; SStructuredNode sourceNode = ( SStructuredNode ) nodeByPre . get ( new RankID ( componentID , parent ) ) ; if ( sourceNode == null ) { return null ; } EList < SLayer > layerList = graph . getSLayerByName ( edgeNamespace ) ; SLayer layer = ( layerList != null && layerList . size ( ) > <NUM_LIT:0> ) ? layerList . get ( <NUM_LIT:0> ) : null ; if ( layer == null ) { layer = SaltFactory . eINSTANCE . createSLayer ( ) ; layer . setSName ( edgeNamespace ) ; graph . addSLayer ( layer ) ; } SRelation rel = null ; if ( ! resultSet . wasNull ( ) ) { rel = findExistingRelation ( graph , sourceNode , targetNode , edgeName , layer ) ; if ( rel == null ) { rel = createNewRelation ( graph , sourceNode , targetNode , edgeName , type , componentID , layer , parent , pre , nodeByPre ) ; } addEdgeAnnotations ( resultSet , rel ) ; } return rel ; } protected SolutionKey < ? > createSolutionKey ( ) { throw new UnsupportedOperationException ( "<STR_LIT>" ) ; } protected void newline ( StringBuilder sb , int indentBy ) { sb . append ( "<STR_LIT:n>" ) ; indent ( sb , indentBy ) ; } protected void indent ( StringBuilder sb , int indentBy ) { sb . append ( StringUtils . repeat ( AbstractSqlGenerator . TABSTOP , indentBy ) ) ; } protected long longValue ( ResultSet resultSet , String table , String column ) throws SQLException { return resultSet . getLong ( outerQueryTableAccessStrategy . columnName ( table , column ) ) ; } protected String stringValue ( ResultSet resultSet , String table , String column ) throws SQLException { return resultSet . getString ( outerQueryTableAccessStrategy . columnName ( table , column ) ) ; } public CorpusPathExtractor getCorpusPathExtractor ( ) { return corpusPathExtractor ; } public void setCorpusPathExtractor ( CorpusPathExtractor corpusPathExtractor ) { this . corpusPathExtractor = corpusPathExtractor ; } public TableAccessStrategy getOuterQueryTableAccessStrategy ( ) { return outerQueryTableAccessStrategy ; } @ Override public void setOuterQueryTableAccessStrategy ( TableAccessStrategy outerQueryTableAccessStrategy ) { this . outerQueryTableAccessStrategy = outerQueryTableAccessStrategy ; } public static class RankID { private long componentID ; private long pre ; public RankID ( long componentID , long pre ) { this . componentID = componentID ; this . pre = pre ; } public long getComponentID ( ) { return componentID ; } public long getPre ( ) { return pre ; } @ Override public boolean equals ( Object obj ) { if ( obj == null ) { return false ; } if ( getClass ( ) != obj . getClass ( ) ) { return false ; } final RankID other = ( RankID ) obj ; if ( this . componentID != other . componentID ) { return false ; } if ( this . pre != other . pre ) { return false ; } return true ; } @ Override public int hashCode ( ) { int hash = <NUM_LIT:5> ; hash = <NUM_LIT> * hash + ( int ) ( this . componentID ^ ( this . componentID > > > <NUM_LIT:32> ) ) ; hash = <NUM_LIT> * hash + ( int ) ( this . pre ^ ( this . pre > > > <NUM_LIT:32> ) ) ; return hash ; } } } </s>
<s> package annis . sqlgen ; import static annis . sqlgen . TableAccessStrategy . EDGE_ANNOTATION_TABLE ; import static annis . sqlgen . TableAccessStrategy . NODE_ANNOTATION_TABLE ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import annis . model . QueryNode ; import annis . model . QueryAnnotation ; import annis . ql . parser . QueryData ; import annis . sqlgen . model . CommonAncestor ; import annis . sqlgen . model . Dominance ; import annis . sqlgen . model . Identical ; import annis . sqlgen . model . Inclusion ; import annis . sqlgen . model . Join ; import annis . sqlgen . model . LeftAlignment ; import annis . sqlgen . model . LeftDominance ; import annis . sqlgen . model . LeftOverlap ; import annis . sqlgen . model . Overlap ; import annis . sqlgen . model . PointingRelation ; import annis . sqlgen . model . Precedence ; import annis . sqlgen . model . RightAlignment ; import annis . sqlgen . model . RightDominance ; import annis . sqlgen . model . RightOverlap ; import annis . sqlgen . model . SameSpan ; import annis . sqlgen . model . Sibling ; public abstract class AbstractWhereClauseGenerator extends TableAccessStrategyFactory implements WhereClauseSqlGenerator < QueryData > { @ Override public Set < String > whereConditions ( QueryData queryData , List < QueryNode > alternative , String indent ) { List < String > conditions = new ArrayList < String > ( ) ; for ( QueryNode node : alternative ) { if ( node . getSpannedText ( ) != null ) { addSpanConditions ( conditions , queryData , node ) ; } if ( node . isToken ( ) ) { addIsTokenConditions ( conditions , queryData , node ) ; } if ( node . isRoot ( ) ) { addIsRootConditions ( conditions , queryData , node ) ; } if ( node . getNamespace ( ) != null ) { addNodeNamespaceConditions ( conditions , queryData , node ) ; } if ( node . getName ( ) != null ) { addNodeNameCondition ( conditions , queryData , node ) ; } if ( node . getArity ( ) != null ) { addNodeArityConditions ( conditions , queryData , node ) ; } if ( node . getTokenArity ( ) != null ) { addTokenArityConditions ( conditions , queryData , node ) ; } for ( Join join : node . getJoins ( ) ) { QueryNode target = join . getTarget ( ) ; if ( join instanceof SameSpan ) { addSameSpanConditions ( conditions , node , target , ( SameSpan ) join , queryData ) ; } else if ( join instanceof Identical ) { addIdenticalConditions ( conditions , node , target , ( Identical ) join , queryData ) ; } else if ( join instanceof LeftAlignment ) { addLeftAlignmentConditions ( conditions , node , target , ( LeftAlignment ) join , queryData ) ; } else if ( join instanceof RightAlignment ) { addRightAlignmentConditions ( conditions , node , target , ( RightAlignment ) join , queryData ) ; } else if ( join instanceof Inclusion ) { addInclusionConditions ( conditions , node , target , ( Inclusion ) join , queryData ) ; } else if ( join instanceof Overlap ) { addOverlapConditions ( conditions , node , target , ( Overlap ) join , queryData ) ; } else if ( join instanceof LeftOverlap ) { addLeftOverlapConditions ( conditions , target , node , ( LeftOverlap ) join , queryData ) ; } else if ( join instanceof RightOverlap ) { addRightOverlapConditions ( conditions , target , node , ( RightOverlap ) join , queryData ) ; } else if ( join instanceof Precedence ) { addPrecedenceConditions ( conditions , node , target , ( Precedence ) join , queryData ) ; } else if ( join instanceof Sibling ) { addSiblingConditions ( conditions , node , target , ( Sibling ) join , queryData ) ; } else if ( join instanceof CommonAncestor ) { addCommonAncestorConditions ( conditions , node , target , ( CommonAncestor ) join , queryData ) ; } else if ( join instanceof LeftDominance ) { addLeftDominanceConditions ( conditions , node , target , ( LeftDominance ) join , queryData ) ; } else if ( join instanceof RightDominance ) { addRightDominanceConditions ( conditions , node , target , ( RightDominance ) join , queryData ) ; } else if ( join instanceof Dominance ) { addDominanceConditions ( conditions , node , target , ( Dominance ) join , queryData ) ; } else if ( join instanceof PointingRelation ) { addPointingRelationConditions ( conditions , node , target , ( PointingRelation ) join , queryData ) ; } } int i = <NUM_LIT:0> ; for ( QueryAnnotation annotation : node . getNodeAnnotations ( ) ) { ++ i ; addAnnotationConditions ( conditions , node , i , annotation , NODE_ANNOTATION_TABLE , queryData ) ; } int j = <NUM_LIT:0> ; for ( QueryAnnotation annotation : node . getEdgeAnnotations ( ) ) { ++ j ; addAnnotationConditions ( conditions , node , j , annotation , EDGE_ANNOTATION_TABLE , queryData ) ; } } return new HashSet < String > ( conditions ) ; } protected abstract void addSpanConditions ( List < String > conditions , QueryData queryData , QueryNode node ) ; protected abstract void addIsTokenConditions ( List < String > conditions , QueryData queryData , QueryNode node ) ; protected abstract void addIsRootConditions ( List < String > conditions , QueryData queryData , QueryNode node ) ; protected abstract void addNodeNamespaceConditions ( List < String > conditions , QueryData queryData , QueryNode node ) ; protected abstract void addNodeNameCondition ( List < String > conditions , QueryData queryData , QueryNode node ) ; protected abstract void addNodeArityConditions ( List < String > conditions , QueryData queryData , QueryNode node ) ; protected abstract void addTokenArityConditions ( List < String > conditions , QueryData queryData , QueryNode node ) ; protected abstract void addSingleEdgeCondition ( QueryNode node , QueryNode target , List < String > conditions , Join join , final String edgeType ) ; protected abstract void addSiblingConditions ( List < String > conditions , QueryNode node , QueryNode target , Sibling join , QueryData queryData ) ; protected abstract void addCommonAncestorConditions ( List < String > conditions , QueryNode node , QueryNode target , CommonAncestor join , QueryData queryData ) ; protected abstract void addSameSpanConditions ( List < String > conditions , QueryNode node , QueryNode target , SameSpan join , QueryData queryData ) ; protected abstract void addIdenticalConditions ( List < String > conditions , QueryNode node , QueryNode target , Identical join , QueryData queryData ) ; protected abstract void addLeftAlignmentConditions ( List < String > conditions , QueryNode node , QueryNode target , LeftAlignment join , QueryData queryData ) ; protected abstract void addRightAlignmentConditions ( List < String > conditions , QueryNode node , QueryNode target , RightAlignment join , QueryData queryData ) ; protected abstract void addInclusionConditions ( List < String > conditions , QueryNode node , QueryNode target , Inclusion join , QueryData queryData ) ; protected abstract void addOverlapConditions ( List < String > conditions , QueryNode node , QueryNode target , Overlap join , QueryData queryData ) ; protected abstract void addLeftOverlapConditions ( List < String > conditions , QueryNode target , QueryNode node , LeftOverlap join , QueryData queryData ) ; protected abstract void addRightOverlapConditions ( List < String > conditions , QueryNode target , QueryNode node , RightOverlap join , QueryData queryData ) ; protected abstract void addPrecedenceConditions ( List < String > conditions , QueryNode node , QueryNode target , Precedence join , QueryData queryData ) ; protected abstract void addAnnotationConditions ( List < String > conditions , QueryNode node , int index , QueryAnnotation annotation , String table , QueryData queryData ) ; protected abstract void addLeftDominanceConditions ( List < String > conditions , QueryNode node , QueryNode target , LeftDominance join , QueryData queryData ) ; protected abstract void addRightDominanceConditions ( List < String > conditions , QueryNode node , QueryNode target , RightDominance join , QueryData queryData ) ; protected abstract void addDominanceConditions ( List < String > conditions , QueryNode node , QueryNode target , Dominance join , QueryData queryData ) ; protected abstract void addPointingRelationConditions ( List < String > conditions , QueryNode node , QueryNode target , PointingRelation join , QueryData queryData ) ; } </s>
<s> package annis . sqlgen ; import java . util . List ; public interface NodeSqlAdapter { String selectClause ( ) ; String selectClauseNullValues ( ) ; String fromClause ( ) ; List < String > whereClause ( ) ; } </s>
<s> package annis . sqlgen ; import static annis . sqlgen . SqlConstraints . between ; import static annis . sqlgen . SqlConstraints . in ; import static annis . sqlgen . SqlConstraints . isNotNull ; import static annis . sqlgen . SqlConstraints . isNull ; import static annis . sqlgen . SqlConstraints . isTrue ; import static annis . sqlgen . SqlConstraints . join ; import static annis . sqlgen . SqlConstraints . numberJoin ; import static annis . sqlgen . SqlConstraints . sqlString ; import static annis . sqlgen . TableAccessStrategy . COMPONENT_TABLE ; import static annis . sqlgen . TableAccessStrategy . FACTS_TABLE ; import static annis . sqlgen . TableAccessStrategy . NODE_TABLE ; import static annis . sqlgen . TableAccessStrategy . RANK_TABLE ; import java . util . List ; import org . apache . commons . lang3 . StringUtils ; import annis . model . QueryAnnotation ; import annis . model . QueryNode ; import annis . model . QueryNode . TextMatching ; import annis . ql . parser . QueryData ; import annis . sqlgen . model . CommonAncestor ; import annis . sqlgen . model . Dominance ; import annis . sqlgen . model . Identical ; import annis . sqlgen . model . Inclusion ; import annis . sqlgen . model . Join ; import annis . sqlgen . model . LeftAlignment ; import annis . sqlgen . model . LeftDominance ; import annis . sqlgen . model . LeftOverlap ; import annis . sqlgen . model . Overlap ; import annis . sqlgen . model . PointingRelation ; import annis . sqlgen . model . Precedence ; import annis . sqlgen . model . RangedJoin ; import annis . sqlgen . model . RankTableJoin ; import annis . sqlgen . model . RightAlignment ; import annis . sqlgen . model . RightDominance ; import annis . sqlgen . model . RightOverlap ; import annis . sqlgen . model . SameSpan ; import annis . sqlgen . model . Sibling ; public class DefaultWhereClauseGenerator extends AbstractWhereClauseGenerator { private boolean optimizeIndirectPrecedence ; private boolean allowIdenticalSibling ; private boolean optimizeInclusion ; private String componentPredicates ; private boolean useIsTokenColumn ; private boolean useToplevelCorpusPredicateInCommonAncestorSubquery ; private boolean useComponentRefPredicateInCommonAncestorSubquery ; private AnnotationConditionProvider annoCondition ; private void addComponentPredicates ( List < String > conditions , QueryNode node , final String edgeType , String componentName ) { conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( COMPONENT_TABLE , "<STR_LIT:type>" ) , sqlString ( edgeType ) ) ) ; if ( componentName == null ) { conditions . add ( isNull ( tables ( node ) . aliasedColumn ( COMPONENT_TABLE , "<STR_LIT:name>" ) ) ) ; } else { conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( COMPONENT_TABLE , "<STR_LIT:name>" ) , sqlString ( componentName ) ) ) ; } } private void addComponentPredicates ( List < String > conditions , QueryNode node , QueryNode target , String componentName , String edgeType ) { conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( COMPONENT_TABLE , "<STR_LIT:id>" ) , tables ( target ) . aliasedColumn ( COMPONENT_TABLE , "<STR_LIT:id>" ) ) ) ; if ( "<STR_LIT>" . equals ( componentPredicates ) || "<STR_LIT>" . equals ( componentPredicates ) ) { addComponentPredicates ( conditions , node , edgeType , componentName ) ; } if ( "<STR_LIT>" . equals ( componentPredicates ) || "<STR_LIT>" . equals ( componentPredicates ) ) { addComponentPredicates ( conditions , target , edgeType , componentName ) ; } } @ Override protected void addPointingRelationConditions ( List < String > conditions , QueryNode node , QueryNode target , PointingRelation join , QueryData queryData ) { addSingleEdgeCondition ( node , target , conditions , join , "<STR_LIT:p>" ) ; } @ Override protected void addDominanceConditions ( List < String > conditions , QueryNode node , QueryNode target , Dominance join , QueryData queryData ) { addSingleEdgeCondition ( node , target , conditions , join , "<STR_LIT:d>" ) ; } @ Override protected void addRightDominanceConditions ( List < String > conditions , QueryNode node , QueryNode target , RightDominance join , QueryData queryData ) { addLeftOrRightDominance ( conditions , node , target , queryData , join , "<STR_LIT>" , "<STR_LIT>" ) ; } @ Override protected void addLeftDominanceConditions ( List < String > conditions , QueryNode node , QueryNode target , LeftDominance join , QueryData queryData ) { addLeftOrRightDominance ( conditions , node , target , queryData , join , "<STR_LIT>" , "<STR_LIT>" ) ; } protected void addLeftOrRightDominance ( List < String > conditions , QueryNode node , QueryNode target , QueryData queryData , RankTableJoin join , String aggregationFunction , String tokenBoarder ) { RankTableJoin rankTableJoin = ( RankTableJoin ) join ; String componentName = rankTableJoin . getName ( ) ; addComponentPredicates ( conditions , node , target , componentName , "<STR_LIT:d>" ) ; TableAccessStrategy tas = tables ( null ) ; conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , tables ( target ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) ) ) ; List < Long > corpusList = queryData . getCorpusList ( ) ; boolean doJoin = ! tas . isMaterialized ( NODE_TABLE , RANK_TABLE ) ; String innerSelect = "<STR_LIT>" + aggregationFunction + "<STR_LIT>" + tokenBoarder + "<STR_LIT>" ; if ( doJoin ) { innerSelect += tas . tableName ( NODE_TABLE ) + "<STR_LIT>" + tas . tableName ( RANK_TABLE ) + "<STR_LIT>" ; } else { innerSelect += tas . tableName ( RANK_TABLE ) + "<STR_LIT>" ; } innerSelect += "<STR_LIT>" + tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) + "<STR_LIT>" + tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) + "<STR_LIT>" + tables ( target ) . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) + "<STR_LIT>" + ( corpusList == null || corpusList . isEmpty ( ) ? "<STR_LIT>" : StringUtils . join ( corpusList , "<STR_LIT:U+002C>" ) ) + "<STR_LIT:)>" ; if ( doJoin ) { innerSelect += "<STR_LIT>" + ( corpusList == null || corpusList . isEmpty ( ) ? "<STR_LIT>" : StringUtils . join ( corpusList , "<STR_LIT:U+002C>" ) ) + "<STR_LIT:)>" + "<STR_LIT>" ; } conditions . add ( in ( tables ( target ) . aliasedColumn ( NODE_TABLE , tokenBoarder ) , innerSelect ) ) ; } void joinOnNode ( List < String > conditions , QueryNode node , QueryNode target , String operator , String leftColumn , String rightColumn ) { conditions . add ( join ( operator , tables ( node ) . aliasedColumn ( NODE_TABLE , leftColumn ) , tables ( target ) . aliasedColumn ( NODE_TABLE , rightColumn ) ) ) ; } void betweenJoinOnNode ( List < String > conditions , QueryNode node , QueryNode target , String leftColumn , String rightColumn , int min , int max ) { conditions . add ( between ( tables ( node ) . aliasedColumn ( NODE_TABLE , leftColumn ) , tables ( target ) . aliasedColumn ( NODE_TABLE , rightColumn ) , min , max ) ) ; } void numberJoinOnNode ( List < String > conditions , QueryNode node , QueryNode target , String operator , String leftColumn , String rightColumn , int offset ) { conditions . add ( numberJoin ( operator , tables ( node ) . aliasedColumn ( NODE_TABLE , leftColumn ) , tables ( target ) . aliasedColumn ( NODE_TABLE , rightColumn ) , offset ) ) ; } @ Override protected void addAnnotationConditions ( List < String > conditions , QueryNode node , int index , QueryAnnotation annotation , String table , QueryData queryData ) { annoCondition . addAnnotationConditions ( conditions , node , index , annotation , table , queryData , tables ( node ) ) ; } @ Override protected void addPrecedenceConditions ( List < String > conditions , QueryNode node , QueryNode target , Precedence join , QueryData queryData ) { joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" ) ; int min = join . getMinDistance ( ) ; int max = join . getMaxDistance ( ) ; String left = join . getSegmentationName ( ) == null ? "<STR_LIT>" : "<STR_LIT>" ; String right = join . getSegmentationName ( ) == null ? "<STR_LIT>" : "<STR_LIT>" ; if ( join . getSegmentationName ( ) != null ) { conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) , sqlString ( join . getSegmentationName ( ) ) ) ) ; } if ( min == <NUM_LIT:0> && max == <NUM_LIT:0> ) { if ( optimizeIndirectPrecedence ) { numberJoinOnNode ( conditions , node , target , "<STR_LIT>" , right , left , - <NUM_LIT:1> ) ; } else { joinOnNode ( conditions , node , target , "<STR_LIT:<>" , right , left ) ; } } else if ( min == max ) { numberJoinOnNode ( conditions , node , target , "<STR_LIT:=>" , right , left , - min ) ; } else { betweenJoinOnNode ( conditions , node , target , right , left , - min , - max ) ; } } @ Override protected void addRightOverlapConditions ( List < String > conditions , QueryNode target , QueryNode node , RightOverlap join , QueryData queryData ) { joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , node , target , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , target , node , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , node , target , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } @ Override protected void addLeftOverlapConditions ( List < String > conditions , QueryNode target , QueryNode node , LeftOverlap join , QueryData queryData ) { joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , node , target , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , target , node , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , node , target , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } @ Override protected void addOverlapConditions ( List < String > conditions , QueryNode node , QueryNode target , Overlap join , QueryData queryData ) { joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , node , target , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , target , node , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } @ Override protected void addInclusionConditions ( List < String > conditions , QueryNode node , QueryNode target , Inclusion join , QueryData queryData ) { joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , node , target , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , node , target , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; if ( optimizeInclusion ) { joinOnNode ( conditions , target , node , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , target , node , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; } } @ Override protected void addRightAlignmentConditions ( List < String > conditions , QueryNode node , QueryNode target , RightAlignment join , QueryData queryData ) { joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" ) ; } @ Override protected void addLeftAlignmentConditions ( List < String > conditions , QueryNode node , QueryNode target , LeftAlignment join , QueryData queryData ) { joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" ) ; } @ Override protected void addIdenticalConditions ( List < String > conditions , QueryNode node , QueryNode target , Identical join , QueryData queryData ) { joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT:id>" , "<STR_LIT:id>" ) ; } @ Override protected void addSameSpanConditions ( List < String > conditions , QueryNode node , QueryNode target , SameSpan join , QueryData queryData ) { joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" ) ; joinOnNode ( conditions , node , target , "<STR_LIT:=>" , "<STR_LIT>" , "<STR_LIT>" ) ; } @ Override protected void addCommonAncestorConditions ( List < String > conditions , QueryNode node , QueryNode target , CommonAncestor join , QueryData queryData ) { List < Long > corpusList = queryData . getCorpusList ( ) ; String componentName = join . getName ( ) ; addComponentPredicates ( conditions , node , target , componentName , "<STR_LIT:d>" ) ; if ( ! allowIdenticalSibling ) { joinOnNode ( conditions , node , target , "<STR_LIT>" , "<STR_LIT:id>" , "<STR_LIT:id>" ) ; } if ( useComponentRefPredicateInCommonAncestorSubquery ) { conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , tables ( target ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) ) ) ; } TableAccessStrategy tas = tables ( null ) ; String pre1 = tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) ; String pre2 = tables ( target ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) ; String pre = tas . column ( "<STR_LIT>" , tas . columnName ( RANK_TABLE , "<STR_LIT>" ) ) ; String post = tas . column ( "<STR_LIT>" , tas . columnName ( RANK_TABLE , "<STR_LIT>" ) ) ; String component = tas . column ( "<STR_LIT>" , tas . columnName ( RANK_TABLE , "<STR_LIT>" ) ) ; String component1 = tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) ; StringBuffer sb = new StringBuffer ( ) ; sb . append ( "<STR_LIT>" + tas . tableName ( RANK_TABLE ) + "<STR_LIT>" ) ; if ( useComponentRefPredicateInCommonAncestorSubquery ) { sb . append ( "<STR_LIT:t>" + component + "<STR_LIT:U+0020=U+0020>" + component1 + "<STR_LIT>" ) ; } sb . append ( "<STR_LIT:t>" + pre + "<STR_LIT>" + pre1 + "<STR_LIT>" + pre1 + "<STR_LIT>" + post + "<STR_LIT>" ) ; sb . append ( "<STR_LIT:t>" + pre + "<STR_LIT>" + pre2 + "<STR_LIT>" + pre2 + "<STR_LIT>" + post ) ; if ( useToplevelCorpusPredicateInCommonAncestorSubquery && ! ( corpusList == null || corpusList . isEmpty ( ) ) ) { sb . append ( "<STR_LIT>" ) ; sb . append ( StringUtils . join ( corpusList , "<STR_LIT:U+002C>" ) ) ; sb . append ( "<STR_LIT:)>" ) ; } sb . append ( "<STR_LIT:)>" ) ; conditions . add ( sb . toString ( ) ) ; } @ Override protected void addSiblingConditions ( List < String > conditions , QueryNode node , QueryNode target , Sibling join , QueryData queryData ) { Sibling sibling = ( Sibling ) join ; String componentName = sibling . getName ( ) ; addComponentPredicates ( conditions , node , target , componentName , "<STR_LIT:d>" ) ; conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , tables ( target ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) ) ) ; if ( ! allowIdenticalSibling ) { joinOnNode ( conditions , node , target , "<STR_LIT>" , "<STR_LIT:id>" , "<STR_LIT:id>" ) ; } } @ Override protected void addSingleEdgeCondition ( QueryNode node , QueryNode target , List < String > conditions , Join join , final String edgeType ) { RankTableJoin rankTableJoin = ( RankTableJoin ) join ; String componentName = rankTableJoin . getName ( ) ; addComponentPredicates ( conditions , node , target , componentName , edgeType ) ; int min = rankTableJoin . getMinDistance ( ) ; int max = rankTableJoin . getMaxDistance ( ) ; if ( min == <NUM_LIT:1> && max == <NUM_LIT:1> ) { conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , tables ( target ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) ) ) ; } else { conditions . add ( join ( "<STR_LIT:<>" , tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , tables ( target ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) ) ) ; conditions . add ( join ( "<STR_LIT:<>" , tables ( target ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) ) ) ; if ( min > <NUM_LIT:0> && min == max ) { conditions . add ( numberJoin ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , tables ( target ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , - min ) ) ; } else if ( min > <NUM_LIT:0> && min < max ) { conditions . add ( between ( tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , tables ( target ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) , - min , - max ) ) ; } } } @ Override protected void addTokenArityConditions ( List < String > conditions , QueryData queryData , QueryNode node ) { QueryNode . Range tokenArity = node . getTokenArity ( ) ; if ( tokenArity . getMin ( ) == tokenArity . getMax ( ) ) { conditions . add ( numberJoin ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) , tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) , - ( tokenArity . getMin ( ) ) + <NUM_LIT:1> ) ) ; } else { conditions . add ( between ( tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) , tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) , - ( tokenArity . getMin ( ) ) + <NUM_LIT:1> , - ( tokenArity . getMax ( ) ) + <NUM_LIT:1> ) ) ; } } @ Override protected void addNodeArityConditions ( List < String > conditions , QueryData queryData , QueryNode node ) { List < Long > corpusList = queryData . getCorpusList ( ) ; TableAccessStrategy tas = tables ( null ) ; String pre1 = tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT>" ) ; String parent = tas . column ( "<STR_LIT>" , tas . columnName ( RANK_TABLE , "<STR_LIT>" ) ) ; String pre = tas . column ( "<STR_LIT>" , tas . columnName ( RANK_TABLE , "<STR_LIT>" ) ) ; StringBuffer sb = new StringBuffer ( ) ; sb . append ( "<STR_LIT>" + pre + "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" + tas . tableName ( RANK_TABLE ) + "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" + parent + "<STR_LIT:U+0020=U+0020>" + pre1 + "<STR_LIT>" + ( corpusList . isEmpty ( ) ? "<STR_LIT>" : StringUtils . join ( corpusList , "<STR_LIT:U+002C>" ) ) + "<STR_LIT:)>" + "<STR_LIT:)>" ) ; QueryNode . Range arity = node . getArity ( ) ; if ( arity . getMin ( ) == arity . getMax ( ) ) { conditions . add ( join ( "<STR_LIT:=>" , sb . toString ( ) , String . valueOf ( arity . getMin ( ) ) ) ) ; } else { conditions . add ( between ( sb . toString ( ) , arity . getMin ( ) , arity . getMax ( ) ) ) ; } } @ Override protected void addNodeNameCondition ( List < String > conditions , QueryData queryData , QueryNode node ) { conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT:name>" ) , sqlString ( node . getName ( ) ) ) ) ; } @ Override protected void addNodeNamespaceConditions ( List < String > conditions , QueryData queryData , QueryNode node ) { conditions . add ( join ( "<STR_LIT:=>" , tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) , sqlString ( node . getNamespace ( ) ) ) ) ; } @ Override protected void addIsRootConditions ( List < String > conditions , QueryData queryData , QueryNode node ) { conditions . add ( isTrue ( tables ( node ) . aliasedColumn ( RANK_TABLE , "<STR_LIT:root>" ) ) ) ; } @ Override protected void addIsTokenConditions ( List < String > conditions , QueryData queryData , QueryNode node ) { if ( useIsTokenColumn ) { conditions . add ( isTrue ( tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) ) ; } else { conditions . add ( isNotNull ( tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) ) ) ; } } @ Override protected void addSpanConditions ( List < String > conditions , QueryData queryData , QueryNode node ) { TextMatching textMatching = node . getSpanTextMatching ( ) ; conditions . add ( join ( textMatching . sqlOperator ( ) , tables ( node ) . aliasedColumn ( NODE_TABLE , "<STR_LIT>" ) , sqlString ( node . getSpannedText ( ) , textMatching ) ) ) ; } public boolean isOptimizeIndirectPrecedence ( ) { return optimizeIndirectPrecedence ; } public void setOptimizeIndirectPrecedence ( boolean optimizeIndirectPrecedence ) { this . optimizeIndirectPrecedence = optimizeIndirectPrecedence ; } public boolean isAllowIdenticalSibling ( ) { return allowIdenticalSibling ; } public void setAllowIdenticalSibling ( boolean allowIdenticalSibling ) { this . allowIdenticalSibling = allowIdenticalSibling ; } public boolean isOptimizeInclusion ( ) { return optimizeInclusion ; } public void setOptimizeInclusion ( boolean optimizeInclusion ) { this . optimizeInclusion = optimizeInclusion ; } public String getComponentPredicates ( ) { return componentPredicates ; } public void setComponentPredicates ( String componentPredicates ) { this . componentPredicates = componentPredicates ; } public boolean isUseIsTokenColumn ( ) { return useIsTokenColumn ; } public void setUseIsTokenColumn ( boolean useIsTokenColumn ) { this . useIsTokenColumn = useIsTokenColumn ; } public boolean isUseToplevelCorpusPredicateInCommonAncestorSubquery ( ) { return useToplevelCorpusPredicateInCommonAncestorSubquery ; } public void setUseToplevelCorpusPredicateInCommonAncestorSubquery ( boolean useToplevelCorpusPredicateInCommonAncestorSubquery ) { this . useToplevelCorpusPredicateInCommonAncestorSubquery = useToplevelCorpusPredicateInCommonAncestorSubquery ; } public boolean isUseComponentRefPredicateInCommonAncestorSubquery ( ) { return useComponentRefPredicateInCommonAncestorSubquery ; } public void setUseComponentRefPredicateInCommonAncestorSubquery ( boolean useComponentRefPredicateInCommonAncestorSubquery ) { this . useComponentRefPredicateInCommonAncestorSubquery = useComponentRefPredicateInCommonAncestorSubquery ; } public AnnotationConditionProvider getAnnoCondition ( ) { return annoCondition ; } public void setAnnoCondition ( AnnotationConditionProvider annoCondition ) { this . annoCondition = annoCondition ; } } </s>