Try to roundtrip reconciled IDs as much as possible when import/export as Excel files.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@322 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
5db6ee8ae5
commit
8dd0dea472
@ -76,26 +76,29 @@ public class XlsExporter implements Exporter {
|
||||
int cellIndex = column.getCellIndex();
|
||||
if (cellIndex < row.cells.size()) {
|
||||
Cell cell = row.cells.get(cellIndex);
|
||||
if (cell != null && cell.value != null) {
|
||||
Object v = cell.value;
|
||||
if (v instanceof Number) {
|
||||
c.setCellValue(((Number) v).doubleValue());
|
||||
} else if (v instanceof Boolean) {
|
||||
c.setCellValue(((Boolean) v).booleanValue());
|
||||
} else if (v instanceof Date) {
|
||||
c.setCellValue((Date) v);
|
||||
} else if (v instanceof Calendar) {
|
||||
c.setCellValue((Calendar) v);
|
||||
} else if (v instanceof String) {
|
||||
c.setCellValue((String) v);
|
||||
}
|
||||
|
||||
if (cell != null) {
|
||||
if (cell.recon != null && cell.recon.match != null) {
|
||||
c.setCellValue(cell.recon.match.topicName);
|
||||
|
||||
HSSFHyperlink hl = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
|
||||
hl.setLabel(cell.recon.match.topicName);
|
||||
hl.setAddress("http://www.freebase.com/view" + cell.recon.match.topicID);
|
||||
|
||||
c.setHyperlink(hl);
|
||||
} else if (cell.value != null) {
|
||||
Object v = cell.value;
|
||||
|
||||
if (v instanceof Number) {
|
||||
c.setCellValue(((Number) v).doubleValue());
|
||||
} else if (v instanceof Boolean) {
|
||||
c.setCellValue(((Boolean) v).booleanValue());
|
||||
} else if (v instanceof Date) {
|
||||
c.setCellValue((Date) v);
|
||||
} else if (v instanceof Calendar) {
|
||||
c.setCellValue((Calendar) v);
|
||||
} else if (v instanceof String) {
|
||||
c.setCellValue((String) v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
import org.apache.poi.common.usermodel.Hyperlink;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
@ -18,7 +19,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import com.metaweb.gridworks.model.Cell;
|
||||
import com.metaweb.gridworks.model.Column;
|
||||
import com.metaweb.gridworks.model.Project;
|
||||
import com.metaweb.gridworks.model.Recon;
|
||||
import com.metaweb.gridworks.model.ReconCandidate;
|
||||
import com.metaweb.gridworks.model.Row;
|
||||
import com.metaweb.gridworks.model.Recon.Judgment;
|
||||
|
||||
public class ExcelImporter implements Importer {
|
||||
final protected boolean _xmlBased;
|
||||
@ -155,7 +159,39 @@ public class ExcelImporter implements Importer {
|
||||
}
|
||||
|
||||
if (value != null) {
|
||||
newRow.setCell(c, new Cell(value, null));
|
||||
Recon recon = null;
|
||||
|
||||
Hyperlink hyperlink = cell.getHyperlink();
|
||||
if (hyperlink != null) {
|
||||
String url = hyperlink.getAddress();
|
||||
|
||||
if (url.startsWith("http://") ||
|
||||
url.startsWith("https://")) {
|
||||
|
||||
final String sig = "freebase.com/view";
|
||||
|
||||
int i = url.indexOf(sig);
|
||||
if (i > 0) {
|
||||
String id = url.substring(i + sig.length());
|
||||
|
||||
int q = id.indexOf('?');
|
||||
if (q > 0) {
|
||||
id = id.substring(0, q);
|
||||
}
|
||||
int h = id.indexOf('#');
|
||||
if (h > 0) {
|
||||
id = id.substring(0, h);
|
||||
}
|
||||
|
||||
recon = new Recon();
|
||||
recon.judgment = Judgment.Matched;
|
||||
recon.match = new ReconCandidate(id, "", value.toString(), new String[0], 100);
|
||||
recon.addCandidate(recon.match);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newRow.setCell(c, new Cell(value, recon));
|
||||
hasData = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user