Search in sources :

Example 1 with CorpusConfig

use of annis.service.objects.CorpusConfig in project ANNIS by korpling.

the class QueryDaoImpl method getCorpusConfigurations.

@Override
public CorpusConfigMap getCorpusConfigurations() {
    List<AnnisCorpus> annisCorpora = listCorpora();
    CorpusConfigMap cConfigs = new CorpusConfigMap();
    if (annisCorpora != null) {
        for (AnnisCorpus c : annisCorpora) {
            try {
                Properties p = getCorpusConfiguration(c.getName());
                if (p != null) {
                    CorpusConfig corpusConfig = new CorpusConfig();
                    corpusConfig.setConfig(p);
                    cConfigs.put(c.getName(), corpusConfig);
                }
            } catch (FileNotFoundException ex) {
                log.error("no corpus.properties found for {}", c.getName());
            }
        }
    }
    return cConfigs;
}
Also used : AnnisCorpus(annis.service.objects.AnnisCorpus) CorpusConfigMap(annis.service.objects.CorpusConfigMap) FileNotFoundException(java.io.FileNotFoundException) Properties(java.util.Properties) CorpusConfig(annis.service.objects.CorpusConfig)

Example 2 with CorpusConfig

use of annis.service.objects.CorpusConfig in project ANNIS by korpling.

the class SaltBasedExporter method convertSaltProject.

/**
 * Iterates over all matches (modelled as corpus graphs) and calls {@link #convertText(de.hu_berlin.german.korpling.saltnpepper.salt.saltCommon.sDocumentStructure.SDocumentGraph, java.util.List, java.util.Map, int, java.io.Writer) } for
 * the single document graph.
 * @param p
 * @param annoKeys
 * @param args
 * @param alignmc
 * @param offset
 * @param out
 */
// invokes the createAdjacencyMatrix method, if nodeCount != null or outputText otherwise
private void convertSaltProject(SaltProject p, List<String> annoKeys, Map<String, String> args, boolean alignmc, int offset, Map<String, CorpusConfig> corpusConfigs, Writer out, Integer nodeCount) throws IOException, IllegalArgumentException {
    int recordNumber = offset;
    if (p != null && p.getCorpusGraphs() != null) {
        Map<String, String> spanAnno2order = null;
        boolean virtualTokenizationFromNamespace = false;
        Set<String> corpusNames = CommonHelper.getToplevelCorpusNames(p);
        if (!corpusNames.isEmpty()) {
            CorpusConfig config = corpusConfigs.get(corpusNames.iterator().next());
            if (config != null) {
                if ("true".equalsIgnoreCase(config.getConfig("virtual_tokenization_from_namespace"))) {
                    virtualTokenizationFromNamespace = true;
                } else {
                    String mappingRaw = config.getConfig("virtual_tokenization_mapping");
                    if (mappingRaw != null) {
                        spanAnno2order = new HashMap<>();
                        for (String singleMapping : Splitter.on(',').split(mappingRaw)) {
                            List<String> mappingParts = Splitter.on('=').splitToList(singleMapping);
                            if (mappingParts.size() >= 2) {
                                spanAnno2order.put(mappingParts.get(0), mappingParts.get(1));
                            }
                        }
                    }
                }
            }
        }
        for (SCorpusGraph corpusGraph : p.getCorpusGraphs()) {
            if (corpusGraph.getDocuments() != null) {
                for (SDocument doc : corpusGraph.getDocuments()) {
                    if (virtualTokenizationFromNamespace) {
                        TimelineReconstructor.removeVirtualTokenizationUsingNamespace(doc.getDocumentGraph());
                    } else if (spanAnno2order != null) {
                        // there is a definition how to map the virtual tokenization to a real one
                        TimelineReconstructor.removeVirtualTokenization(doc.getDocumentGraph(), spanAnno2order);
                    }
                    if (nodeCount != null) {
                        createAdjacencyMatrix(doc.getDocumentGraph(), args, recordNumber++, nodeCount);
                    } else {
                        outputText(doc.getDocumentGraph(), alignmc, recordNumber++, out);
                    }
                }
            }
        }
    }
}
Also used : SDocument(org.corpus_tools.salt.common.SDocument) CorpusConfig(annis.service.objects.CorpusConfig) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph)

Example 3 with CorpusConfig

use of annis.service.objects.CorpusConfig in project ANNIS by korpling.

the class SearchOptionsPanel method mergeConfigs.

/**
 * Builds a single config for selection of one or muliple corpora.
 *
 * @param corpora Specifies the combination of corpora, for which the config
 * is calculated.
 * @param corpusConfigurations  A map containg the known corpus configurations.
 * @return A new config which takes into account the segementation of all
 * selected corpora.
 */
private CorpusConfig mergeConfigs(Set<String> corpora, CorpusConfigMap corpusConfigurations) {
    CorpusConfig corpusConfig = new CorpusConfig();
    // calculate the left and right context.
    String leftCtx = mergeConfigValue(KEY_MAX_CONTEXT_LEFT, corpora, corpusConfigurations);
    String rightCtx = mergeConfigValue(KEY_MAX_CONTEXT_RIGHT, corpora, corpusConfigurations);
    corpusConfig.setConfig(KEY_MAX_CONTEXT_LEFT, leftCtx);
    corpusConfig.setConfig(KEY_MAX_CONTEXT_RIGHT, rightCtx);
    // calculate the default-context
    corpusConfig.setConfig(KEY_CONTEXT_STEPS, mergeConfigValue(KEY_CONTEXT_STEPS, corpora, corpusConfigurations));
    corpusConfig.setConfig(KEY_DEFAULT_CONTEXT, mergeConfigValue(KEY_DEFAULT_CONTEXT, corpora, corpusConfigurations));
    // get the results per page
    corpusConfig.setConfig(KEY_RESULT_PER_PAGE, mergeConfigValue(KEY_RESULT_PER_PAGE, corpora, corpusConfigurations));
    corpusConfig.setConfig(KEY_DEFAULT_CONTEXT_SEGMENTATION, checkSegments(KEY_DEFAULT_CONTEXT_SEGMENTATION, corpora, corpusConfigurations));
    corpusConfig.setConfig(KEY_DEFAULT_BASE_TEXT_SEGMENTATION, checkSegments(KEY_DEFAULT_BASE_TEXT_SEGMENTATION, corpora, corpusConfigurations));
    return corpusConfig;
}
Also used : CorpusConfig(annis.service.objects.CorpusConfig)

Example 4 with CorpusConfig

use of annis.service.objects.CorpusConfig in project ANNIS by korpling.

the class SearchOptionsPanel method checkSegments.

/**
 * Checks, if all selected corpora have the same default segmentation layer.
 * If not the tok layer is taken, because every corpus has this one.
 *
 * @param key the key for the segementation config, must be
 * {@link #KEY_DEFAULT_BASE_TEXT_SEGMENTATION} or
 * {@link #KEY_DEFAULT_CONTEXT_SEGMENTATION}.
 * @param corpora the corpora which has to be checked.
 * @return "tok" or a segment which is defined in all corpora.
 */
private String checkSegments(String key, Set<String> corpora, CorpusConfigMap corpusConfigurations) {
    String segmentation = null;
    for (String corpus : corpora) {
        CorpusConfig c = null;
        if (corpusConfigurations.containsConfig(corpus)) {
            c = corpusConfigurations.get(corpus);
        } else {
            c = corpusConfigurations.get(DEFAULT_CONFIG);
        }
        // do nothing if not even default config is set
        if (c == null) {
            continue;
        }
        String tmpSegment = c.getConfig(key);
        /**
         * If no segment is set in the corpus config use always the tok segment.
         */
        if (tmpSegment == null) {
            return corpusConfigurations.get(DEFAULT_CONFIG).getConfig(key);
        }
        if (segmentation == null) {
            segmentation = tmpSegment;
            continue;
        }
        if (// return the default config
        !segmentation.equals(tmpSegment)) {
            return corpusConfigurations.get(DEFAULT_CONFIG).getConfig(key);
        }
    }
    if (segmentation == null) {
        return corpusConfigurations.get(DEFAULT_CONFIG).getConfig(key);
    } else {
        return segmentation;
    }
}
Also used : CorpusConfig(annis.service.objects.CorpusConfig)

Example 5 with CorpusConfig

use of annis.service.objects.CorpusConfig in project ANNIS by korpling.

the class DocBrowserController method docsAvailable.

public boolean docsAvailable(String id) {
    if (ui != null) {
        CorpusConfig corpusConfig = ui.getCorpusConfigWithCache(id);
        if (corpusConfig != null) {
            if (corpusConfig.containsKey("browse-documents")) {
                return Boolean.parseBoolean(corpusConfig.getConfig("browse-documents"));
            } else // get the default config
            {
                corpusConfig = ui.getCorpusConfigWithCache(Helper.DEFAULT_CONFIG);
                boolean browseDocuments = Boolean.parseBoolean(corpusConfig.getConfig("browse-documents", "true"));
                return browseDocuments;
            }
        }
    }
    return true;
}
Also used : CorpusConfig(annis.service.objects.CorpusConfig)

Aggregations

CorpusConfig (annis.service.objects.CorpusConfig)9 Properties (java.util.Properties)2 CountCallback (annis.gui.controller.CountCallback)1 SpecificPagingCallback (annis.gui.controller.SpecificPagingCallback)1 DisplayedResultQuery (annis.gui.objects.DisplayedResultQuery)1 ResultFetchJob (annis.gui.resultfetch.ResultFetchJob)1 SingleResultFetchJob (annis.gui.resultfetch.SingleResultFetchJob)1 ResultViewPanel (annis.gui.resultview.ResultViewPanel)1 MediaController (annis.libgui.media.MediaController)1 IFrameResourceMap (annis.libgui.visualizers.IFrameResourceMap)1 AnnisCorpus (annis.service.objects.AnnisCorpus)1 CorpusConfigMap (annis.service.objects.CorpusConfigMap)1 MatchAndDocumentCount (annis.service.objects.MatchAndDocumentCount)1 AsyncWebResource (com.sun.jersey.api.client.AsyncWebResource)1 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)1 VaadinSession (com.vaadin.server.VaadinSession)1 TabSheet (com.vaadin.ui.TabSheet)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1