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();
@Override public boolean accept(File dir, String name) { return name.endsWith(".lst") && !linearDefinition.getLists().contains(name); } });
@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 (linearDefinition.getSeparator() == null || linearDefinition.getSeparator().length() == 0) { String separator = JOptionPane.showInputDialog( MainFrame.getInstance(), "Type a character separator to separate" + "\nfeatures in the gazetteers lists.", "Feature Separator", JOptionPane.QUESTION_MESSAGE); if (separator == null || separator.equals("")) { return; } linearDefinition.setSeparator(separator); } listTableModel.addEmptyFeatureColumns(); // cancel filtering and redisplay the table listEntryTextField.setText(""); listTableModel.setFilterText(""); listTableModel.fireTableStructureChanged(); } });
"No URL provided for gazetteer creation!"); definition = new LinearDefinition(); definition.setSeparator(Strings.unescape(gazetteerFeatureSeparator)); try { definition.setURL(listsURL.toURL()); definition.load(); int linesCnt = definition.size(); listsByNode = definition.loadLists(); Iterator<LinearNode> inodes = definition.iterator();
@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()); } } }
linearDefinition.add(linearNode); linearDefinition.getNodesByListNames().put(listName, linearNode); GazetteerList gazetteerList; try { gazetteerList = linearDefinition.loadSingleList(listName, true); } catch (ResourceInstantiationException rie) { rie.printStackTrace(); return; linearDefinition.getListsByNode().put(linearNode, gazetteerList);
if (selectedFile == null) { return; } try { URL previousURL = linearDefinition.getURL(); linearDefinition.setURL(selectedFile.toURI().toURL()); linearDefinition.store(); linearDefinition.setURL(previousURL); for (Object object : linearDefinition.getListsByNode().values()) { GazetteerList gazetteerList = (GazetteerList) object; previousURL = gazetteerList.getURL();
int row = e.getFirstRow(); int column = e.getColumn(); GazetteerList gazetteerList = linearDefinition.getListsByNode().get(selectedLinearNode); switch (e.getType()) { case TableModelEvent.UPDATE: linearDefinition.getListsByNode().remove(selectedLinearNode); linearDefinition.getListsByNode() .put(selectedLinearNode, gazetteerList); linearDefinition.getNodesByListNames().remove(oldListFileName); linearDefinition.getNodesByListNames() .put(newListFileName, selectedLinearNode); linearDefinition.setModified(true); } else if (column == 1) { // major type String newMajorType = (String) if (oldMajorType != null && oldMajorType.equals(newMajorType)) { return; } linearDefinition.getListsByNode().remove(selectedLinearNode); selectedLinearNode.setMajorType(newMajorType); linearDefinition.getListsByNode() .put(selectedLinearNode, gazetteerList); linearDefinition.getNodesByListNames() .put(selectedLinearNode.getList(), selectedLinearNode); linearDefinition.setModified(true); } else if (column == 2) { // minor type String newMinorType = (String)
} else if (linearDefinition.getSeparator() != null && linearDefinition.getSeparator().length() > 0 && value.contains(linearDefinition.getSeparator())) { newEntryButton.setEnabled(false); newEntryButton.setText("Char Forbidden: " + linearDefinition.getSeparator()); filterListButton.setEnabled(false); } else { GazetteerList gazetteerList = linearDefinition.getListsByNode().get(selectedLinearNode); boolean found = false; for (Object object : gazetteerList) {
GazetteerList theList = null; Iterator<GazetteerList> theListsIter = gazetteer.getLinearDefinition().getListsByNode().values() .iterator(); while(theListsIter.hasNext() && listName.equals("")) {
if (linearDefinition.getSeparator() != null && linearDefinition.getSeparator().length() > 0) { linearDefinition.loadLists(true); for (Object object : linearDefinition.getNodes()) { LinearNode node = (LinearNode) object; values.add(node.getList() == null ? "" : node.getList());
@Override public boolean addAll(Collection<? extends LinearNode> c) { boolean result = false; Iterator<? extends LinearNode> iter = c.iterator(); LinearNode o; while(iter.hasNext()) { o = iter.next(); result |= add(o); } // while return result; } // addAll()
public void addEmptyFeatureColumns() { // find the first row fully filled with value if (getColumnCount() == 1) { GazetteerNode node = gazetteerListFiltered.get(0); Map<String, Object> map = new HashMap<String, Object>(); // add a couple of rows map.put("", ""); node.setFeatureMap(map); } else { for (Object object : gazetteerListFiltered) { GazetteerNode node = (GazetteerNode) object; Map<String,Object> map = node.getFeatureMap(); if (map != null && (2*map.size()+1) == getColumnCount()) { map.put("", ""); break; } } } for (Object object : gazetteerList) { GazetteerNode node = (GazetteerNode) object; node.setSeparator(linearDefinition.getSeparator()); } }
try { mapsList = new HashMap[1000]; definition = new LinearDefinition(); try { definition.setURL(listsURL.toURL()); definition.load(); int i = definition.size(); listsByNode = definition.loadLists(); categoryList = new ArrayList<Lookup>(i + 1); Iterator<LinearNode> iterator = definition.iterator(); int j = 0; LinearNode linearnode;
gazetteer.getLinearDefinition().getListsByNode(); Iterator<LinearNode> iter1 = theLists.keySet().iterator(); while(iter1.hasNext()) {
@Override public boolean addAll(int index, Collection<? extends LinearNode> c) { int size = nodes.size(); Iterator<? extends LinearNode> iter = c.iterator(); LinearNode o; while(iter.hasNext()) { o = iter.next(); add(index, o); // instance of linearnode } // while boolean result = (size != nodes.size()); isModified |= result; return result; }
SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (!listTable.isShowing()) { return; } JToolTip toolTip = listTable.createToolTip(); toolTip.setTipText("No separator character allowed: [" + linearDefinition.getSeparator() + "]"); PopupFactory popupFactory = PopupFactory.getSharedInstance(); final Popup popup = popupFactory.getPopup( listTable, toolTip, point.x, point.y - 20); popup.show(); Date timeToRun = new Date(System.currentTimeMillis() + 3000); timer.schedule(new TimerTask() { @Override public void run() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { popup.hide(); // hide the tooltip after some time }}); }}, timeToRun); }}); value = ((String)value).replaceAll(
definitionTable.getSelectedRow(), definitionTable.convertColumnIndexToView(0)); selectedLinearNode = linearDefinition.getNodesByListNames().get(listName); if (selectedLinearNode != null) { listTableModel.setGazetteerList(linearDefinition.getListsByNode().get(selectedLinearNode));
@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); } }