Search in sources :

Example 1 with CheckErrorPage

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;
}
Also used : CheckErrorResult(org.wikipediacleaner.api.check.CheckErrorResult) ArrayList(java.util.ArrayList) PageAnalysis(org.wikipediacleaner.api.data.analysis.PageAnalysis) CheckErrorPage(org.wikipediacleaner.api.check.CheckErrorPage) Performance(org.wikipediacleaner.utils.Performance)

Example 2 with CheckErrorPage

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;
}
Also used : ArrayList(java.util.ArrayList) PageAnalysis(org.wikipediacleaner.api.data.analysis.PageAnalysis) CheckErrorPage(org.wikipediacleaner.api.check.CheckErrorPage)

Example 3 with CheckErrorPage

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);
            }
        }
    }
}
Also used : PageAnalysis(org.wikipediacleaner.api.data.analysis.PageAnalysis) CheckErrorPage(org.wikipediacleaner.api.check.CheckErrorPage)

Example 4 with CheckErrorPage

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;
    }
}
Also used : Configuration(org.wikipediacleaner.utils.Configuration) ArrayList(java.util.ArrayList) Page(org.wikipediacleaner.api.data.Page) CheckErrorPage(org.wikipediacleaner.api.check.CheckErrorPage) CheckErrorPage(org.wikipediacleaner.api.check.CheckErrorPage) ConfigurationValueString(org.wikipediacleaner.utils.ConfigurationValueString)

Example 5 with CheckErrorPage

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;
}
Also used : ArrayList(java.util.ArrayList) WPCConfigurationString(org.wikipediacleaner.api.configuration.WPCConfigurationString) PageElementTitle(org.wikipediacleaner.api.data.PageElementTitle) PageElementTemplate(org.wikipediacleaner.api.data.PageElementTemplate) CheckErrorResult(org.wikipediacleaner.api.check.CheckErrorResult) CheckErrorAlgorithm(org.wikipediacleaner.api.check.algorithm.CheckErrorAlgorithm) Parameter(org.wikipediacleaner.api.data.PageElementTemplate.Parameter) CheckErrorPage(org.wikipediacleaner.api.check.CheckErrorPage)

Aggregations

CheckErrorPage (org.wikipediacleaner.api.check.CheckErrorPage)26 ArrayList (java.util.ArrayList)14 CheckErrorAlgorithm (org.wikipediacleaner.api.check.algorithm.CheckErrorAlgorithm)12 PageAnalysis (org.wikipediacleaner.api.data.analysis.PageAnalysis)11 WPCConfigurationString (org.wikipediacleaner.api.configuration.WPCConfigurationString)8 CheckErrorResult (org.wikipediacleaner.api.check.CheckErrorResult)7 Page (org.wikipediacleaner.api.data.Page)7 AlgorithmError (org.wikipediacleaner.api.algorithm.AlgorithmError)6 CheckWiki (org.wikipediacleaner.api.check.CheckWiki)4 Configuration (org.wikipediacleaner.utils.Configuration)4 ConfigurationValueString (org.wikipediacleaner.utils.ConfigurationValueString)4 PageElementTemplate (org.wikipediacleaner.api.data.PageElementTemplate)3 JList (javax.swing.JList)2 API (org.wikipediacleaner.api.API)2 APIException (org.wikipediacleaner.api.APIException)2 Algorithm (org.wikipediacleaner.api.algorithm.Algorithm)2 PageElementExternalLink (org.wikipediacleaner.api.data.PageElementExternalLink)2 Parameter (org.wikipediacleaner.api.data.PageElementTemplate.Parameter)2 PageElementTitle (org.wikipediacleaner.api.data.PageElementTitle)2 ActionDeletePage (org.wikipediacleaner.gui.swing.action.ActionDeletePage)2