Changeset 2477 for SRUCQIBridge


Ignore:
Timestamp:
01/17/13 16:59:23 (11 years ago)
Author:
akislev
Message:

integrated recent changes needed for the scan operation to work

Location:
SRUCQIBridge
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • SRUCQIBridge/pom.xml

    r2179 r2477  
    33    <modelVersion>4.0.0</modelVersion>
    44    <artifactId>sru-cqibridge</artifactId>
    5     <version>1.0-SNAPSHOT</version>
     5    <version>1.0</version>
    66    <packaging>war</packaging>
    77
    88    <name>SRU-CQIBridge</name>
     9    <url>http://weblicht.sfs.uni-tuebingen.de/</url>
    910
    1011    <properties>
     
    1213        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    1314    </properties>
     15   
     16    <repositories>
     17        <repository>
     18            <id>clarin</id>
     19            <url>http://catalog.clarin.eu/ds/nexus/content/repositories/Clarin/</url>
     20        </repository>
     21    </repositories>
    1422
    1523    <dependencies>
     
    1725            <groupId>eu.clarin.sru</groupId>
    1826            <artifactId>sru-server</artifactId>
    19             <version>0.6.0-SNAPSHOT</version>
     27            <version>1.1.0</version>
    2028        </dependency>
    2129        <dependency>
    2230            <groupId>eu.clarin.cqi</groupId>
    2331            <artifactId>cqi-client</artifactId>
    24             <version>1.0-SNAPSHOT</version>
     32            <version>1.0</version>
    2533        </dependency>
    2634    </dependencies>
     
    5159    </build>
    5260    <groupId>eu.clarin.sru.cqibridge</groupId>
     61    <licenses>
     62        <license>
     63            <name>GNU General Public License, Version 3</name>
     64            <url>http://www.gnu.org/licenses/</url>
     65        </license>
     66    </licenses>
    5367</project>
  • SRUCQIBridge/src/main/java/eu/clarin/sru/cqibridge/CqiSRUSearchEngine.java

    r2188 r2477  
    2121import eu.clarin.sru.server.*;
    2222import eu.clarin.sru.server.utils.SRUSearchEngineBase;
     23import java.util.Arrays;
    2324import java.util.Map;
    2425import java.util.NoSuchElementException;
     
    5253    private static final String INDEX_CQL_SERVERCHOICE = "cql.serverChoice";
    5354    private static final String INDEX_FCS_WORDS = "words";
     55    private static final String INDEX_FCS_RESOURCE = "fcs.resource";
     56    private static final String FCS_RESOURCE_TERM_WILDCARD = "*";
     57    private static final String FCS_RESOURCE_TERM_ANY = "any";
    5458    private static final String FCS_NS = "http://clarin.eu/fcs/1.0";
    5559    private static final String FCS_PREFIX = "fcs";
     
    5761    private static final String FCS_KWIC_PREFIX = "kwic";
    5862    private static final String CLARIN_FCS_RECORD_SCHEMA = FCS_NS;
     63    private static final String X_CLARIN_RESOURCE_INFO = "x-clarin-resource-info";
    5964    private static final Pattern SPACE_PATTERN = Pattern.compile("\\s+");
    6065    private static final String WORD_POSITIONAL_ATTRIBUTE = "word";
     
    6267    private static final Logger logger =
    6368            LoggerFactory.getLogger(CqiSRUSearchEngine.class);
     69    private static final ResourceInfo[] RESOURCE_INFOS = new ResourceInfo[]{
     70        new ResourceInfo("tueba-ddc", -1, false,
     71        Arrays.asList("en", "TuebaDDC",
     72        "de", "TÃŒbaDDC"),
     73        Arrays.asList("en", "TÃŒbingen Treebank of Written German - Diachronic Corpus.",
     74        "de", "TÃŒbingen Baumbank des Deutschen - Diachrones Corpus."),
     75        Arrays.asList("deu"),
     76        Arrays.asList("text", "fcs.words")),};
    6477    private CqiClient client;
    6578    private String defaultCorpusName;
     
    130143    public SRUScanResultSet scan(SRUServerConfig config, SRURequest request,
    131144            SRUDiagnosticList diagnostics) throws SRUException {
    132         return null;
     145        /*
     146         * handle scan on CLARIN FCS fcs.resource;
     147         * otherwise return an empty scan result set ...
     148         */
     149        final ResourceInfo[] result =
     150                translateFcsScanResource(request.getScanClause());
     151        final boolean provideResourceInfo = (result != null)
     152                && parseBoolean(request.getExtraRequestData(X_CLARIN_RESOURCE_INFO));
     153        return new SRUScanResultSet(diagnostics) {
     154            private int idx = -1;
     155
     156            @Override
     157            public boolean nextTerm() {
     158                return (result != null) && (++idx < result.length);
     159            }
     160
     161            @Override
     162            public String getValue() {
     163                return result[idx].getCorpusId();
     164            }
     165
     166            @Override
     167            public int getNumberOfRecords() {
     168                return result[idx].getResourceCount();
     169            }
     170
     171            @Override
     172            public String getDisplayTerm() {
     173                return null;
     174            }
     175
     176            @Override
     177            public SRUScanResultSet.WhereInList getWhereInList() {
     178                return null;
     179            }
     180
     181            @Override
     182            public boolean hasExtraTermData() {
     183                return provideResourceInfo;
     184            }
     185
     186            @Override
     187            public void writeExtraTermData(XMLStreamWriter writer)
     188                    throws XMLStreamException {
     189                if (provideResourceInfo) {
     190                    result[idx].writeResourceInfo(writer, null);
     191                }
     192            }
     193        };
    133194    }
    134195
     
    174235
    175236            return new SRUSearchResultSet(diagnostics) {
    176 
    177237                private int pos = 0;
    178238
     
    297357    }
    298358
     359    private ResourceInfo[] translateFcsScanResource(CQLNode query)
     360            throws SRUException {
     361        if (query instanceof CQLTermNode) {
     362            final CQLTermNode root = (CQLTermNode) query;
     363            logger.debug("index = '{}', relation = '{}', term = '{}'",
     364                    new Object[]{root.getIndex(),
     365                        root.getRelation().getBase(), root.getTerm()});
     366
     367            String index = root.getIndex();
     368            if (!(INDEX_FCS_RESOURCE.equals(index) || INDEX_CQL_SERVERCHOICE.equals(index))) {
     369                throw new SRUException(SRUConstants.SRU_UNSUPPORTED_INDEX,
     370                        root.getIndex(), "Index \"" + root.getIndex()
     371                        + "\" is not supported in scan operation.");
     372            }
     373
     374
     375            // only allow "=" relation without any modifiers
     376            final CQLRelation relationNode = root.getRelation();
     377            String relation = relationNode.getBase();
     378            if (!(CQI_SUPPORTED_RELATION_CQL_1_1.equals(relation)
     379                    || CQI_SUPPORTED_RELATION_CQL_1_2.equals(relation)
     380                    || CQI_SUPPORTED_RELATION_EXACT.equals(relation))) {
     381                throw new SRUException(SRUConstants.SRU_UNSUPPORTED_RELATION,
     382                        relationNode.getBase(), "Relation \""
     383                        + relationNode.getBase()
     384                        + "\" is not supported in scan operation.");
     385            }
     386            Vector<Modifier> modifiers = relationNode.getModifiers();
     387            if ((modifiers != null) && !modifiers.isEmpty()) {
     388                Modifier modifier = modifiers.get(0);
     389                throw new SRUException(
     390                        SRUConstants.SRU_UNSUPPORTED_RELATION_MODIFIER,
     391                        modifier.getValue(), "Relation modifier \""
     392                        + modifier.getValue()
     393                        + "\" is not supported in scan operation.");
     394            }
     395
     396            String term = root.getTerm();
     397            if ((term == null) || term.isEmpty()) {
     398                throw new SRUException(SRUConstants.SRU_EMPTY_TERM_UNSUPPORTED,
     399                        "An empty term is not supported in scan operation.");
     400            }
     401
     402            /*
     403             * generate result: currently we only have a flat hierarchy, so
     404             * return an empty result on any attempt to do a recursive scan ...
     405             */
     406            if ((INDEX_CQL_SERVERCHOICE.equals(index)
     407                    && INDEX_FCS_RESOURCE.equals(term))
     408                    || (INDEX_FCS_RESOURCE.equals(index)
     409                    && (FCS_RESOURCE_TERM_WILDCARD.equals(term)
     410                    || FCS_RESOURCE_TERM_ANY.equalsIgnoreCase(term)))) {
     411                return RESOURCE_INFOS;
     412            } else {
     413                return null;
     414            }
     415        } else {
     416            throw new SRUException(SRUConstants.SRU_QUERY_FEATURE_UNSUPPORTED,
     417                    "Scan clause too complex.");
     418        }
     419    }
     420
    299421    private String translateCQLtoCQP(CQLNode query) throws SRUException {
    300422        if (query instanceof CQLTermNode) {
     
    342464                + "(CQL conformance level 0).");
    343465    }
     466
     467    private boolean parseBoolean(String value) {
     468        if (value != null) {
     469            return value.endsWith("1") || Boolean.parseBoolean(value);
     470        }
     471        return false;
     472    }
    344473}
Note: See TracChangeset for help on using the changeset viewer.