/** * Loads the gazetteer lists and maps them to the nodes * * @return a map of nodes vs GazetteerLists * @param isOrdered true if the feature maps used should be ordered * @throws ResourceInstantiationException when the resource cannot be * created */ public Map<LinearNode, GazetteerList> loadLists(boolean isOrdered) throws ResourceInstantiationException { try { gazListsByNode = new HashMap<LinearNode, GazetteerList>(); Iterator<LinearNode> inodes = nodes.iterator(); while(inodes.hasNext()) { LinearNode node = inodes.next(); GazetteerList list = new GazetteerList(); list.setSeparator(separator); URL lurl = new URL(url, node.getList()); list.setURL(lurl); list.setEncoding(encoding); list.load(isOrdered); gazListsByNode.put(node, list); } // while inodes } catch(Exception ex) { throw new ResourceInstantiationException(ex); } return gazListsByNode; } // loadLists()
@Override public void fireTableChanged(TableModelEvent e) { if (gazetteerList == null) { return; } if (filter.length() < 1) { gazetteerListFiltered.clear(); gazetteerListFiltered.addAll(gazetteerList); super.fireTableChanged(e); } else { filterRows(); // same as super.fireTableDataChanged() to avoid recursion super.fireTableChanged(new TableModelEvent(this)); } }
for (Object object : linearDefinition.getListsByNode().values()) { GazetteerList gazetteerList = (GazetteerList) object; previousURL = gazetteerList.getURL(); gazetteerList.setURL(new File(selectedFile.getParentFile(), Files.fileFromURL(gazetteerList.getURL()).getName()) .toURI().toURL()); gazetteerList.store(); gazetteerList.setURL(previousURL); gazetteerList.setModified(false);
GazetteerList theList = theLists.get(iter1.next()); try { if(theList.isModified()) theList.store(); } catch(ResourceInstantiationException ex) { throw new GateRuntimeException(ex.getMessage());
LinearDefinition ld = gazetter.getLinearDefinition(); //add .lst record LinearNode ln = new LinearNode("glossary.lst", "minor", "major", "en", "AnnotType"); ld.add(ln); //add Lookup record Map<String, Object> features = new HashMap<>(); features.put("someFeatureName", "some value"); GazetteerNode gn = new GazetteerNode("string to be found", features); gn.setSeparator("@"); GazetteerList theList = ld.getListsByNode().get(ln); theList.add(gn); //save updated files theList.store(); ld.store(); //optionally re-init the gazetteer to make changes to work gazetter.reInit();
while(theListsIter.hasNext() && listName.equals("")) { theList = theListsIter.next(); if(theList.getURL().toExternalForm().endsWith(annotType + ".lst")) listName = theList.getURL().toExternalForm(); theLanguage)); theList.add(new GazetteerNode(text)); gazetteer.add(theString, new Lookup(listName, annotType, "inferred", theLanguage)); theList.add(new GazetteerNode(theString));
public void addRow(GazetteerNode gazetteerNode) { gazetteerList.add(gazetteerNode); }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); setForeground(table.getForeground()); LinearNode linearNode = linearDefinition.getNodesByListNames().get(value); if (linearNode != null) { GazetteerList gazetteerList = linearDefinition.getListsByNode().get(linearNode); if (gazetteerList != null && gazetteerList.isModified()) { setForeground(Color.RED); } } return this; } });
@Override public void actionPerformed(ActionEvent e) { if (selectedLinearNode == null) { return; } GazetteerList gazetteerList = linearDefinition.getListsByNode().get(selectedLinearNode); gazetteerList.clear(); try { gazetteerList.load(true); } catch (ResourceInstantiationException rie) { rie.printStackTrace(); return; } // reselect the row to redisplay the list int row = definitionTable.getSelectedRow(); definitionTable.clearSelection(); definitionTable.getSelectionModel().setSelectionInterval(row, row); } }
} catch(Exception ex) { throw new GateRuntimeException("Could not read gazetteer entry " + linenr + " from URL " + getURL() + ": " + ex.getMessage(), ex);
"\\Q"+linearDefinition.getSeparator()+"\\E", ""); GazetteerNode gazetteerNode = gazetteerListFiltered.get(row); if (column == 0) { fireTableRowsUpdated(row, row); gazetteerList.setModified(true); definitionTable.repaint();
public ListTableModel() { gazetteerListFiltered = new GazetteerList(); }
@Override public Object getValueAt(int row, int column) { GazetteerNode node = gazetteerListFiltered.get(row); if (column == 0) { return node.getEntry(); } else { Map<String,Object> featureMap = node.getFeatureMap(); if (featureMap == null || featureMap.size()*2 < column) { return ""; } List<String> features = new ArrayList<String>(featureMap.keySet()); int featureCount = (column + (column % 2)) / 2; if (column % 2 == 1) { return features.get(featureCount-1); } else { return featureMap.get(features.get(featureCount-1)); } } }
clear(); entries = tempEntries; break;
&& oldListFileName.equals(newListFileName)) { return; } try { // save the previous list gazetteerList.store(); MainFrame.getInstance().statusChanged("Previous list saved in " + gazetteerList.getURL().getPath()); } catch (ResourceInstantiationException rie) { Err.prln("Unable to save the list.\n" + rie.getMessage()); File source = Files.fileFromURL(gazetteerList.getURL()); File destination = new File(source.getParentFile(), newListFileName); gazetteerList.setURL(destination.toURI().toURL()); gazetteerList.setModified(false); } catch (MalformedURLException mue) { Err.prln("File name invalid.\n" + mue.getMessage());
@Override public void actionPerformed(ActionEvent e) { try { if (linearDefinition.isModified()) { linearDefinition.store(); } for (Object object : linearDefinition.getListsByNode().values()) { GazetteerList gazetteerList = (GazetteerList) object; if (gazetteerList.isModified()) { gazetteerList.store(); } } gazetteer.reInit(); MainFrame.getInstance().statusChanged("Gazetteer saved in " + linearDefinition.getURL().getPath()); definitionTable.repaint(); } catch (ResourceInstantiationException re) { MainFrame.getInstance().statusChanged( "Unable to save the Gazetteer."); Err.prln("Unable to save the Gazetteer.\n" + re.getMessage()); } } }
listTableModel.setGazetteerList(new GazetteerList()); selectedLinearNode = null; listEntryTextField.setEnabled(false);