Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Translator.java « translation « core « omtc « capitati « com « java « main « src - github.com/ianj-als/omtc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 08335d4f2aaa4d6279e9791b2ae58e774e3bd23d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * Copyright Capita Translation and Interpreting 2013
 *
 * This file is part of OMTC.
 *
 * OMTC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * OMTC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with OMTC.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.capitati.omtc.core.translation;

import java.net.URI;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import com.capitati.omtc.core.engine.IEngine;
import com.capitati.omtc.core.resources.IDerivedResource;
import com.capitati.omtc.core.resources.IPrimaryResource;
import com.capitati.omtc.core.resources.IResource;
import com.capitati.omtc.core.scheduling.IPriority;
import com.capitati.omtc.core.scheduling.ITicketObserver;
import com.capitati.omtc.core.scheduling.TranslationTicket;
import com.capitati.omtc.core.session.ISession;
import com.google.common.base.Predicate;

/**
 * An associative class that brings together an engine, glossaries and
 * translation memories. These resources are to be used as a translator.
 * 
 * @author ian
 *
 * @param <P> - the type of the priority's value.
 */
public abstract class Translator<V,
                                    T extends IPrimaryResource,
                                    G extends IPrimaryResource>
implements IDerivedResource {
  private final UUID identifier;
  private final URI location;
  private final Date birthDate;
  private final IEngine engine;
  private final Set<G> glossaries = new HashSet<G>();
  private final Set<T> translationMemories = new HashSet<T>();

  protected Translator(
      final UUID theIdentifier,
      final URI theLocation,
      final Date theBirthDate,
      final IEngine theEngine) {
    super();
    identifier = theIdentifier;
    location = theLocation;
    birthDate = theBirthDate;
    engine = theEngine;
  }

  protected Translator(
      final UUID theIdentifier,
      final URI theLocation,
      final Date theBirthDate,
      final IEngine theEngine,
      final Set<G> theGlossaries,
      final Set<T> theTranslationMemories) {
    super();
    identifier = theIdentifier;
    location = theLocation;
    birthDate = theBirthDate;
    engine = theEngine;
    glossaries.addAll(theGlossaries);
    translationMemories.addAll(theTranslationMemories);
  }

  public UUID getIdentifier() {
    return identifier;
  }

  public URI getURI() {
    return location;
  }

  public Date getBirthDate() {
    return birthDate;
  }

  public Set<IResource> getCreationResources() {
    final Set<IResource> creationResources = new HashSet<IResource>(glossaries);

    creationResources.addAll(translationMemories);

    return creationResources;
  }

  public IEngine getEngine() {
    return engine;
  }

  public Set<G> getGlossaries() {
    return new HashSet<G>(glossaries);
  }

  public Set<T> getTranslationMemories() {
    return new HashSet<T>(translationMemories);
  }

  /**
   * Schedule a translation for a primary resource. It is implementation
   * defined which kind of primary resources shall be translated.
   *
   * @param session - the invoking session.
   * @param resourceToTranslate - the primary resource to translate.
   * @param thePriority - the requested priority.
   * @param translationObserver - the observer that listens for the translation
   * task to starting and complete.
   * @return A translation ticket.
   * @throws Exception On a scheduling error.
   */
  public abstract TranslationTicket<V, T, G> scheduleTranslation(
      ISession session,
      IPrimaryResource resourceToTranslate,
      IPriority<V> thePriority,
      ITicketObserver<TranslationTicket<V, T, G>, V> translationObserver)
  throws Exception;

  /**
   * Schedule a translation for a single sentence.
   *
   * @param session - the invoking session.
   * @param sourceSentence - the sentence to translate.
   * @param thePriority - the requested priority.
   * @param translationObserver - the observer that listens for the translation
   * task to starting and complete.
   * @return A translation ticket.
   * @throws Exception On a scheduling error.
   */
  public abstract TranslationTicket<V, T, G> scheduleTranslation(
      ISession session,
      String sourceSentence,
      IPriority<V> thePriority,
      ITicketObserver<TranslationTicket<V, T, G>, V> translationObserver)
  throws Exception;

  /**
   * Retrieve the dispensed translation tickets.
   *
   * @param session - the invoking session.
   * @param filter - a predicate used to filter the translation tickets.
   * @return A {@link java.util.Set} of currently scheduled translation
   * tickets. It is the implementations responsibility to manage the in-flight
   * collection of tickets.
   * @throws Exception On error retrieving translations.
   */
  public abstract Set<TranslationTicket<V, T, G>> retrieveTranslations(
      ISession session,
      Predicate<TranslationTicket<V, T, G>> filter) throws Exception;
}