use of org.wikipediacleaner.api.check.CheckErrorPage in project wpcleaner by WPCleaner.
the class AlgorithmError method analyzeError.
/**
* Analyze a page to find errors of a given type.
*
* @param algorithm Algorithm.
* @param pageAnalysis Page analysis.
* @return Error page.
*/
public static CheckErrorPage analyzeError(CheckErrorAlgorithm algorithm, PageAnalysis pageAnalysis) {
if ((algorithm == null) || (pageAnalysis == null)) {
return null;
}
Performance perf = null;
if (traceTime) {
perf = Performance.getInstance("CheckError.analyzeError");
}
CheckErrorPage errorPage = new CheckErrorPage(pageAnalysis.getPage(), algorithm);
boolean errorFound = false;
List<CheckErrorResult> errorsFound = new ArrayList<>();
int errorNumber = algorithm.getErrorNumber();
PageAnalysis.Result result = pageAnalysis.getCheckWikiErrors(errorNumber);
if (result != null) {
errorFound = result.getErrors(errorsFound);
} else {
errorFound = algorithm.analyze(pageAnalysis, errorsFound, false);
pageAnalysis.setCheckWikiErrors(errorNumber, errorFound, errorsFound);
}
errorPage.setResults(errorFound, errorsFound);
if (perf != null) {
perf.printStep("Error n°" + algorithm.getErrorNumber());
perf.release();
}
return errorPage;
}
use of org.wikipediacleaner.api.check.CheckErrorPage in project wpcleaner by WPCleaner.
the class AlgorithmError method computeErrorsFixed.
/**
* @param initialErrors List of initial errors.
* @param contents Current contents.
* @param shouldCheckSpelling True if spelling should be checked.
* @return Information about errors fixed.
*/
public static List<Progress> computeErrorsFixed(List<CheckErrorPage> initialErrors, String contents, boolean shouldCheckSpelling) {
final List<Progress> errorsFixed = new ArrayList<>();
PageAnalysis analysis = null;
if (initialErrors != null) {
for (CheckErrorPage initialError : initialErrors) {
if (analysis == null) {
analysis = initialError.getPage().getAnalysis(contents, true);
analysis.shouldCheckSpelling(shouldCheckSpelling);
}
CheckErrorPage errorPage = analyzeError(initialError.getAlgorithm(), analysis);
if ((errorPage.getErrorFound() == false) || (errorPage.getActiveResultsCount() < initialError.getActiveResultsCount())) {
errorsFixed.add(new Progress(initialError.getAlgorithm(), errorPage.getErrorFound() == false));
}
}
}
return errorsFixed;
}
use of org.wikipediacleaner.api.check.CheckErrorPage in project wpcleaner by WPCleaner.
the class OnePageWindow method initializeInitialErrors.
/**
* Initialize list of initial errors.
*
* @param algorithms Algorithms.
*/
protected void initializeInitialErrors(Collection<CheckErrorAlgorithm> algorithms) {
if (page != null) {
PageAnalysis pageAnalysis = page.getAnalysis(page.getContents(), false);
pageAnalysis.shouldCheckSpelling(shouldCheckSpelling());
List<CheckErrorPage> errorsFound = AlgorithmError.analyzeErrors(algorithms, pageAnalysis, false);
initialErrors = new ArrayList<>();
if (errorsFound != null) {
for (CheckErrorPage tmpError : errorsFound) {
initialErrors.add(tmpError);
}
}
}
}
use of org.wikipediacleaner.api.check.CheckErrorPage in project wpcleaner by WPCleaner.
the class ActionFullAnalysis method actionPerformed.
/**
* Analyze a page.
*
* @param e Event triggering this call.
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent e) {
if ((e == null) || (wiki == null)) {
return;
}
// Analyze a list of selected pages
if (list != null) {
List<? extends Object> selection = list.getSelectedValuesList();
List<Page> pages = new ArrayList<>();
if (selection != null) {
for (Object object : selection) {
if (object instanceof Page) {
pages.add((Page) object);
} else if (object instanceof CheckErrorPage) {
pages.add(((CheckErrorPage) object).getPage());
}
}
}
Controller.runFullAnalysis(parent, pages, knownPages, wiki);
return;
}
// Analyze a single page
if ((text != null) || (combo != null)) {
String tmp = null;
if (text != null) {
tmp = text.getText();
} else {
Object select = combo.getSelectedItem();
if (select != null) {
tmp = select.toString();
}
}
if ((tmp == null) || (tmp.trim().length() == 0)) {
Utilities.displayWarning(parent, GT._T("You must input a page name for running a full analysis"), (text != null) ? text : combo);
return;
}
tmp = tmp.trim();
Configuration config = Configuration.getConfiguration();
config.setString(null, ConfigurationValueString.PAGE_NAME, tmp);
config.save();
Controller.runFullAnalysis(tmp, null, wiki);
return;
}
// Analyze a single page
if (title != null) {
Controller.runFullAnalysis(title, null, wiki);
return;
}
}
use of org.wikipediacleaner.api.check.CheckErrorPage in project wpcleaner by WPCleaner.
the class UpdateDuplicateArgsWarningTools method constructWarningElements.
/**
* Extract information about duplicate arguments.
*
* @param analysis Page analysis (must have enough information to compute the list of duplicate arguments).
* @param talkPage Talk page.
* @param todoSubpage to do sub-page.
* @return List of duplicate arguments errors.
*/
@Override
protected Collection<String> constructWarningElements(PageAnalysis analysis, Page talkPage, Page todoSubpage) {
if ((analysis == null) || (analysis.getPage() == null)) {
return null;
}
// Prepare list of algorithms
List<CheckErrorAlgorithm> algorithms = new ArrayList<>();
// Duplicate template args
algorithms.add(CheckErrorAlgorithms.getAlgorithm(wiki, 524));
// Retrieve list of errors
List<CheckErrorResult> errorResults = new ArrayList<>();
for (CheckErrorAlgorithm algorithm : algorithms) {
int errorNumber = algorithm.getErrorNumber();
if (CheckErrorAlgorithms.isAlgorithmActive(wiki, errorNumber)) {
CheckErrorPage errorPage = AlgorithmError.analyzeError(algorithm, analysis);
List<CheckErrorResult> results = errorPage.getResults();
if (results != null) {
errorResults.addAll(results);
}
}
}
Collections.sort(errorResults);
// Compute list of elements for the warning
List<String> elements = new ArrayList<>();
String contents = analysis.getContents();
for (CheckErrorResult errorResult : errorResults) {
if (ErrorLevel.ERROR.equals(errorResult.getErrorLevel())) {
int beginIndex = errorResult.getStartPosition();
while ((beginIndex < contents.length()) && (contents.charAt(beginIndex) != '|') && (contents.charAt(beginIndex) != '}')) {
beginIndex++;
}
if ((beginIndex < contents.length()) && (contents.charAt(beginIndex) == '|')) {
beginIndex++;
}
String templateName = null;
String argumentName = null;
String chapterName = "";
boolean keep = false;
PageElementTemplate template = analysis.isInTemplate(beginIndex);
if (template != null) {
templateName = template.getTemplateName();
Parameter param = template.getParameterAtIndex(beginIndex);
if (param != null) {
argumentName = param.getComputedName();
PageElementTitle title = PageAnalysisUtils.getCurrentChapter(analysis, beginIndex);
if (title != null) {
chapterName = title.getTitle();
}
keep = true;
}
}
if (keep) {
elements.add(templateName);
elements.add(argumentName);
elements.add(chapterName);
}
}
}
return elements;
}
Aggregations