This commit is contained in:
Jacky 2017-11-03 17:04:48 -04:00
commit 3a3083a1de
19 changed files with 544 additions and 9667 deletions

View File

@ -0,0 +1,19 @@
Copyright (c) 2010 Dave Perrett, http://recursive-design.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -33,17 +33,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.commands.cell; package com.google.refine.commands.cell;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.json.JSONArray;
import com.google.refine.commands.Command; import com.google.refine.commands.Command;
import com.google.refine.model.AbstractOperation; import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project; import com.google.refine.model.Project;
import com.google.refine.operations.cell.MultiValuedCellSplitOperation; import com.google.refine.operations.cell.MultiValuedCellSplitOperation;
import com.google.refine.util.ParsingUtilities;
import com.google.refine.process.Process; import com.google.refine.process.Process;
public class SplitMultiValueCellsCommand extends Command { public class SplitMultiValueCellsCommand extends Command {
@ -58,11 +61,33 @@ public class SplitMultiValueCellsCommand extends Command {
String keyColumnName = request.getParameter("keyColumnName"); String keyColumnName = request.getParameter("keyColumnName");
String separator = request.getParameter("separator"); String separator = request.getParameter("separator");
String mode = request.getParameter("mode"); String mode = request.getParameter("mode");
Boolean regex = Boolean.parseBoolean(request.getParameter("regex"));
AbstractOperation op = new MultiValuedCellSplitOperation(columnName, keyColumnName, separator, mode);
Process process = op.createProcess(project, new Properties()); if ("separator".equals(mode)) {
AbstractOperation op = new MultiValuedCellSplitOperation(columnName,
performProcessAndRespond(request, response, project, process); keyColumnName,
separator,
regex);
Process process = op.createProcess(project, new Properties());
performProcessAndRespond(request, response, project, process);
} else {
String s = request.getParameter("fieldLengths");
JSONArray a = ParsingUtilities.evaluateJsonStringToArray(s);
int[] fieldLengths = new int[a.length()];
for (int i = 0; i < fieldLengths.length; i++) {
fieldLengths[i] = a.getInt(i);
}
AbstractOperation op = new MultiValuedCellSplitOperation(columnName,
keyColumnName,
fieldLengths);
Process process = op.createProcess(project, new Properties());
performProcessAndRespond(request, response, project, process);
}
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);
} }

View File

@ -33,9 +33,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.operations.cell; package com.google.refine.operations.cell;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.json.JSONException; import org.json.JSONException;
@ -50,32 +51,64 @@ import com.google.refine.model.Project;
import com.google.refine.model.Row; import com.google.refine.model.Row;
import com.google.refine.model.changes.MassRowChange; import com.google.refine.model.changes.MassRowChange;
import com.google.refine.operations.OperationRegistry; import com.google.refine.operations.OperationRegistry;
import com.google.refine.util.JSONUtilities;
public class MultiValuedCellSplitOperation extends AbstractOperation { public class MultiValuedCellSplitOperation extends AbstractOperation {
final protected String _columnName; final protected String _columnName;
final protected String _keyColumnName; final protected String _keyColumnName;
final protected String _separator;
final protected String _mode; final protected String _mode;
final protected String _separator;
final protected boolean _regex;
final protected int[] _fieldLengths;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
return new MultiValuedCellSplitOperation( String mode = obj.getString("mode");
obj.getString("columnName"),
obj.getString("keyColumnName"), if ("separator".equals(mode)) {
obj.getString("separator"), return new MultiValuedCellSplitOperation(
obj.getString("mode") obj.getString("columnName"),
); obj.getString("keyColumnName"),
obj.getString("separator"),
obj.getBoolean("regex")
);
} else {
return new MultiValuedCellSplitOperation(
obj.getString("columnName"),
obj.getString("keyColumnName"),
JSONUtilities.getIntArray(obj, "fieldLengths")
);
}
} }
public MultiValuedCellSplitOperation( public MultiValuedCellSplitOperation(
String columnName, String columnName,
String keyColumnName, String keyColumnName,
String separator, String separator,
String mode boolean regex
) { ) {
_columnName = columnName; _columnName = columnName;
_keyColumnName = keyColumnName; _keyColumnName = keyColumnName;
_separator = separator; _separator = separator;
_mode = mode; _mode = "separator";
_regex = regex;
_fieldLengths = null;
}
public MultiValuedCellSplitOperation(
String columnName,
String keyColumnName,
int[] fieldLengths
) {
_columnName = columnName;
_keyColumnName = keyColumnName;
_mode = "lengths";
_separator = null;
_regex = false;
_fieldLengths = fieldLengths;
} }
@Override @Override
@ -87,8 +120,17 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
writer.key("description"); writer.value("Split multi-valued cells in column " + _columnName); writer.key("description"); writer.value("Split multi-valued cells in column " + _columnName);
writer.key("columnName"); writer.value(_columnName); writer.key("columnName"); writer.value(_columnName);
writer.key("keyColumnName"); writer.value(_keyColumnName); writer.key("keyColumnName"); writer.value(_keyColumnName);
writer.key("separator"); writer.value(_separator);
writer.key("mode"); writer.value(_mode); writer.key("mode"); writer.value(_mode);
if ("separator".equals(_mode)) {
writer.key("separator"); writer.value(_separator);
writer.key("regex"); writer.value(_regex);
} else {
writer.key("fieldLengths"); writer.array();
for (int l : _fieldLengths) {
writer.value(l);
}
writer.endArray();
}
writer.endObject(); writer.endObject();
} }
@ -110,7 +152,7 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
throw new Exception("No key column named " + _keyColumnName); throw new Exception("No key column named " + _keyColumnName);
} }
int keyCellIndex = keyColumn.getCellIndex(); int keyCellIndex = keyColumn.getCellIndex();
List<Row> newRows = new ArrayList<Row>(); List<Row> newRows = new ArrayList<Row>();
int oldRowCount = project.rows.size(); int oldRowCount = project.rows.size();
@ -124,8 +166,28 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
Object value = oldRow.getCellValue(cellIndex); Object value = oldRow.getCellValue(cellIndex);
String s = value instanceof String ? ((String) value) : value.toString(); String s = value instanceof String ? ((String) value) : value.toString();
String[] values = null; String[] values = null;
if (_mode.equals("regex")) { if("lengths".equals(_mode)) {
values = s.split(_separator); if (_fieldLengths.length >= 0 && _fieldLengths[0] > 0) {
values = new String[_fieldLengths.length];
int lastIndex = 0;
for (int i = 0; i < _fieldLengths.length; i++) {
int thisIndex = lastIndex;
Object o = _fieldLengths[i];
if (o instanceof Number) {
thisIndex = Math.min(s.length(), lastIndex + Math.max(0, ((Number) o).intValue()));
}
values[i] = s.substring(lastIndex, thisIndex);
lastIndex = thisIndex;
}
}
}
else if (_regex) {
Pattern pattern = Pattern.compile(_separator);
values = pattern.split(s);
} else { } else {
values = StringUtils.splitByWholeSeparatorPreserveAllTokens(s, _separator); values = StringUtils.splitByWholeSeparatorPreserveAllTokens(s, _separator);
} }
@ -138,14 +200,14 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
// First value goes into the same row // First value goes into the same row
{ {
Row firstNewRow = oldRow.dup(); Row firstNewRow = oldRow.dup();
firstNewRow.setCell(cellIndex, new Cell(values[0].trim(), null)); firstNewRow.setCell(cellIndex, new Cell(values[0], null));
newRows.add(firstNewRow); newRows.add(firstNewRow);
} }
int r2 = r + 1; int r2 = r + 1;
for (int v = 1; v < values.length; v++) { for (int v = 1; v < values.length; v++) {
Cell newCell = new Cell(values[v].trim(), null); Cell newCell = new Cell(values[v], null);
if (r2 < project.rows.size()) { if (r2 < project.rows.size()) {
Row oldRow2 = project.rows.get(r2); Row oldRow2 = project.rows.get(r2);

View File

@ -0,0 +1,223 @@
/*
Copyright 2010, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.google.refine.tests.model;
import static org.mockito.Mockito.mock;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.Properties;
import java.util.List;
import java.util.ArrayList;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.ProjectManager;
import com.google.refine.ProjectMetadata;
import com.google.refine.RefineServlet;
import com.google.refine.importers.SeparatorBasedImporter;
import com.google.refine.importing.ImportingJob;
import com.google.refine.importing.ImportingManager;
import com.google.refine.io.FileProjectManager;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.ModelException;
import com.google.refine.model.Project;
import com.google.refine.process.Process;
import com.google.refine.operations.cell.MultiValuedCellSplitOperation;
import com.google.refine.tests.RefineServletStub;
import com.google.refine.tests.RefineTest;
import com.google.refine.tests.util.TestUtils;
public class SplitMultiValuedCellsTests extends RefineTest {
// dependencies
private RefineServlet servlet;
private Project project;
private ProjectMetadata pm;
private JSONObject options;
private ImportingJob job;
private SeparatorBasedImporter importer;
@Override
@BeforeTest
public void init() {
logger = LoggerFactory.getLogger(this.getClass());
}
@BeforeMethod
public void SetUp() throws JSONException, IOException, ModelException {
servlet = new RefineServletStub();
File dir = TestUtils.createTempDirectory("openrefine-test-workspace-dir");
FileProjectManager.initialize(dir);
project = new Project();
pm = new ProjectMetadata();
pm.setName("SplitMultiValuedCells test");
ProjectManager.singleton.registerProject(project, pm);
options = mock(JSONObject.class);
ImportingManager.initialize(servlet);
job = ImportingManager.createJob();
importer = new SeparatorBasedImporter();
}
@AfterMethod
public void TearDown() {
ImportingManager.disposeJob(job.id);
ProjectManager.singleton.deleteProject(project.id);
job = null;
project = null;
pm = null;
options = null;
}
/**
* Test to demonstrate the intended behaviour of the function, for issue #1268
* https://github.com/OpenRefine/OpenRefine/issues/1268
*/
@Test
public void testSplitMultiValuedCellsTextSeparator() throws Exception {
String csv = "Key,Value\n"
+ "Record_1,one:two;three four\n";
prepareOptions(",", 10, 0, 0, 1, false, false);
List<Exception> exceptions = new ArrayList<Exception>();
importer.parseOneFile(project, pm, job, "filesource", new StringReader(csv), -1, options, exceptions);
project.update();
ProjectManager.singleton.registerProject(project, pm);
AbstractOperation op = new MultiValuedCellSplitOperation(
"Value",
"Key",
":",
false);
Process process = op.createProcess(project, new Properties());
process.performImmediate();
int keyCol = project.columnModel.getColumnByName("Key").getCellIndex();
int valueCol = project.columnModel.getColumnByName("Value").getCellIndex();
Assert.assertEquals(project.rows.get(0).getCellValue(keyCol), "Record_1");
Assert.assertEquals(project.rows.get(0).getCellValue(valueCol), "one");
Assert.assertEquals(project.rows.get(1).getCellValue(keyCol), null);
Assert.assertEquals(project.rows.get(1).getCellValue(valueCol), "two;three four");
}
@Test
public void testSplitMultiValuedCellsRegExSeparator() throws Exception {
String csv = "Key,Value\n"
+ "Record_1,one:two;three four\n";
prepareOptions(",", 10, 0, 0, 1, false, false);
List<Exception> exceptions = new ArrayList<Exception>();
importer.parseOneFile(project, pm, job, "filesource", new StringReader(csv), -1, options, exceptions);
project.update();
ProjectManager.singleton.registerProject(project, pm);
AbstractOperation op = new MultiValuedCellSplitOperation(
"Value",
"Key",
"\\W",
true);
Process process = op.createProcess(project, new Properties());
process.performImmediate();
int keyCol = project.columnModel.getColumnByName("Key").getCellIndex();
int valueCol = project.columnModel.getColumnByName("Value").getCellIndex();
Assert.assertEquals(project.rows.get(0).getCellValue(keyCol), "Record_1");
Assert.assertEquals(project.rows.get(0).getCellValue(valueCol), "one");
Assert.assertEquals(project.rows.get(1).getCellValue(keyCol), null);
Assert.assertEquals(project.rows.get(1).getCellValue(valueCol), "two");
Assert.assertEquals(project.rows.get(2).getCellValue(keyCol), null);
Assert.assertEquals(project.rows.get(2).getCellValue(valueCol), "three");
Assert.assertEquals(project.rows.get(3).getCellValue(keyCol), null);
Assert.assertEquals(project.rows.get(3).getCellValue(valueCol), "four");
}
@Test
public void testSplitMultiValuedCellsLengths() throws Exception {
String csv = "Key,Value\n"
+ "Record_1,one:two;three four\n";
prepareOptions(",", 10, 0, 0, 1, false, false);
List<Exception> exceptions = new ArrayList<Exception>();
importer.parseOneFile(project, pm, job, "filesource", new StringReader(csv), -1, options, exceptions);
project.update();
ProjectManager.singleton.registerProject(project, pm);
int[] lengths = {4,4,6,4};
AbstractOperation op = new MultiValuedCellSplitOperation(
"Value",
"Key",
lengths);
Process process = op.createProcess(project, new Properties());
process.performImmediate();
int keyCol = project.columnModel.getColumnByName("Key").getCellIndex();
int valueCol = project.columnModel.getColumnByName("Value").getCellIndex();
Assert.assertEquals(project.rows.get(0).getCellValue(keyCol), "Record_1");
Assert.assertEquals(project.rows.get(0).getCellValue(valueCol), "one:");
Assert.assertEquals(project.rows.get(1).getCellValue(keyCol), null);
Assert.assertEquals(project.rows.get(1).getCellValue(valueCol), "two;");
Assert.assertEquals(project.rows.get(2).getCellValue(keyCol), null);
Assert.assertEquals(project.rows.get(2).getCellValue(valueCol), "three ");
Assert.assertEquals(project.rows.get(3).getCellValue(keyCol), null);
Assert.assertEquals(project.rows.get(3).getCellValue(valueCol), "four");
}
private void prepareOptions(
String sep, int limit, int skip, int ignoreLines,
int headerLines, boolean guessValueType, boolean ignoreQuotes) {
whenGetStringOption("separator", options, sep);
whenGetIntegerOption("limit", options, limit);
whenGetIntegerOption("skipDataLines", options, skip);
whenGetIntegerOption("ignoreLines", options, ignoreLines);
whenGetIntegerOption("headerLines", options, headerLines);
whenGetBooleanOption("guessCellValueTypes", options, guessValueType);
whenGetBooleanOption("processQuotes", options, !ignoreQuotes);
whenGetBooleanOption("storeBlankCellsAsNulls", options, true);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +1,4 @@
/*! jQuery based internationalization library, Copyright 2010 Dave Perrett, http://recursive-design.com/
* Released under the MIT license -- https://opensource.org/licenses/MIT */
(function(f){f.i18n={dict:null,plural:null,setDictionary:function(a){null===this.dict?this.dict=a:f.extend(this.dict,a)},setPlural:function(a){this.plural=a},_p:function(a,d,e){var c=this.dict[a],b=[];b.push(e);if(void 0===c||null===this.plural)return this.printf(1<e?d:a,b);a=this.plural.replace(/n%/g,e+"%");eval(a);return this.printf(c[plural],b)},_:function(a,d){var e=a;this.dict&&this.dict[a]&&(e=this.dict[a]);return this.printf(e,d)},printf:function(a,d){if(!d)return a;for(var e="",c=/%(\d+)\$s/g, (function(f){f.i18n={dict:null,plural:null,setDictionary:function(a){null===this.dict?this.dict=a:f.extend(this.dict,a)},setPlural:function(a){this.plural=a},_p:function(a,d,e){var c=this.dict[a],b=[];b.push(e);if(void 0===c||null===this.plural)return this.printf(1<e?d:a,b);a=this.plural.replace(/n%/g,e+"%");eval(a);return this.printf(c[plural],b)},_:function(a,d){var e=a;this.dict&&this.dict[a]&&(e=this.dict[a]);return this.printf(e,d)},printf:function(a,d){if(!d)return a;for(var e="",c=/%(\d+)\$s/g,
b=c.exec(a);b;){var f=parseInt(b[1],10)-1;a=a.replace("%"+b[1]+"$s",d[f]);b=c.exec(a)}c=a.split("%s");if(1<c.length)for(b=0;b<d.length;b++)0<c[b].length&&c[b].lastIndexOf("%")==c[b].length-1&&(c[b]+="s"+c.splice(b+1,1)[0]),e+=c[b]+d[b];return e+c[c.length-1]}};f.fn._t=function(a,d){return f(this).text(f.i18n._(a,d))}})(jQuery); b=c.exec(a);b;){var f=parseInt(b[1],10)-1;a=a.replace("%"+b[1]+"$s",d[f]);b=c.exec(a)}c=a.split("%s");if(1<c.length)for(b=0;b<d.length;b++)0<c[b].length&&c[b].lastIndexOf("%")==c[b].length-1&&(c[b]+="s"+c.splice(b+1,1)[0]),e+=c[b]+d[b];return e+c[c.length-1]}};f.fn._t=function(a,d){return f(this).text(f.i18n._(a,d))}})(jQuery);

View File

@ -532,6 +532,7 @@
"split-col": "Split column", "split-col": "Split column",
"several-col": "into several columns", "several-col": "into several columns",
"how-split": "How to Split Column", "how-split": "How to Split Column",
"how-split-cells": "How to split multi-valued cells",
"by-sep": "by separator", "by-sep": "by separator",
"separator": "Separator", "separator": "Separator",
"reg-exp": "regular expression", "reg-exp": "regular expression",

View File

@ -1,7 +1,7 @@
{ {
"name": "Français", "name": "Français",
"core-index": { "core-index": {
"change-value": "Changer la valeur de la clé de préférence", "change-value": "Changer la valeur de cette préférence",
"preferences": "Préférences", "preferences": "Préférences",
"about": "À propos", "about": "À propos",
"slogan": "Un outil puissant pour travailler avec des données désordonnées", "slogan": "Un outil puissant pour travailler avec des données désordonnées",
@ -10,17 +10,17 @@
"edit": "Éditer", "edit": "Éditer",
"add-pref": "Ajouter une préférence", "add-pref": "Ajouter une préférence",
"value": "Valeur", "value": "Valeur",
"no-proj": "Aucun projet nexiste. Cliquer sur 'Créer un projet' sur la gauche pour créer un nouveau projet.", "no-proj": "Aucun projet nexiste. Cliquer sur \"Créer un projet\" sur la gauche pour créer un nouveau projet.",
"try-these": "Si vous ne disposez daucun jeu de données, vous pouvez essayer ces", "try-these": "Si vous ne disposez daucun jeu de données, vous pouvez essayer ces",
"version": "Version", "version": "Version",
"key": "Clé", "key": "Préférence",
"error-rename": "Échec du renommage du projet :", "error-rename": "Échec du renommage du projet :",
"download": "Télécharger", "download": "Télécharger",
"sample-data": "jeux de données d'exemple", "sample-data": "jeux de données d'exemple",
"new-version": "Nouvelle version !", "new-version": "Nouvelle version !",
"now": "maintenant", "now": "maintenant",
"delete-key": "Supprimer la clé de préférence", "delete-key": "Supprimer la préférence",
"pref-key": "Valeur de la clé de préférence :", "pref-key": "Valeur de la préférence :",
"delete": "Supprimer" "delete": "Supprimer"
}, },
"core-index-create": { "core-index-create": {
@ -85,7 +85,7 @@
}, },
"core-index-open": { "core-index-open": {
"rename": "renommer", "rename": "renommer",
"del-body": "Êtes-vous sûr de supprimer ce projet \"", "del-body": "Êtes-vous sûr de vouloir supprimer ce projet \"",
"open-proj": "Ouvrir un projet", "open-proj": "Ouvrir un projet",
"browse": "Parcourir le dossier de lespace de travail", "browse": "Parcourir le dossier de lespace de travail",
"warning-proj-name": "Vous devez donner un nom au projet.", "warning-proj-name": "Vous devez donner un nom au projet.",
@ -99,7 +99,7 @@
"core-index-lang": { "core-index-lang": {
"lang-settings": "Langue", "lang-settings": "Langue",
"send-req": "Changer la langue", "send-req": "Changer la langue",
"page-reload": "Cette page doit être actualisée pour appliquer le changement.", "page-reload": "Cette page sera actualisée pour appliquer le changement.",
"label": "Choisir sa langue préférée" "label": "Choisir sa langue préférée"
}, },
"core-index-parser": { "core-index-parser": {
@ -134,7 +134,7 @@
}, },
"core-dialogs": { "core-dialogs": {
"help": "Aide", "help": "Aide",
"medium-format": "Format local moyen", "medium-format": "Format moyen",
"html-table": "Table HTML", "html-table": "Table HTML",
"internal-err": "Erreur interne", "internal-err": "Erreur interne",
"from-total": "</b> total", "from-total": "</b> total",
@ -144,11 +144,11 @@
"keying-function": "Fonction de codage", "keying-function": "Fonction de codage",
"reuse": "Réutiliser", "reuse": "Réutiliser",
"date-format": "Pour la date/heure, utiliser le format", "date-format": "Pour la date/heure, utiliser le format",
"focusing-on": "centre sur", "focusing-on": "centrer sur",
"fingerprint": "empreinte", "fingerprint": "empreinte",
"block-chars": "Bloc de caractères", "block-chars": "Bloc de caractères",
"long-format": "Format local long", "long-format": "Format long",
"short-format": "Format local court", "short-format": "Format court",
"leven": "Levenshtein", "leven": "Levenshtein",
"rotated-clock": "Tourné de 45°", "rotated-clock": "Tourné de 45°",
"upload": "Téléverser", "upload": "Téléverser",
@ -323,7 +323,7 @@
"watch-cast": "Regarder ces tutoriels vidéos", "watch-cast": "Regarder ces tutoriels vidéos",
"continue-remaining": "Poursuivre avec les opérations restantes", "continue-remaining": "Poursuivre avec les opérations restantes",
"remove-all": "Supprimer toutes les facettes", "remove-all": "Supprimer toutes les facettes",
"complete": "terminer", "complete": "effectué",
"undo": "Défaire", "undo": "Défaire",
"warning-align": "Vous navez encore défini aucun schéma dalignement,\n il ny a donc aucun triplet à exporter.\n\n Utiliser la commande Freebase > Éditer le squelette du schéma dalignement...\n pour commencer par aligner vos données avec les schémas Freebase.", "warning-align": "Vous navez encore défini aucun schéma dalignement,\n il ny a donc aucun triplet à exporter.\n\n Utiliser la commande Freebase > Éditer le squelette du schéma dalignement...\n pour commencer par aligner vos données avec les schémas Freebase.",
"use-to-select": "Utiliser les facettes et les filtres pour sélectionner les sous-ensembles de données à traiter. Choisir les méthodes de facette et de filtre dans les menus situés dans les entêtes de colonne.", "use-to-select": "Utiliser les facettes et les filtres pour sélectionner les sous-ensembles de données à traiter. Choisir les méthodes de facette et de filtre dans les menus situés dans les entêtes de colonne.",
@ -367,7 +367,7 @@
"all": "Tous les encodages", "all": "Tous les encodages",
"years-ago": "années avant", "years-ago": "années avant",
"week-ago": "semaine dernière", "week-ago": "semaine dernière",
"working": "En fonctionement", "working": "En fonctionnement",
"encoding": "Encodage", "encoding": "Encodage",
"months-ago": "mois avant", "months-ago": "mois avant",
"yesterday": "hier", "yesterday": "hier",

View File

@ -158,8 +158,8 @@ ExpressionPreviewDialog.Widget.prototype.getExpression = function(commit) {
s = this._getLanguage() + ":" + s; s = this._getLanguage() + ":" + s;
if (commit) { if (commit) {
$.post( $.post(
"command/core/log-expression?" + $.param({ project: theProject.id, expression: s }), "command/core/log-expression?" + $.param({ project: theProject.id }),
null, { expression: s },
function(data) { function(data) {
}, },
"json" "json"
@ -390,7 +390,6 @@ ExpressionPreviewDialog.Widget.prototype.update = function() {
var expression = this.expression = $.trim(this._elmts.expressionPreviewTextarea[0].value); var expression = this.expression = $.trim(this._elmts.expressionPreviewTextarea[0].value);
var params = { var params = {
project: theProject.id, project: theProject.id,
expression: this._getLanguage() + ":" + expression,
cellIndex: this._cellIndex cellIndex: this._cellIndex
}; };
this._prepareUpdate(params); this._prepareUpdate(params);
@ -398,6 +397,7 @@ ExpressionPreviewDialog.Widget.prototype.update = function() {
$.post( $.post(
"command/core/preview-expression?" + $.param(params), "command/core/preview-expression?" + $.param(params),
{ {
expression: this._getLanguage() + ":" + expression,
rowIndices: JSON.stringify(this._rowIndices) rowIndices: JSON.stringify(this._rowIndices)
}, },
function(data) { function(data) {
@ -421,10 +421,12 @@ ExpressionPreviewDialog.Widget.prototype._renderPreview = function(expression, d
var table = $('<table></table>').appendTo( var table = $('<table></table>').appendTo(
$('<div>').addClass("expression-preview-table-wrapper").appendTo(container))[0]; $('<div>').addClass("expression-preview-table-wrapper").appendTo(container))[0];
var truncExpression = expression.length > 30 ? expression.substring(0, 30) + ' ...' : expression;
var tr = table.insertRow(0); var tr = table.insertRow(0);
$(tr.insertCell(0)).addClass("expression-preview-heading").text("row"); $(tr.insertCell(0)).addClass("expression-preview-heading").text("row");
$(tr.insertCell(1)).addClass("expression-preview-heading").text("value"); $(tr.insertCell(1)).addClass("expression-preview-heading").text("value");
$(tr.insertCell(2)).addClass("expression-preview-heading").text(expression); $(tr.insertCell(2)).addClass("expression-preview-heading").text(truncExpression);
var renderValue = function(td, v) { var renderValue = function(td, v) {
if (v !== null && v !== undefined) { if (v !== null && v !== undefined) {

View File

@ -178,7 +178,7 @@ Refine.reinitializeProjectData = function(f, fError) {
$.getJSON( $.getJSON(
"command/core/get-project-metadata?" + $.param({ project: theProject.id }), null, "command/core/get-project-metadata?" + $.param({ project: theProject.id }), null,
function(data) { function(data) {
if (data.status == 'error') { if (data.status == "error") {
alert(data.message); alert(data.message);
if (fError) { if (fError) {
fError(); fError();
@ -220,7 +220,7 @@ Refine._renameProject = function() {
data: { "project" : theProject.id, "name" : name }, data: { "project" : theProject.id, "name" : name },
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (data && typeof data.code != 'undefined' && data.code == "ok") { if (data && typeof data.code != "undefined" && data.code == "ok") {
theProject.metadata.name = name; theProject.metadata.name = name;
Refine.setTitle(); Refine.setTitle();
} else { } else {
@ -425,9 +425,12 @@ Refine.fetchRows = function(start, limit, onDone, sorting) {
} }
$.post( $.post(
"command/core/get-rows?" + $.param({ project: theProject.id, start: start, limit: limit }) + "&callback=?", "command/core/get-rows?" + $.param({ project: theProject.id, start: start, limit: limit }),
body, body,
function(data) { function(data) {
if(data.code === "error") {
data = theProject.rowModel;
}
theProject.rowModel = data; theProject.rowModel = data;
// Un-pool objects // Un-pool objects
@ -445,7 +448,7 @@ Refine.fetchRows = function(start, limit, onDone, sorting) {
onDone(); onDone();
} }
}, },
"jsonp" "json"
); );
}; };

View File

@ -33,7 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function BrowsingEngine(div, facetConfigs) { function BrowsingEngine(div, facetConfigs) {
this._div = div; this._div = div;
this._mode = theProject.recordModel.hasRecords ? 'record-based' : 'row-based'; this._mode = theProject.recordModel.hasRecords ? "record-based" : "row-based";
this._facets = []; this._facets = [];
this._initializeUI(); this._initializeUI();
@ -101,6 +101,7 @@ BrowsingEngine.prototype._initializeUI = function() {
'<p>'+$.i18n._('core-project')["not-sure"]+'<br /><a href="https://github.com/OpenRefine/OpenRefine/wiki/Screencasts" target="_blank"><b>'+$.i18n._('core-project')["watch-cast"]+'</b></a></p>' + '<p>'+$.i18n._('core-project')["not-sure"]+'<br /><a href="https://github.com/OpenRefine/OpenRefine/wiki/Screencasts" target="_blank"><b>'+$.i18n._('core-project')["watch-cast"]+'</b></a></p>' +
'</div>' + '</div>' +
'<div class="browsing-panel-header" bind="header">' + '<div class="browsing-panel-header" bind="header">' +
'<div class="browsing-panel-errors" bind="errors"></div>' +
'<div class="browsing-panel-indicator" bind="indicator">' + '<div class="browsing-panel-indicator" bind="indicator">' +
'<img src="images/small-spinner.gif" /> '+$.i18n._('core-project')["refreshing-facet"]+'' + '<img src="images/small-spinner.gif" /> '+$.i18n._('core-project')["refreshing-facet"]+'' +
'</div>' + '</div>' +
@ -240,19 +241,31 @@ BrowsingEngine.prototype.update = function(onDone) {
this._elmts.header.show(); this._elmts.header.show();
this._elmts.controls.css("visibility", "hidden"); this._elmts.controls.css("visibility", "hidden");
this._elmts.indicator.css("visibility", "visible"); this._elmts.indicator.css("display", "block");
$.post( $.post(
"command/core/compute-facets?" + $.param({ project: theProject.id }), "command/core/compute-facets?" + $.param({ project: theProject.id }),
{ engine: JSON.stringify(this.getJSON(true)) }, { engine: JSON.stringify(this.getJSON(true)) },
function(data) { function(data) {
if(data.code === "error") {
var clearErr = $('#err-text').remove();
var err = $('<div id="err-text">')
.text(data.message)
.appendTo(self._elmts.errors);
self._elmts.errors.css("display", "block");
if (onDone) {
onDone();
}
return;
}
var facetData = data.facets; var facetData = data.facets;
for (var i = 0; i < facetData.length; i++) { for (var i = 0; i < facetData.length; i++) {
self._facets[i].facet.updateState(facetData[i]); self._facets[i].facet.updateState(facetData[i]);
} }
self._elmts.indicator.css("visibility", "hidden"); self._elmts.indicator.css("display", "none");
self._elmts.errors.css("display", "none");
if (self._facets.length > 0) { if (self._facets.length > 0) {
self._elmts.header.show(); self._elmts.header.show();
self._elmts.controls.css("visibility", "visible"); self._elmts.controls.css("visibility", "visible");

View File

@ -96,10 +96,13 @@ ProcessPanel.prototype.showUndo = function(historyEntry) {
this._latestHistoryEntry = historyEntry; this._latestHistoryEntry = historyEntry;
truncDescription = historyEntry.description.length > 250 ?
historyEntry.description.substring(0, 250) + " ..." : historyEntry.description
this._div.stop(true, false); this._div.stop(true, false);
this._elmts.progressDiv.hide(); this._elmts.progressDiv.hide();
this._elmts.undoDiv.show(); this._elmts.undoDiv.show();
this._elmts.undoDescription.text(historyEntry.description); this._elmts.undoDescription.text( truncDescription );
this._elmts.undoLink.unbind().click(function() { self.undo(); }); this._elmts.undoLink.unbind().click(function() { self.undo(); });
this._div this._div

View File

@ -36,13 +36,12 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
Refine.postCoreProcess( Refine.postCoreProcess(
"text-transform", "text-transform",
{ {
columnName: column.name, columnName: column.name,
expression: expression,
onError: onError, onError: onError,
repeat: repeat, repeat: repeat,
repeatCount: repeatCount repeatCount: repeatCount
}, },
null, { expression: expression },
{ cellsChanged: true } { cellsChanged: true }
); );
}; };
@ -125,7 +124,7 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
{ {
columnName: column.name, columnName: column.name,
keyColumnName: theProject.columnModel.keyColumnName, keyColumnName: theProject.columnModel.keyColumnName,
separator: separator separator
}, },
null, null,
{ rowsChanged: true } { rowsChanged: true }
@ -134,20 +133,76 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
}; };
var doSplitMultiValueCells = function() { var doSplitMultiValueCells = function() {
var separator = window.prompt($.i18n._('core-views')["what-separator"], ",");
if (separator !== null) { var frame = $(DOM.loadHTML("core", "scripts/views/data-table/split-multi-valued-cells-dialog.html"));
var elmts = DOM.bind(frame);
elmts.dialogHeader.text($.i18n._('core-views')["split-cells"]);
elmts.or_views_howSplit.text($.i18n._('core-views')["how-split-cells"]);
elmts.or_views_bySep.text($.i18n._('core-views')["by-sep"]);
elmts.or_views_separator.text($.i18n._('core-views')["separator"]);
elmts.or_views_regExp.text($.i18n._('core-views')["reg-exp"]);
elmts.or_views_fieldLen.text($.i18n._('core-views')["field-len"]);
elmts.or_views_listInt.text($.i18n._('core-views')["list-int"]);
elmts.okButton.html($.i18n._('core-buttons')["ok"]);
elmts.cancelButton.text($.i18n._('core-buttons')["cancel"]);
var level = DialogSystem.showDialog(frame);
var dismiss = function() { DialogSystem.dismissUntil(level - 1); };
elmts.cancelButton.click(dismiss);
elmts.okButton.click(function() {
var mode = $("input[name='split-by-mode']:checked")[0].value;
var config = {
columnName: column.name,
keyColumnName: theProject.columnModel.keyColumnName,
mode
};
if (mode === "separator") {
config.separator = elmts.separatorInput[0].value;
if (!(config.separator)) {
alert($.i18n._('core-views')["specify-sep"]);
return;
}
config.regex = elmts.regexInput[0].checked;
} else {
var s = "[" + elmts.lengthsTextarea[0].value + "]";
try {
var a = JSON.parse(s);
var lengths = [];
$.each(a, function(i,n) {
if (typeof n == "number") {
lengths.push(n);
}
});
if (lengths.length === 0) {
alert($.i18n._('core-views')["warning-no-length"]);
return;
}
config.fieldLengths = JSON.stringify(lengths);
} catch (e) {
alert($.i18n._('core-views')["warning-format"]);
return;
}
}
Refine.postCoreProcess( Refine.postCoreProcess(
"split-multi-value-cells", "split-multi-value-cells",
{ config,
columnName: column.name,
keyColumnName: theProject.columnModel.keyColumnName,
separator: separator,
mode: "plain"
},
null, null,
{ rowsChanged: true } { rowsChanged: true }
); );
}
dismiss();
});
}; };
MenuSystem.appendTo(menu, [ "core/edit-cells" ], [ MenuSystem.appendTo(menu, [ "core/edit-cells" ], [

View File

@ -72,13 +72,12 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
Refine.postCoreProcess( Refine.postCoreProcess(
"add-column", "add-column",
{ {
baseColumnName: column.name, baseColumnName: column.name,
expression: previewWidget.getExpression(true),
newColumnName: columnName, newColumnName: columnName,
columnInsertIndex: columnIndex + 1, columnInsertIndex: columnIndex + 1,
onError: $('input[name="create-column-dialog-onerror-choice"]:checked')[0].value onError: $('input[name="create-column-dialog-onerror-choice"]:checked')[0].value
}, },
null, { expression: previewWidget.getExpression(true) },
{ modelsChanged: true }, { modelsChanged: true },
{ {
onDone: function(o) { onDone: function(o) {

View File

@ -0,0 +1,40 @@
<div class="dialog-frame" style="width: 600px;">
<div class="dialog-border">
<div class="dialog-header" bind="dialogHeader"></div>
<div class="dialog-body" bind="dialogBody">
<div class="grid-layout layout-looser layout-full"><table><tr>
<td>
<div class="grid-layout layout-tighter"><table>
<tr>
<td colspan="3"><h3><span bind="or_views_howSplit"></span></h3></td>
</tr>
<tr>
<td width="1%"><input type="radio" checked="true" name="split-by-mode" value="separator" id="$split-multi-valued-cells-by-separator" /></td>
<td colspan="2"><label for="$split-multi-valued-cells-by-separator" bind="or_views_bySep"></label></td>
</tr>
<tr><td></td>
<td bind="or_views_separator"></td>
<td><input size="10" value="," bind="separatorInput" />
<input type="checkbox" bind="regexInput" id="$split-column-regex" />
<label for="$split-multi-valued-cells-regex" bind="or_views_regExp"></label></td>
</tr>
<tr>
<td width="1%"><input type="radio" name="split-by-mode" value="lengths" id="$split-multi-valued-cells-by-lengths" /></td>
<td colspan="2"><label for="$split-multi-valued-cells-by-lengths" bind="or_views_fieldLen"></label></td>
</tr>
<tr><td></td>
<td colspan="2"><textarea style="width: 100%;" bind="lengthsTextarea"></textarea></td>
</tr>
<tr><td></td>
<td colspan="2" bind="or_views_listInt"></td>
</tr>
</table></div>
</td>
</table></div>
</div>
<div class="dialog-footer" bind="dialogFooter">
<button class="button" bind="okButton"></button>
<button class="button" bind="cancelButton"></button>
</div>
</div>
</div>

View File

@ -38,9 +38,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
display: none; display: none;
} }
.browsing-panel-errors {
display: none;
position: relative;
height: auto;
margin: 5px;
text-align: center;
background: #fff0f4;
color: #c51244;
padding: 4px 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border: 1px solid #ccc;
}
.browsing-panel-indicator { .browsing-panel-indicator {
visibility: hidden; display: none;
position: absolute; position: relative;
width: 50%; width: 50%;
margin: 5px; margin: 5px;
top: 0em; top: 0em;

21
refine
View File

@ -823,6 +823,22 @@ whitespace() {
done done
} }
checkJavaMajorVersion() {
java_ver=$($JAVA -version 2>&1 | grep version | cut -d ' ' -f 3 | tr -d \")
# Java 6, 7, 8 starts with 1.x
if [ ${java_ver:0:2} == "1." ] ; then
major=`echo ${java_ver} | sed -E 's/1\.([0-9])[0-9_.]{2,6}/\1/g'`
else
# Java 9+ starts with x using semver versioning
major=`echo ${java_ver} | sed -E 's/([0-9]+)(-ea|(\.[0-9]+)*)/\1/g'`
fi
JAVA_VERSION=$(echo ${major} | egrep '^(6|7|8|9)')
if [ -z "$JAVA_VERSION" ] ; then
error "OpenRefine requires Java version 6 or later. If you have multiple versions of Java installed, please set the environment variable JAVA_HOME to the correct version."
fi
}
# -------------------------- script ----------------------------- # -------------------------- script -----------------------------
# ----- Normalize the current directory ------------------------- # ----- Normalize the current directory -------------------------
@ -873,10 +889,7 @@ if [ ! -x "$JAVA" ] ; then
error "Could not find the 'java' executable at '$JAVA', are you sure your JAVA_HOME environment variable is pointing to a proper java installation?" error "Could not find the 'java' executable at '$JAVA', are you sure your JAVA_HOME environment variable is pointing to a proper java installation?"
fi fi
JAVA_VERSION=`$JAVA -version 2>&1 | grep version | cut -d ' ' -f 3 | egrep '^\"1\.(6|7|8|9)'` checkJavaMajorVersion
if [ -z "$JAVA_VERSION" ] ; then
error "OpenRefine requires Java version 6 or later. If you have multiple versions of Java installed, please set the environment variable JAVA_HOME to the correct version."
fi
# ----- Parse the command line args ------------------------------------------ # ----- Parse the command line args ------------------------------------------