Changeset 2477 for SRUCQIBridge
- Timestamp:
- 01/17/13 16:59:23 (11 years ago)
- Location:
- SRUCQIBridge
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUCQIBridge/pom.xml
r2179 r2477 3 3 <modelVersion>4.0.0</modelVersion> 4 4 <artifactId>sru-cqibridge</artifactId> 5 <version>1.0 -SNAPSHOT</version>5 <version>1.0</version> 6 6 <packaging>war</packaging> 7 7 8 8 <name>SRU-CQIBridge</name> 9 <url>http://weblicht.sfs.uni-tuebingen.de/</url> 9 10 10 11 <properties> … … 12 13 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 13 14 </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> 14 22 15 23 <dependencies> … … 17 25 <groupId>eu.clarin.sru</groupId> 18 26 <artifactId>sru-server</artifactId> 19 <version> 0.6.0-SNAPSHOT</version>27 <version>1.1.0</version> 20 28 </dependency> 21 29 <dependency> 22 30 <groupId>eu.clarin.cqi</groupId> 23 31 <artifactId>cqi-client</artifactId> 24 <version>1.0 -SNAPSHOT</version>32 <version>1.0</version> 25 33 </dependency> 26 34 </dependencies> … … 51 59 </build> 52 60 <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> 53 67 </project> -
SRUCQIBridge/src/main/java/eu/clarin/sru/cqibridge/CqiSRUSearchEngine.java
r2188 r2477 21 21 import eu.clarin.sru.server.*; 22 22 import eu.clarin.sru.server.utils.SRUSearchEngineBase; 23 import java.util.Arrays; 23 24 import java.util.Map; 24 25 import java.util.NoSuchElementException; … … 52 53 private static final String INDEX_CQL_SERVERCHOICE = "cql.serverChoice"; 53 54 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"; 54 58 private static final String FCS_NS = "http://clarin.eu/fcs/1.0"; 55 59 private static final String FCS_PREFIX = "fcs"; … … 57 61 private static final String FCS_KWIC_PREFIX = "kwic"; 58 62 private static final String CLARIN_FCS_RECORD_SCHEMA = FCS_NS; 63 private static final String X_CLARIN_RESOURCE_INFO = "x-clarin-resource-info"; 59 64 private static final Pattern SPACE_PATTERN = Pattern.compile("\\s+"); 60 65 private static final String WORD_POSITIONAL_ATTRIBUTE = "word"; … … 62 67 private static final Logger logger = 63 68 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")),}; 64 77 private CqiClient client; 65 78 private String defaultCorpusName; … … 130 143 public SRUScanResultSet scan(SRUServerConfig config, SRURequest request, 131 144 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 }; 133 194 } 134 195 … … 174 235 175 236 return new SRUSearchResultSet(diagnostics) { 176 177 237 private int pos = 0; 178 238 … … 297 357 } 298 358 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 299 421 private String translateCQLtoCQP(CQLNode query) throws SRUException { 300 422 if (query instanceof CQLTermNode) { … … 342 464 + "(CQL conformance level 0)."); 343 465 } 466 467 private boolean parseBoolean(String value) { 468 if (value != null) { 469 return value.endsWith("1") || Boolean.parseBoolean(value); 470 } 471 return false; 472 } 344 473 }
Note: See TracChangeset
for help on using the changeset viewer.