Changeset 2179 for SRUCQIBridge


Ignore:
Timestamp:
08/30/12 13:12:47 (12 years ago)
Author:
akislev
Message:

Updated to use a separately packaged CQI Client

Location:
SRUCQIBridge
Files:
3 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • SRUCQIBridge/pom.xml

    r2105 r2179  
    1818            <artifactId>sru-server</artifactId>
    1919            <version>0.6.0-SNAPSHOT</version>
     20        </dependency>
     21        <dependency>
     22            <groupId>eu.clarin.cqi</groupId>
     23            <artifactId>cqi-client</artifactId>
     24            <version>1.0-SNAPSHOT</version>
    2025        </dependency>
    2126    </dependencies>
  • SRUCQIBridge/src/main/java/eu/clarin/sru/cqibridge/CqiSRUSearchEngine.java

    r2105 r2179  
    1616package eu.clarin.sru.cqibridge;
    1717
     18import eu.clarin.cqi.client.CqiClient;
     19import eu.clarin.cqi.client.CqiClientException;
     20import eu.clarin.cqi.client.CqiResult;
    1821import eu.clarin.sru.server.*;
    1922import eu.clarin.sru.server.utils.SRUSearchEngineBase;
     
    5558    private static final Pattern SPACE_PATTERN = Pattern.compile("\\s+");
    5659    private static final String WORD_POSITIONAL_ATTRIBUTE = "word";
     60    private static final String CONTEXT_STRUCTURAL_ATTRIBUTE = "s";
    5761    private static final Logger logger =
    5862            LoggerFactory.getLogger(CqiSRUSearchEngine.class);
     
    158162                new Object[]{cqpQuery, startRecord, maximumRecords});
    159163        try {
    160             final CqiResult result = client.cqpQuery(defaultCorpusName, cqpQuery);
    161             if (!result.absolute(startRecord)) {
     164            final CqiResult result = client.query(defaultCorpusName, cqpQuery, CONTEXT_STRUCTURAL_ATTRIBUTE);
     165            if ((result.size() > 0 && !result.absolute(startRecord)) || (result.size() == 0 && startRecord > 0)) {
    162166                diagnostics.addDiagnostic(SRUConstants.SRU_FIRST_RECORD_POSITION_OUT_OF_RANGE, Integer.toString(startRecord + 1), null);
    163167            }
     
    204208                public void writeRecord(XMLStreamWriter writer)
    205209                        throws XMLStreamException {
    206                     final CqiResult.Range context;
    207                     try {
    208                         context = result.getRange(CqiResult.Field.CONTEXT);
    209                     } catch (CqiClientException e) {
    210                         throw new XMLStreamException("can't obtain the context range", e);
    211                     }
    212                     final CqiResult.Range match;
    213                     try {
    214                         match = result.getRange(CqiResult.Field.MATCH);
    215                     } catch (CqiClientException e) {
    216                         throw new XMLStreamException("can't obtain the match range", e);
    217                     }
    218                     int matchStart = match.getStart() - context.getStart();
    219                     int matchEnd = match.getEnd() - context.getStart() + 1;
    220                     int contextEnd = context.getEnd() - context.getStart() + 1;
     210                    final int contextStart = result.getContextStart();
     211                    final int contextEnd = result.getContextEnd();
     212                    final int matchStart = result.getMatchStart();
     213                    final int matchEnd = result.getMatchEnd();
     214                    final int relMatchStart = matchStart - contextStart;
     215                    final int relMatchEnd = matchEnd - contextStart + 1;
     216                    final int relContextEnd = contextEnd - contextStart + 1;
    221217                    final StringBuilder leftContext = new StringBuilder();
    222218                    final StringBuilder keyWord = new StringBuilder();
     
    224220                    String[] words;
    225221                    try {
    226                         words = context.getValues(WORD_POSITIONAL_ATTRIBUTE);
     222                        words = result.getValues(WORD_POSITIONAL_ATTRIBUTE, contextStart, contextEnd);
    227223                    } catch (CqiClientException e) {
    228224                        throw new XMLStreamException("can't obtain the values of the positional attribute '" + WORD_POSITIONAL_ATTRIBUTE + "'", e);
    229225                    }
    230226                    boolean isFirst = true;
    231                     for (int i = 0; i < matchStart; i++) {
     227                    for (int i = 0; i < relMatchStart; i++) {
    232228                        if (isFirst) {
    233229                            isFirst = false;
     
    238234                    }
    239235                    isFirst = true;
    240                     for (int i = matchStart; i < matchEnd; i++) {
     236                    for (int i = relMatchStart; i < relMatchEnd; i++) {
    241237                        if (isFirst) {
    242238                            isFirst = false;
     
    247243                    }
    248244                    isFirst = true;
    249                     for (int i = matchEnd; i < contextEnd; i++) {
     245                    for (int i = relMatchEnd; i < relContextEnd; i++) {
    250246                        if (isFirst) {
    251247                            isFirst = false;
  • SRUCQIBridge/src/main/webapp/META-INF/context.xml

    r2105 r2179  
    11<?xml version="1.0" encoding="UTF-8"?>
    2 <Context antiJARLocking="true" path="/SRUCQIBridge"/>
     2<Context antiJARLocking="true" path="/sru"/>
Note: See TracChangeset for help on using the changeset viewer.