summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/ttmserver/Interfaces.php
blob: 3cce0c1a85ae357f250172fe1383ae8e94030f83 (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
<?php
/**
 * TTMServer - The Translate extension translation memory interface
 *
 * @file
 * @author Niklas Laxström
 * @copyright Copyright © 2012-2013, Niklas Laxström
 * @license GPL-2.0+
 * @ingroup TTMServer
 */

/**
 * Interface for TTMServer that can be queried (=all of them).
 * @ingroup TTMServer
 * @since 2012-06-27
 */
interface ReadableTTMServer {
	/**
	 * Fetches all relevant suggestions for given text.
	 *
	 * @param $sourceLanguage String: language code for the provide text
	 * @param $targetLanguage String: language code for the suggestions
	 * @param $text String: the text for which to search suggestions
	 * @return array List: unordered suggestions, which each has fields:
	 *   - source: String: the original text of the suggestion
	 *   - target: String: the suggestion
	 *   - context: String: title of the page where the suggestion comes from
	 *   - quality: Float: the quality of suggestion, 1 is perfect match
	 */
	public function query( $sourceLanguage, $targetLanguage, $text );

	/**
	 * Determines if the suggestion returned by this TTMServer comes
	 * from this wiki or any other wiki.
	 * @param array $suggestion
	 * @return Bool
	 */
	public function isLocalSuggestion( array $suggestion );

	/**
	 * Given suggestion returned by this TTMServer, constructs fully
	 * qualified URL to the location of the translation.
	 * @param array $suggestion
	 * @return String URL
	 */
	public function expandLocation( array $suggestion );
}

/**
 * Interface for TTMServer that can be updated.
 * @ingroup TTMServer
 * @since 2012-06-27
 */
interface WritableTTMServer {
	/**
	 * Shovels the new translation into translation memory.
	 * Use this for single updates (=after message edit).
	 * If no text is provided, entry will be removed from the translation
	 * memory.
	 *
	 * @param MessageHandle $handle
	 * @param string|null $targetText Use null to only delete.
	 */
	public function update( MessageHandle $handle, $targetText );

	/**
	 * Called when starting to fill the translation memory.
	 * Set up necessary variables and remove old content
	 * from the server.
	 */
	public function beginBootstrap();

	/**
	 * Called before every batch (MessageGroup).
	 */
	public function beginBatch();

	/**
	 * Called multiple times per batch if necessary.
	 *
	 * @param array $batch
	 */
	public function batchInsertDefinitions( array $batch );

	/**
	 * Called multiple times per batch if necessary.
	 *
	 * @param array $batch
	 */
	public function batchInsertTranslations( array $batch );

	/**
	 * Called before every batch (MessageGroup).
	 */
	public function endBatch();

	/**
	 * Do any cleanup, optimizing etc.
	 */
	public function endBootstrap();
}

/**
 * Interface for TTMServer that can act as backend for translation search.
 * @ingroup TTMServer
 * @since 2014.04
 */
interface SearchableTTMServer {
	/**
	 * Performs a search in the translation database.
	 *
	 * @param string $queryString String to search for.
	 * @param array $opts Query options like language.
	 * @param array $highlight Tags for highlighting.
	 * @return mixed Result set
	 */
	public function search( $queryString, $opts, $highlight );

	/**
	 * ...
	 */
	public function getFacets( $resultset );

	/**
	 * @param $resultset
	 * @return int
	 */
	public function getTotalHits( $resultset );

	/**
	 * @param $resultset
	 * @return array[]
	 */
	public function getDocuments( $resultset );
}