Changeset 6097 for SRUAggregator


Ignore:
Timestamp:
03/11/15 11:09:37 (9 years ago)
Author:
emanuel.dima@uni-tuebingen.de
Message:
  1. beta-29: better language detection for weblicht
Location:
SRUAggregator/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • SRUAggregator/trunk/pom.xml

    r6093 r6097  
    88        <groupId>eu.clarin.sru.fcs</groupId>
    99        <artifactId>Aggregator2</artifactId>
    10         <version>2.0.0-beta-28</version>
     10        <version>2.0.0-beta-29</version>
    1111        <name>FCS Aggregator</name>
    1212
  • SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/search/Result.java

    r6092 r6097  
    7373
    7474        void addRecord(SRURecord record) {
     75//              TODO(edima): use response.getNextRecordPosition()
    7576                endpointReturnedRecords.getAndIncrement();
    7677                if (record.isRecordSchema(ClarinFCSRecordData.RECORD_SCHEMA)) {
  • SRUAggregator/trunk/src/main/resources/assets/js/main.jsx

    r6093 r6097  
    33"use strict";
    44
    5 var VERSION = "VERSION 2.0.0-beta-28";
     5var VERSION = "VERSION 2.0.0-beta-29";
    66var URLROOT = "/Aggregator-testing";
    77
  • SRUAggregator/trunk/src/main/resources/assets/js/search.js

    r6093 r6097  
    297297        },
    298298
    299         getExportParams: function(corpusId, format) {
     299        getExportParams: function(corpusId, format, filterLanguage) {
    300300                var params = corpusId ? {corpusId:corpusId}:{};
    301301                if (format) params.format = format;
    302                 if (this.state.languageFilter === 'byGuess' || this.state.languageFilter === 'byMetaAndGuess') {
     302                if (filterLanguage) {
     303                        params.filterLanguage = filterLanguage;
     304                } else if (this.state.languageFilter === 'byGuess' || this.state.languageFilter === 'byMetaAndGuess') {
    303305                        params.filterLanguage = this.state.language[0];
    304306                }
     
    307309
    308310        getDownloadLink: function(corpusId, format) {
    309                 return 'rest/search/'+this.state.searchId+'/download?' + this.getExportParams(corpusId, format);
    310         },
    311 
    312         getToWeblichtLink: function(corpusId) {
    313                 var params = corpusId ? {corpusId:corpusId}:{};
    314                 return 'rest/search/'+this.state.searchId+'/toWeblicht?' + this.getExportParams(corpusId);
     311                return 'rest/search/'+this.state.searchId+'/download?' +
     312                        this.getExportParams(corpusId, format);
     313        },
     314
     315        getToWeblichtLink: function(corpusId, forceLanguage) {
     316                return 'rest/search/'+this.state.searchId+'/toWeblicht?' +
     317                        this.getExportParams(corpusId, null, forceLanguage);
    315318        },
    316319
     
    469472                                                                                        layers.map(function(l) {
    470473                                                                                                var cls = l.disabled ? 'disabled':'';
    471                                                                                                 var handler = function() { if (!l.disabled) this.setLayer(l.id); };
     474                                                                                                var handler = function() { if (!l.disabled) this.setLayer(l.id); }.bind(this);
    472475                                                                                                return React.createElement("li", {key: l.id, className: cls}, " ", React.createElement("a", {tabIndex: "-1", href: "#",
    473476                                                                                                        onClick: handler}, " ", l.name, " "));
     
    753756        },
    754757
    755         renderToWeblichtLinks: function(corpusId, error) {
     758        renderToWeblichtLinks: function(corpusId, forceLanguage, error) {
    756759                return (
    757760                        React.createElement("div", {className: "dropdown"},
     
    765768                                                error ?
    766769                                                        React.createElement("div", {className: "alert alert-danger", style: {margin:10, width:200}}, error) :
    767                                                         React.createElement("a", {href: this.props.getToWeblichtLink(corpusId), target: "_blank"}, " ",
     770                                                        React.createElement("a", {href: this.props.getToWeblichtLink(corpusId, forceLanguage), target: "_blank"}, " ",
    768771                                                                "Send to Weblicht")
    769772                                               
     
    834837                        return false;
    835838                }
    836                 var wlerror = null;
     839
     840                var forceLanguage = null, wlerror = null;
    837841                if (this.props.weblichtLanguages.indexOf(this.props.searchedLanguage[0]) < 0) {
    838                         wlerror = "Cannot use WebLicht: unsupported language";
     842                        // the search language is either AnyLanguage or unsupported
     843                        if (this.props.searchedLanguage[0] === multipleLanguageCode) {
     844                                if (corpusHit.corpus.languages && corpusHit.corpus.languages.length === 1) {
     845                                        forceLanguage = corpusHit.corpus.languages[0];
     846                                } else {
     847                                        var langs = corpusHit.kwics.map(function(kwic) {return kwic.language;});
     848                                        langs = _.uniq(langs.filter(function(l){ return l !== null; }));
     849                                        console.log("languages:", langs);
     850                                        if (langs.length === 1) {
     851                                                forceLanguage = langs[0];
     852                                        }
     853                                }
     854                        }
     855                        if (!forceLanguage) {
     856                                wlerror = "Cannot use WebLicht: unsupported language ("+this.props.searchedLanguage[1]+")";
     857                        }
    839858                }
    840859                var corpus = corpusHit.corpus;
     
    852871                                                                         this.renderDisplayKWIC(),
    853872                                                                        React.createElement("div", {className: "inline"}, " ", this.renderDownloadLinks(corpusHit.corpus.id), " "),
    854                                                                         React.createElement("div", {className: "inline"}, " ", this.renderToWeblichtLinks(corpus.id, wlerror), " ")
     873                                                                        React.createElement("div", {className: "inline"}, " ", this.renderToWeblichtLinks(corpus.id, forceLanguage, wlerror), " ")
    855874                                                                )
    856875                                                        ),
     
    9911010                return ret;
    9921011        },
     1012
     1013        uniq: function(a) {
     1014                var r = [];
     1015                for (var i = 0; i < a.length; i++) {
     1016                        if (r.indexOf(a[i]) < 0) {
     1017                                r.push(a[i]);
     1018                        }
     1019                }
     1020                return r;
     1021        },
    9931022};
    9941023
  • SRUAggregator/trunk/src/main/resources/assets/js/search.jsx

    r6093 r6097  
    297297        },
    298298
    299         getExportParams: function(corpusId, format) {
     299        getExportParams: function(corpusId, format, filterLanguage) {
    300300                var params = corpusId ? {corpusId:corpusId}:{};
    301301                if (format) params.format = format;
    302                 if (this.state.languageFilter === 'byGuess' || this.state.languageFilter === 'byMetaAndGuess') {
     302                if (filterLanguage) {
     303                        params.filterLanguage = filterLanguage;
     304                } else if (this.state.languageFilter === 'byGuess' || this.state.languageFilter === 'byMetaAndGuess') {
    303305                        params.filterLanguage = this.state.language[0];
    304306                }
     
    307309
    308310        getDownloadLink: function(corpusId, format) {
    309                 return 'rest/search/'+this.state.searchId+'/download?' + this.getExportParams(corpusId, format);
    310         },
    311 
    312         getToWeblichtLink: function(corpusId) {
    313                 var params = corpusId ? {corpusId:corpusId}:{};
    314                 return 'rest/search/'+this.state.searchId+'/toWeblicht?' + this.getExportParams(corpusId);
     311                return 'rest/search/'+this.state.searchId+'/download?' +
     312                        this.getExportParams(corpusId, format);
     313        },
     314
     315        getToWeblichtLink: function(corpusId, forceLanguage) {
     316                return 'rest/search/'+this.state.searchId+'/toWeblicht?' +
     317                        this.getExportParams(corpusId, null, forceLanguage);
    315318        },
    316319
     
    469472                                                                                {       layers.map(function(l) {
    470473                                                                                                var cls = l.disabled ? 'disabled':'';
    471                                                                                                 var handler = function() { if (!l.disabled) this.setLayer(l.id); };
     474                                                                                                var handler = function() { if (!l.disabled) this.setLayer(l.id); }.bind(this);
    472475                                                                                                return <li key={l.id} className={cls}> <a tabIndex="-1" href="#"
    473476                                                                                                        onClick={handler}> {l.name} </a></li>;
     
    753756        },
    754757
    755         renderToWeblichtLinks: function(corpusId, error) {
     758        renderToWeblichtLinks: function(corpusId, forceLanguage, error) {
    756759                return (
    757760                        <div className="dropdown">
     
    765768                                                {error ?
    766769                                                        <div className="alert alert-danger" style={{margin:10, width:200}}>{error}</div> :
    767                                                         <a href={this.props.getToWeblichtLink(corpusId)} target="_blank">{" "}
     770                                                        <a href={this.props.getToWeblichtLink(corpusId, forceLanguage)} target="_blank">{" "}
    768771                                                                Send to Weblicht</a>
    769772                                                }
     
    834837                        return false;
    835838                }
    836                 var wlerror = null;
     839
     840                var forceLanguage = null, wlerror = null;
    837841                if (this.props.weblichtLanguages.indexOf(this.props.searchedLanguage[0]) < 0) {
    838                         wlerror = "Cannot use WebLicht: unsupported language";
     842                        // the search language is either AnyLanguage or unsupported
     843                        if (this.props.searchedLanguage[0] === multipleLanguageCode) {
     844                                if (corpusHit.corpus.languages && corpusHit.corpus.languages.length === 1) {
     845                                        forceLanguage = corpusHit.corpus.languages[0];
     846                                } else {
     847                                        var langs = corpusHit.kwics.map(function(kwic) {return kwic.language;});
     848                                        langs = _.uniq(langs.filter(function(l){ return l !== null; }));
     849                                        console.log("languages:", langs);
     850                                        if (langs.length === 1) {
     851                                                forceLanguage = langs[0];
     852                                        }
     853                                }
     854                        }
     855                        if (!forceLanguage) {
     856                                wlerror = "Cannot use WebLicht: unsupported language ("+this.props.searchedLanguage[1]+")";
     857                        }
    839858                }
    840859                var corpus = corpusHit.corpus;
     
    852871                                                                        { this.renderDisplayKWIC() }
    853872                                                                        <div className="inline"> {this.renderDownloadLinks(corpusHit.corpus.id)} </div>
    854                                                                         <div className="inline"> {this.renderToWeblichtLinks(corpus.id, wlerror)} </div>
     873                                                                        <div className="inline"> {this.renderToWeblichtLinks(corpus.id, forceLanguage, wlerror)} </div>
    855874                                                                </div>
    856875                                                        </div>
     
    9911010                return ret;
    9921011        },
     1012
     1013        uniq: function(a) {
     1014                var r = [];
     1015                for (var i = 0; i < a.length; i++) {
     1016                        if (r.indexOf(a[i]) < 0) {
     1017                                r.push(a[i]);
     1018                        }
     1019                }
     1020                return r;
     1021        },
    9931022};
    9941023
Note: See TracChangeset for help on using the changeset viewer.