Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Commit

Permalink
1.4.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jprante committed Nov 25, 2014
1 parent 1368fbe commit 32761b9
Show file tree
Hide file tree
Showing 17 changed files with 401 additions and 47 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ zh-tw

| Elasticsearch | Plugin | Release date |
| -------------- | -------------- | ------------ |
| 1.4.0 | 1.4.0.2 | Nov 26, 2014 |
| 1.4.0 | 1.4.0.1 | Nov 20, 2014 |
| 1.4.0 | 1.4.0.0 | Nov 14, 2014 |
| 1.3.1 | 1.3.0.0 | Jul 30, 2014 |
Expand All @@ -91,14 +92,15 @@ zh-tw

## Installation

./bin/plugin -install langdetect -url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-langdetect/1.4.0.1/elasticsearch-langdetect-1.4.0.1-plugin.zip
./bin/plugin -install langdetect -url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-langdetect/1.4.0.2/elasticsearch-langdetect-1.4.0.2-plugin.zip

Do not forget to restart the node after installing.

## Checksum

| File | SHA1 |
| --------------------------------------------- | -----------------------------------------|
| elasticsearch-langdetect-1.4.0.2-plugin.zip | 60919142f12d8b54e519f6cf97862e842c6b3bb8 |
| elasticsearch-langdetect-1.4.0.1-plugin.zip | a7ab2401ae68789bf1e5841427ce40440c903da4 |
| elasticsearch-langdetect-1.4.0.0-plugin.zip | f95361fa1a81b2681e2e9002b03ca6aad57f3012 |
| elasticsearch-langdetect-1.3.0.0-plugin.zip | e2dd56c72f19cec861141becd8beb18d7bb26ee6 |
Expand Down Expand Up @@ -246,7 +248,7 @@ All feedback is welcome! If you find issues, please post them at [Github](https:

curl -XPOST 'localhost:9200/_langdetect?pretty' -d 'This is a test'
{
"ok" : true,
"profile" : "/langdetect/",
"languages" : [ {
"language" : "en",
"probability" : 0.9999971603535163
Expand All @@ -255,7 +257,7 @@ All feedback is welcome! If you find issues, please post them at [Github](https:

curl -XPOST 'localhost:9200/_langdetect?pretty' -d 'Das ist ein Test'
{
"ok" : true,
"profile" : "/langdetect/",
"languages" : [ {
"language" : "de",
"probability" : 0.9999993070517024
Expand All @@ -264,7 +266,7 @@ All feedback is welcome! If you find issues, please post them at [Github](https:

curl -XPOST 'localhost:9200/_langdetect?pretty' -d 'Datt isse ne test'
{
"ok" : true,
"profile" : "/langdetect/",
"languages" : [ {
"language" : "no",
"probability" : 0.5714251911820175
Expand All @@ -277,6 +279,9 @@ All feedback is welcome! If you find issues, please post them at [Github](https:
} ]
}

## Change profile of language detection to "shart text" profile

curl -XPOST 'localhost:9200/_langdetect/profile?profile=/langdetect/short-text/'

# Credits

Expand Down
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.xbib.elasticsearch.plugin</groupId>
<artifactId>elasticsearch-langdetect</artifactId>
<version>1.4.0.1</version>
<version>1.4.0.2</version>

<packaging>jar</packaging>

Expand Down Expand Up @@ -99,6 +99,20 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@

public class LangdetectResponse extends ActionResponse implements StatusToXContent {

private String profile;

private List<Language> languages;

public LangdetectResponse() {
}

public LangdetectResponse setProfile(String profile) {
this.profile = profile;
return this;
}

public String getProfile() {
return profile;
}

public LangdetectResponse setLanguages(List<Language> languages) {
this.languages = languages;
return this;
Expand All @@ -29,6 +40,7 @@ public List<Language> getLanguages() {

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("profile", profile);
builder.startArray("languages");
for (Language lang : languages) {
builder.startObject().field("language", lang.getLanguage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ public TransportLangdetectAction(Settings settings, ThreadPool threadPool,
ActionFilters actionFilters, LangdetectService service) {
super(settings, LangdetectAction.NAME, threadPool, actionFilters);
this.service = service;
// start the service here
this.service.start();
}

@Override
protected void doExecute(LangdetectRequest request, ActionListener<LangdetectResponse> listener) {
try {
List<Language> langs = service.detectAll(request.getText());
listener.onResponse(new LangdetectResponse().setLanguages(langs));
listener.onResponse(new LangdetectResponse().setLanguages(langs).setProfile(service.getProfile()));
} catch (LanguageDetectionException e) {
listener.onFailure(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.xbib.elasticsearch.action.langdetect.profile;

import org.elasticsearch.action.admin.indices.IndicesAction;
import org.elasticsearch.client.IndicesAdminClient;

public class LangdetectProfileAction extends IndicesAction<LangdetectProfileRequest, LangdetectProfileResponse, LangdetectProfileRequestBuilder> {

public static final String NAME = "langdetect.profile";

public static final LangdetectProfileAction INSTANCE = new LangdetectProfileAction();

private LangdetectProfileAction() {
super(NAME);
}

@Override
public LangdetectProfileRequestBuilder newRequestBuilder(IndicesAdminClient client) {
return new LangdetectProfileRequestBuilder(client);
}

@Override
public LangdetectProfileResponse newResponse() {
return new LangdetectProfileResponse();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.xbib.elasticsearch.action.langdetect.profile;

import org.elasticsearch.action.support.single.custom.SingleCustomOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;

public class LangdetectProfileRequest extends SingleCustomOperationRequest<LangdetectProfileRequest> {

private String profile;

public LangdetectProfileRequest() {
}

public LangdetectProfileRequest setProfile(String profile) {
this.profile = profile;
return this;
}

public String getProfile() {
return profile;
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
profile = in.readString();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(profile);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.xbib.elasticsearch.action.langdetect.profile;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.single.custom.SingleCustomOperationRequestBuilder;
import org.elasticsearch.client.IndicesAdminClient;

public class LangdetectProfileRequestBuilder extends SingleCustomOperationRequestBuilder<LangdetectProfileRequest, LangdetectProfileResponse, LangdetectProfileRequestBuilder> {

public LangdetectProfileRequestBuilder(IndicesAdminClient client) {
super(client, new LangdetectProfileRequest());
}

public LangdetectProfileRequestBuilder setProfile(String string) {
request.setProfile(string);
return this;
}

@Override
protected void doExecute(ActionListener<LangdetectProfileResponse> listener) {
client.execute(LangdetectProfileAction.INSTANCE, request, listener);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.xbib.elasticsearch.action.langdetect.profile;

import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.xcontent.StatusToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.RestStatus;

import java.io.IOException;

import static org.elasticsearch.rest.RestStatus.OK;

public class LangdetectProfileResponse extends ActionResponse implements StatusToXContent {

public LangdetectProfileResponse() {
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("ok", true);
return builder;
}

@Override
public RestStatus status() {
return OK;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.xbib.elasticsearch.action.langdetect.profile;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.xbib.elasticsearch.index.analysis.langdetect.LanguageDetectionException;
import org.xbib.elasticsearch.module.langdetect.LangdetectService;

public class TransportLangdetectProfileAction extends TransportAction<LangdetectProfileRequest, LangdetectProfileResponse> {

private final LangdetectService service;

@Inject
public TransportLangdetectProfileAction(Settings settings, ThreadPool threadPool,
ActionFilters actionFilters, LangdetectService service) {
super(settings, LangdetectProfileAction.NAME, threadPool, actionFilters);
this.service = service;
}

@Override
protected void doExecute(LangdetectProfileRequest request, ActionListener<LangdetectProfileResponse> listener) {
try {
service.setProfile(request.getProfile());
listener.onResponse(new LangdetectProfileResponse());
} catch (LanguageDetectionException e) {
listener.onFailure(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.xbib.elasticsearch.module.langdetect;

import org.elasticsearch.common.inject.Binder;
import org.elasticsearch.common.inject.Module;

public class LangdetectIndexModule implements Module {

@Override
public void configure(Binder binder) {
binder.bind(RegisterLangdetectType.class).asEagerSingleton();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class LangdetectModule implements Module {

@Override
public void configure(Binder binder) {
binder.bind(RegisterLangdetectType.class).asEagerSingleton();
binder.bind(LangdetectService.class).asEagerSingleton();
}

}
Loading

0 comments on commit 32761b9

Please sign in to comment.