public void repair(Project aProject, CAS aCas) { List<LogMessage> messages = new ArrayList<>(); repair(aProject, aCas, messages); if (log.isWarnEnabled() && !messages.isEmpty()) { messages.forEach(s -> log.warn("{}", s)); } }
public boolean analyze(Project aProject, CAS aCas) throws CasDoctorException { List<LogMessage> messages = new ArrayList<>(); boolean result = analyze(aProject, aCas, messages); if (log.isDebugEnabled()) { messages.forEach(s -> log.debug("{}", s)); } return result; }
if (casDoctor.isRepairsActive()) { try { casDoctor.repair(aProject, aCas); casDoctor.analyze(aProject, aCas); .append(") in project[") .append(aProject.getName()).append("] (").append(aProject.getId()).append(")\n"); e.getDetails().forEach(m -> detailMsg.append( String.format("- [%s] %s%n", m.level, m.message)));
casDoctor.analyze(aProject, aJcas.getCas()); .append(aProject.getName()).append("] (").append(aProject.getId()) .append(")\n"); e.getDetails().forEach(m -> detailMsg.append(String.format("- [%s] %s%n", m.level, m.message)));
ok &= check.check(aProject, aCas, aMessages); log.debug("CasDoctor analysis [" + checkClass.getSimpleName() + "] completed in " + (System.currentTimeMillis() - tStartTask) + "ms"); throw new CasDoctorException(aMessages);
public static Set<FeatureStructure> getNonIndexedFSes(CAS aCas) { TypeSystem ts = aCas.getTypeSystem(); Set<FeatureStructure> allIndexedFS = collectIndexed(aCas); Set<FeatureStructure> allReachableFS = collectReachable(aCas); // Remove all that are indexed allReachableFS.removeAll(allIndexedFS); // Remove all that are not annotations allReachableFS.removeIf(fs -> !ts.subsumes(aCas.getAnnotationType(), fs.getType())); // All that is left are non-index annotations return allReachableFS; }
public static Map<FeatureStructure, FeatureStructure> getNonIndexedFSesWithOwner(CAS aCas) { TypeSystem ts = aCas.getTypeSystem(); LowLevelCAS llcas = aCas.getLowLevelCAS(); Set<FeatureStructure> allIndexedFS = collectIndexed(aCas); Map<FeatureStructure, FeatureStructure> allReachableFS = new TreeMap<>( Comparator.comparingInt(llcas::ll_getFSRef)); FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS( aCas.getTypeSystem().getTopType()); i.forEachRemaining(fs -> collect(allReachableFS, allIndexedFS, fs, fs)); // Remove all that are not annotations allReachableFS.entrySet().removeIf(e -> !ts.subsumes(aCas.getAnnotationType(), e.getKey().getType())); // Remove all that are indexed allReachableFS.entrySet().removeIf(e -> e.getKey() == e.getValue()); // All that is left are non-index annotations return allReachableFS; } }
public static void collect(Set<FeatureStructure> aFSes, FeatureStructure aFS) { if (aFS != null && !aFSes.contains(aFS)) { aFSes.add(aFS); for (Feature f : aFS.getType().getFeatures()) { if (!f.getRange().isPrimitive() && !CAS.FEATURE_BASE_NAME_SOFA.equals(f.getShortName())) { collect(aFSes, aFS.getFeatureValue(f)); } } } }
public ProjectCasDoctorPanel(String id, IModel<Project> aProjectModel) { super(id, aProjectModel); setOutputMarkupId(true); Form<FormModel> form = new Form<>("casDoctorForm", PropertyModel.of(this, "formModel")); add(form); CheckBoxMultipleChoice<Class<? extends Repair>> repairs = new CheckBoxMultipleChoice<>( "repairs"); repairs.setModel(PropertyModel.of(this, "formModel.repairs")); repairs.setChoices(CasDoctor.scanRepairs()); repairs.setChoiceRenderer(new ChoiceRenderer<>("simpleName")); repairs.setPrefix("<div class=\"checkbox\">"); repairs.setSuffix("</div>"); repairs.setLabelPosition(LabelPosition.WRAP_AFTER); form.add(repairs); form.add(new LambdaAjaxButton<FormModel>("check", this::actionCheck)); form.add(new LambdaAjaxButton<FormModel>("repair", this::actionRepair)); add(createMessageSetsView()); }
@Override public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) { Map<FeatureStructure, FeatureStructure> nonIndexed = getNonIndexedFSesWithOwner(aCas); if (!nonIndexed.isEmpty()) { aMessages.add(new LogMessage(this, LogLevel.ERROR, "Unindexed feature structures: %d", nonIndexed.size())); for (Entry<FeatureStructure, FeatureStructure> e : nonIndexed.entrySet()) { aMessages.add(new LogMessage(this, LogLevel.ERROR, "Non-indexed feature structure [%s] reachable through [%s]", e.getKey(), e.getValue())); } } // else { // aMessages.add(String.format("[%s] OK", getClass().getSimpleName())); // } return nonIndexed.isEmpty(); } }
@Override public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) Set<FeatureStructure> nonIndexed = getNonIndexedFSes(aCas);
if (casDoctor.isRepairsActive()) { try { casDoctor.repair(aProject, aCas); casDoctor.analyze(aProject, aCas); .append(") in project[") .append(aProject.getName()).append("] (").append(aProject.getId()).append(")\n"); e.getDetails().forEach(m -> detailMsg.append( String.format("- [%s] %s%n", m.level, m.message)));
casDoctor.analyze(aDocument.getProject(), aJcas.getCas()); .append(aDocument.getProject().getName()).append("] (") .append(aDocument.getProject().getId()).append(")\n"); e.getDetails().forEach(m -> detailMsg.append(String.format("- [%s] %s%n", m.level, m.message)));
/** * Recursively collect referenced FSes and also record for each the last indexed FS that refers * the them. */ public static void collect(Map<FeatureStructure, FeatureStructure> aFSes, Set<FeatureStructure> aIndexed, FeatureStructure aFS, FeatureStructure aLastIndexed) { if (aFS != null && !aFSes.containsKey(aFS)) { // We might find an annotation indirectly. In that case make sure we consider it as // an indexed annotation instead of wrongly recording it as non-indexed if (aIndexed.contains(aFS)) { aFSes.put(aFS, aFS); } else { aFSes.put(aFS, aLastIndexed); } for (Feature f : aFS.getType().getFeatures()) { if (!f.getRange().isPrimitive() && !CAS.FEATURE_BASE_NAME_SOFA.equals(f.getShortName())) { collect(aFSes, aIndexed, aFS.getFeatureValue(f), aIndexed.contains(aFS) ? aFS : aLastIndexed); } } } }
public ProjectCasDoctorPanel(String id, IModel<Project> aProjectModel) { super(id, aProjectModel); setOutputMarkupId(true); Form<FormModel> form = new Form<>("casDoctorForm", PropertyModel.of(this, "formModel")); add(form); CheckBoxMultipleChoice<Class<? extends Repair>> repairs = new CheckBoxMultipleChoice<>( "repairs"); repairs.setModel(PropertyModel.of(this, "formModel.repairs")); repairs.setChoices(CasDoctor.scanRepairs()); repairs.setChoiceRenderer(new ChoiceRenderer<>("simpleName")); repairs.setPrefix("<div class=\"checkbox\">"); repairs.setSuffix("</div>"); repairs.setLabelPosition(LabelPosition.WRAP_AFTER); form.add(repairs); form.add(new LambdaAjaxButton<FormModel>("check", this::actionCheck)); form.add(new LambdaAjaxButton<FormModel>("repair", this::actionRepair)); add(createMessageSetsView()); }
if (casDoctor.isRepairsActive()) { try { casDoctor.repair(aProject, aCas); casDoctor.analyze(aProject, aCas); .append(") in project[") .append(aProject.getName()).append("] (").append(aProject.getId()).append(")\n"); e.getDetails().forEach(m -> detailMsg.append( String.format("- [%s] %s%n", m.level, m.message)));
casDoctor.analyze(aDocument.getProject(), aJcas.getCas()); .append(aDocument.getProject().getName()).append("] (") .append(aDocument.getProject().getId()).append(")\n"); e.getDetails().forEach(m -> detailMsg.append(String.format("- [%s] %s%n", m.level, m.message)));
public static Set<FeatureStructure> collectReachable(CAS aCas) { LowLevelCAS llcas = aCas.getLowLevelCAS(); Set<FeatureStructure> fses = new TreeSet<>(Comparator.comparingInt(llcas::ll_getFSRef)); FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS( aCas.getTypeSystem().getTopType()); i.forEachRemaining(fs -> collect(fses, fs)); return fses; }