|
| 1 | +/* |
| 2 | +* Copyright 2014 Basis Technology Corp. |
| 3 | +* |
| 4 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +* you may not use this file except in compliance with the License. |
| 6 | +* You may obtain a copy of the License at |
| 7 | +* |
| 8 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +* |
| 10 | +* Unless required by applicable law or agreed to in writing, software |
| 11 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +* See the License for the specific language governing permissions and |
| 14 | +* limitations under the License. |
| 15 | +*/ |
| 16 | +package com.basistech.rosette.examples; |
| 17 | + |
| 18 | +import com.basistech.rosette.api.HttpRosetteAPI; |
| 19 | +import com.basistech.rosette.apimodel.DocumentRequest; |
| 20 | +import com.basistech.rosette.apimodel.LanguageOptions; |
| 21 | +import com.basistech.rosette.apimodel.LanguageResponse; |
| 22 | + |
| 23 | +import java.io.IOException; |
| 24 | + |
| 25 | +/** |
| 26 | + * Example which demonstrates the language detection api with the multilingual option. |
| 27 | + */ |
| 28 | +public final class LanguageMultilingualExample extends ExampleBase { |
| 29 | + public static void main(String[] args) { |
| 30 | + try { |
| 31 | + new LanguageMultilingualExample().run(); |
| 32 | + } catch (Exception e) { |
| 33 | + e.printStackTrace(); |
| 34 | + System.exit(1); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + private void run() throws IOException { |
| 39 | + String languageMultilingualData = "On Thursday, as protesters gathered in Washington D.C., the United States Federal Communications Commission under Chairman Ajit Pai voted 3-2 to overturn a 2015 decision, commonly called Net Neutrality, that forbade Internet service providers (ISPs) such as Verizon, Comcast, and AT&T from blocking individual websites or charging websites or customers more for faster load times. Quatre femmes ont été nommées au Conseil de rédaction de la loi du Qatar. Jeudi, le décret royal du Qatar a annoncé que 28 nouveaux membres ont été nommés pour le Conseil de la Choura du pays. ذكرت مصادر أمنية يونانية، أن 9 موقوفين من منظمة \"د هـ ك ب ج\" الذين كانت قد أوقفتهم الشرطة اليونانية في وقت سابق كانوا يخططون لاغتيال الرئيس التركي رجب طيب أردوغان."; |
| 40 | + |
| 41 | + HttpRosetteAPI rosetteApi = new HttpRosetteAPI.Builder() |
| 42 | + .key(getApiKeyFromSystemProperty()) |
| 43 | + .url(getAltUrlFromSystemProperty()) |
| 44 | + .build(); |
| 45 | + //The api object creates an http client, but to provide your own: |
| 46 | + //rosetteApi.httpClient(CloseableHttpClient) |
| 47 | + |
| 48 | + LanguageOptions options = LanguageOptions.builder().multilingual(true).build(); |
| 49 | + |
| 50 | + DocumentRequest<LanguageOptions> request = DocumentRequest.<LanguageOptions>builder() |
| 51 | + .content(languageMultilingualData) |
| 52 | + .options(options) |
| 53 | + .build(); |
| 54 | + LanguageResponse response = rosetteApi.perform(HttpRosetteAPI.LANGUAGE_SERVICE_PATH, request, LanguageResponse.class); |
| 55 | + System.out.println(responseToJson(response)); |
| 56 | + } |
| 57 | +} |
0 commit comments