Search in sources :

Example 1 with Concept

use of org.edamontology.edammap.core.edam.Concept in project edammap by edamontology.

the class Report method writeConcept.

private static void writeConcept(Writer writer, Map<EdamUri, Concept> concepts, Match match) throws IOException {
    EdamUri edamUri = match.getEdamUri();
    // TODO
    Concept concept = concepts.get(edamUri);
    writer.write("\t\t\t\t\t<div class=\"concept\">");
    if (concept.isObsolete()) {
        writer.write("<span class=\"obsolete\">");
    }
    writer.write("<strong>" + FetcherCommon.getLinkHtml(edamUri.toString(), concept.getLabel() + " (" + edamUri.getNrString() + ")") + "</strong>");
    if (match.getConceptMatch().getType() != ConceptMatchType.label && match.getConceptMatch().getType() != ConceptMatchType.none) {
        writer.write(" (" + conceptMatchString(concept, match.getConceptMatch()) + ")");
    }
    if (concept.isObsolete()) {
        writer.write("</span>");
    }
    writeParentsChildren(writer, concepts, match.getParents(), "Child of");
    writeParentsChildren(writer, concepts, match.getParentsAnnotation(), "Child of annotation");
    writeParentsChildren(writer, concepts, match.getParentsRemainingAnnotation(), "Child of excluded annotation");
    writeParentsChildren(writer, concepts, match.getChildren(), "Parent of");
    writeParentsChildren(writer, concepts, match.getChildrenAnnotation(), "Parent of annotation");
    writeParentsChildren(writer, concepts, match.getChildrenRemainingAnnotation(), "Parent of excluded annotation");
    writer.write("</div>\n");
}
Also used : Concept(org.edamontology.edammap.core.edam.Concept) EdamUri(org.edamontology.edammap.core.edam.EdamUri)

Example 2 with Concept

use of org.edamontology.edammap.core.edam.Concept in project edammap by edamontology.

the class Txt method out.

static void out(QueryType type, PrintStream ps, Map<EdamUri, Concept> concepts, List<Query> queries, List<MappingTest> mappings) throws IOException {
    ps.print("query_id");
    ps.print(SEP);
    ps.print("query_name");
    ps.print(SEP);
    ps.print("edam_branch");
    ps.print(SEP);
    ps.print("edam_uri");
    ps.print(SEP);
    ps.print("edam_label");
    ps.print(SEP);
    ps.print("edam_obsolete");
    ps.print(SEP);
    ps.print("best_one_query");
    ps.print(SEP);
    ps.print("best_one_edam");
    ps.print(SEP);
    ps.print("best_one_score");
    ps.print(SEP);
    ps.print("without_path_score");
    ps.print(SEP);
    ps.print("score");
    ps.print(SEP);
    ps.print("test");
    ps.println();
    for (int i = 0; i < queries.size(); ++i) {
        Query query = queries.get(i);
        MappingTest mapping = mappings.get(i);
        for (Branch branch : Branch.values()) {
            for (MatchTest matchTest : mapping.getMatches(branch)) {
                Match match = matchTest.getMatch();
                Concept concept = concepts.get(match.getEdamUri());
                ps.print(query.getId() != null ? query.getId() : "");
                ps.print(SEP);
                ps.print(query.getName() != null ? query.getName() : "");
                ps.print(SEP);
                ps.print(branch);
                ps.print(SEP);
                ps.print(match.getEdamUri());
                ps.print(SEP);
                ps.print(concept.getLabel());
                ps.print(SEP);
                ps.print(concept.isObsolete());
                ps.print(SEP);
                ps.print(match.getQueryMatch().getType().name());
                ps.print(SEP);
                ps.print(match.getConceptMatch().getType().name());
                ps.print(SEP);
                ps.print(match.getBestOneScore() > -1 ? match.getBestOneScore() : "");
                ps.print(SEP);
                ps.print(match.getWithoutPathScore() > -1 ? match.getWithoutPathScore() : "");
                ps.print(SEP);
                ps.print(match.getScore());
                ps.print(SEP);
                ps.print(matchTest.getTest().name());
                ps.println();
            }
        }
    }
}
Also used : Concept(org.edamontology.edammap.core.edam.Concept) Query(org.edamontology.edammap.core.query.Query) Branch(org.edamontology.edammap.core.edam.Branch) MappingTest(org.edamontology.edammap.core.benchmarking.MappingTest) MatchTest(org.edamontology.edammap.core.benchmarking.MatchTest) Match(org.edamontology.edammap.core.mapping.Match)

Example 3 with Concept

use of org.edamontology.edammap.core.edam.Concept in project edammap by edamontology.

the class Cli method run.

private static void run(Version version) throws IOException, ParseException {
    List<Param> paramsMain = new ArrayList<>();
    paramsMain.add(new Param("Ontology file", CliArgs.EDAM, new File(args.getEdam()).getName(), "https://github.com/edamontology/edamontology/tree/master/releases"));
    if (Input.isProtocol(args.getQuery())) {
        paramsMain.add(new Param("Query file", CliArgs.QUERY, args.getQuery(), args.getQuery()));
    } else {
        paramsMain.add(new Param("Query file", CliArgs.QUERY, new File(args.getQuery()).getName()));
    }
    paramsMain.add(new Param("Type", CliArgs.TYPE, args.getType().toString()));
    paramsMain.add(new Param("Output file", CliArgs.OUTPUT, new File(args.getOutput()).getName()));
    paramsMain.add(new Param("Report file", CliArgs.REPORT, new File(args.getReport()).getName()));
    paramsMain.add(new Param("Report page size", CliArgs.REPORT_PAGE_SIZE, args.getReportPageSize(), 0.0, null));
    paramsMain.add(new Param("Report pagination size", CliArgs.REPORT_PAGINATION_SIZE, args.getReportPaginationSize(), 0.0, null));
    paramsMain.add(new Param("Number of threads", CliArgs.THREADS, args.getThreads(), 0.0, null));
    Output output = new Output(args.getOutput(), args.getReport(), false);
    stopwords = PreProcessor.getStopwords(args.getPreProcessorArgs().getStopwords());
    processor = new Processor(args.getProcessorArgs());
    idf = null;
    if (args.getPreProcessorArgs().isStemming()) {
        if (args.getProcessorArgs().getIdfStemmed() != null && !args.getProcessorArgs().getIdfStemmed().isEmpty()) {
            idf = new Idf(args.getProcessorArgs().getIdfStemmed());
        }
    } else {
        if (args.getProcessorArgs().getIdf() != null && !args.getProcessorArgs().getIdf().isEmpty()) {
            idf = new Idf(args.getProcessorArgs().getIdf());
        }
    }
    logger.info("Loading concepts");
    Map<EdamUri, Concept> concepts = Edam.load(args.getEdam());
    logger.info("Processing {} concepts", concepts.size());
    processedConcepts = processor.getProcessedConcepts(concepts, args.getMapperArgs().getIdfArgs(), args.getMapperArgs().getMultiplierArgs(), new PreProcessor(args.getPreProcessorArgs(), stopwords));
    logger.info("Loading queries");
    queries = QueryLoader.get(args.getQuery(), args.getType(), concepts, args.getFetcherArgs().getTimeout(), args.getFetcherArgs().getPrivateArgs().getUserAgent());
    publications = new ArrayList<>(queries.size());
    webpages = new ArrayList<>(queries.size());
    docs = new ArrayList<>(queries.size());
    mappings = new ArrayList<>(queries.size());
    for (int i = 0; i < queries.size(); ++i) {
        publications.add(null);
        webpages.add(null);
        docs.add(null);
        mappings.add(null);
    }
    start = System.currentTimeMillis();
    logger.info("Start: {}", Instant.ofEpochMilli(start));
    logger.info("Starting mapper threads");
    for (int i = 0; i < args.getThreads(); ++i) {
        Thread t = new Thread(new Cli());
        t.setDaemon(true);
        t.start();
    }
    synchronized (lock) {
        while (!lockDone || numThreads > 0) {
            try {
                lock.wait();
            } catch (InterruptedException e) {
                // TODO exit threads cleanly? give timeout for threads to exit? close db? print that exiting and waiting for threads to terminate?
                logger.error("Exception!", e);
                System.exit(1);
            }
        }
    }
    logger.info("All mapper threads stopped");
    long stop = System.currentTimeMillis();
    logger.info("Stop: {}", Instant.ofEpochMilli(stop));
    logger.info("Mapping took {}s", (stop - start) / 1000.0);
    Results results = Benchmark.calculate(queries, mappings);
    logger.info("Outputting results");
    output.output(args, paramsMain, args.getType(), args.getReportPageSize(), args.getReportPaginationSize(), concepts, queries, webpages, docs, publications, results, start, stop, version);
    logger.info("{} : {}", results.toStringMeasure(Measure.recall), Measure.recall);
    logger.info("{} : {}", results.toStringMeasure(Measure.AveP), Measure.AveP);
}
Also used : Concept(org.edamontology.edammap.core.edam.Concept) PreProcessor(org.edamontology.edammap.core.preprocessing.PreProcessor) Processor(org.edamontology.edammap.core.processing.Processor) ArrayList(java.util.ArrayList) PreProcessor(org.edamontology.edammap.core.preprocessing.PreProcessor) Idf(org.edamontology.edammap.core.idf.Idf) Results(org.edamontology.edammap.core.benchmarking.Results) Output(org.edamontology.edammap.core.output.Output) Param(org.edamontology.edammap.core.output.Param) File(java.io.File) EdamUri(org.edamontology.edammap.core.edam.EdamUri)

Example 4 with Concept

use of org.edamontology.edammap.core.edam.Concept in project edammap by edamontology.

the class Processor method getProcessedConcepts.

public Map<EdamUri, ConceptProcessed> getProcessedConcepts(Map<EdamUri, Concept> concepts, IdfArgs idfArgs, MultiplierArgs multiplierArgs, PreProcessor preProcessor) {
    Map<EdamUri, ConceptProcessed> processedConcepts = new LinkedHashMap<>();
    IdfMake idfMake = new IdfMake();
    for (Map.Entry<EdamUri, Concept> concept : concepts.entrySet()) {
        processedConcepts.put(concept.getKey(), processConcept(concept.getValue(), idfMake, preProcessor));
    }
    Idf idf = new Idf(idfMake.getIdf());
    for (ConceptProcessed processedConcept : processedConcepts.values()) {
        processConceptIdf(processedConcept, idf);
    }
    for (ConceptProcessed processedConcept : processedConcepts.values()) {
        anonymizeProcessedConcept(processedConcept, idfArgs, multiplierArgs);
    }
    return processedConcepts;
}
Also used : Concept(org.edamontology.edammap.core.edam.Concept) IdfMake(org.edamontology.edammap.core.idf.IdfMake) Idf(org.edamontology.edammap.core.idf.Idf) EdamUri(org.edamontology.edammap.core.edam.EdamUri) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with Concept

use of org.edamontology.edammap.core.edam.Concept in project edammap by edamontology.

the class QueryLoader method edamUriJson.

private static EdamUri edamUriJson(Edam edam, Map<EdamUri, Concept> concepts) {
    if (edam.getUri() != null && !edam.getUri().trim().isEmpty()) {
        EdamUri edamUri = new EdamUri(edam.getUri().trim().toLowerCase(Locale.ROOT), EDAM_PREFIX);
        if (!checkEdamUri(edamUri, concepts))
            return null;
        return edamUri;
    }
    if (edam.getTerm() != null && !edam.getTerm().trim().isEmpty()) {
        String term = edam.getTerm().trim();
        if (concepts != null) {
            for (Entry<EdamUri, Concept> e : concepts.entrySet()) {
                if (e.getValue().getLabel().equals(term))
                    return e.getKey();
            }
            for (Entry<EdamUri, Concept> e : concepts.entrySet()) {
                if (e.getValue().getExactSynonyms().contains(term))
                    return e.getKey();
            }
            for (Entry<EdamUri, Concept> e : concepts.entrySet()) {
                if (e.getValue().getNarrowSynonyms().contains(term))
                    return e.getKey();
                if (e.getValue().getBroadSynonyms().contains(term))
                    return e.getKey();
            }
        }
        logger.warn("Can't find EDAM URI for term {} in JSON", term);
        return null;
    } else {
        logger.warn("An EDAM object is empty in JSON");
        return null;
    }
}
Also used : Concept(org.edamontology.edammap.core.edam.Concept) EdamUri(org.edamontology.edammap.core.edam.EdamUri)

Aggregations

Concept (org.edamontology.edammap.core.edam.Concept)6 EdamUri (org.edamontology.edammap.core.edam.EdamUri)4 MatchTest (org.edamontology.edammap.core.benchmarking.MatchTest)2 Branch (org.edamontology.edammap.core.edam.Branch)2 Idf (org.edamontology.edammap.core.idf.Idf)2 Match (org.edamontology.edammap.core.mapping.Match)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 MappingTest (org.edamontology.edammap.core.benchmarking.MappingTest)1 Results (org.edamontology.edammap.core.benchmarking.Results)1 IdfMake (org.edamontology.edammap.core.idf.IdfMake)1 ConceptMatch (org.edamontology.edammap.core.mapping.ConceptMatch)1 ConceptMatchType (org.edamontology.edammap.core.mapping.ConceptMatchType)1 MatchAverageStats (org.edamontology.edammap.core.mapping.MatchAverageStats)1 QueryMatch (org.edamontology.edammap.core.mapping.QueryMatch)1 Output (org.edamontology.edammap.core.output.Output)1 Param (org.edamontology.edammap.core.output.Param)1 PreProcessor (org.edamontology.edammap.core.preprocessing.PreProcessor)1