<commit_before>package uk.ac.ebi.ae3.indexbuilder;

import org.mindswap.pellet.owlapi.PelletReasonerFactory;
import org.semanticweb.owl.apibinding.OWLManager;
import org.semanticweb.owl.inference.OWLReasonerException;
import org.semanticweb.owl.inference.OWLReasonerFactory;
import org.semanticweb.owl.inference.OWLReasoner;
import org.semanticweb.owl.io.StreamInputSource;
import org.semanticweb.owl.model.*;

import java.util.*;
import java.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author pashky
 */
public class Efo {

    private static Efo instance = new Efo();

    public static Efo getEfo() {
        return instance;
    }

    private Map<String,EfoNode> efomap = new HashMap<String,EfoNode>();
    private SortedSet<EfoNode> roots = new TreeSet<EfoNode>(EfoNode.termAlphaComp);

    private static class EfoNode {
        private String id;
        private String term;
        private boolean branchRoot;

        private static Comparator<EfoNode> termAlphaComp = new Comparator<EfoNode>() {
            public int compare(EfoNode o1, EfoNode o2) {
                return o1.term.compareTo(o2.term);
            }
        };

        private SortedSet<EfoNode> children = new TreeSet<EfoNode>(termAlphaComp);
        private SortedSet<EfoNode> parents = new TreeSet<EfoNode>(termAlphaComp);

        private EfoNode(String id, String term, boolean branchRoot) {
            this.id = id;
            this.term = term;
            this.branchRoot = branchRoot;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            EfoNode efoNode = (EfoNode) o;

            if (id != null ? !id.equals(efoNode.id) : efoNode.id != null) return false;

            return true;
        }

        @Override
        public int hashCode() {
            int result = id != null ? id.hashCode() : 0;
            result = 31 * result + (term != null ? term.hashCode() : 0);
            result = 31 * result + (children != null ? children.hashCode() : 0);
            return result;
        }

        @Override
        public String toString() {
            return id + "(" + term + ")" + (children.isEmpty() ? "" : "+");
        }
    }

    public static class Term {
        private String id;
        private String term;
        private boolean expandable;
        private boolean branchRoot;
        private int depth;

        private Term(EfoNode node) {
            this(node, 0);
        }

        private Term(Term other, int depth) {
            this.id = other.getId();
            this.term = other.getTerm();
            this.expandable = other.isExpandable();
            this.branchRoot = other.isBranchRoot();
            this.depth = depth;
        }

        private Term(EfoNode node, int depth) {
            this.id = node.id;
            this.term = node.term;
            this.expandable = !node.children.isEmpty();
            this.branchRoot = node.branchRoot;
            this.depth = depth;
        }

        public String getId() {
            return id;
        }

        public String getTerm() {
            return term;
        }

        public boolean isExpandable() {
            return expandable;
        }

        public boolean isBranchRoot() {
            return branchRoot;
        }

        public int getDepth() {
            return depth;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Term term = (Term) o;

            if (id != null ? !id.equals(term.id) : term.id != null) return false;

            return true;
        }

        @Override
        public int hashCode() {
            return id != null ? id.hashCode() : 0;
        }

        @Override
        public String toString() {
            return id + "(" + term + ")";
        }
    }

    private static class Loader {
        final private Logger log = LoggerFactory.getLogger(getClass());
        private OWLOntologyManager manager;
        private OWLOntology ontology;
        private OWLReasoner reasoner;
        private Map<String,EfoNode> efomap;
        private Set<String> orgnodes;

        private Loader()
        {
            log.info("Loading ontology");
            manager = OWLManager.createOWLOntologyManager();
            try {
                ontology = manager.loadOntology(new StreamInputSource(getClass().getClassLoader().getResourceAsStream("META-INF/efo.owl")));
            } catch(OWLOntologyCreationException e) {
                throw new RuntimeException("Can't load EF Ontology", e);
            }

        }

        private static class ClassAnnoVisitor implements OWLAnnotationVisitor {
            private String term;
            private boolean branchRoot;
            private boolean organizational;

            public void visit(OWLConstantAnnotation annotation) {
                if (annotation.isLabel()) {
                    OWLConstant c = annotation.getAnnotationValue();
                    term = c.getLiteral();
                } else if(annotation.getAnnotationURI().toString().contains("branch_class")) {
                    branchRoot = Boolean.valueOf(annotation.getAnnotationValue().getLiteral());
                } else if(annotation.getAnnotationURI().toString().contains("organizational_class")) {
                    organizational = Boolean.valueOf(annotation.getAnnotationValue().getLiteral());
                }
            }

            public void visit(OWLObjectAnnotation annotation) {
            }

            public String getTerm() {
                return term;
            }

            public boolean isBranchRoot() {
                return branchRoot;
            }

            public boolean isOrganizational() {
                return organizational;
            }
        }


        private void load(Map<String,EfoNode> efomap) {
            try {
                this.efomap = efomap;<commit_msg>ArrayExpress_label support<commit_after>package uk.ac.ebi.ae3.indexbuilder;

import org.mindswap.pellet.owlapi.PelletReasonerFactory;
import org.semanticweb.owl.apibinding.OWLManager;
import org.semanticweb.owl.inference.OWLReasonerException;
import org.semanticweb.owl.inference.OWLReasonerFactory;
import org.semanticweb.owl.inference.OWLReasoner;
import org.semanticweb.owl.io.StreamInputSource;
import org.semanticweb.owl.model.*;

import java.util.*;
import java.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author pashky
 */
public class Efo {

    private static Efo instance = new Efo();

    public static Efo getEfo() {
        return instance;
    }

    private Map<String,EfoNode> efomap = new HashMap<String,EfoNode>();
    private SortedSet<EfoNode> roots = new TreeSet<EfoNode>(EfoNode.termAlphaComp);

    private static class EfoNode {
        private String id;
        private String term;
        private boolean branchRoot;

        private static Comparator<EfoNode> termAlphaComp = new Comparator<EfoNode>() {
            public int compare(EfoNode o1, EfoNode o2) {
                return o1.term.compareTo(o2.term);
            }
        };

        private SortedSet<EfoNode> children = new TreeSet<EfoNode>(termAlphaComp);
        private SortedSet<EfoNode> parents = new TreeSet<EfoNode>(termAlphaComp);

        private EfoNode(String id, String term, boolean branchRoot) {
            this.id = id;
            this.term = term;
            this.branchRoot = branchRoot;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            EfoNode efoNode = (EfoNode) o;

            if (id != null ? !id.equals(efoNode.id) : efoNode.id != null) return false;

            return true;
        }

        @Override
        public int hashCode() {
            int result = id != null ? id.hashCode() : 0;
            result = 31 * result + (term != null ? term.hashCode() : 0);
            result = 31 * result + (children != null ? children.hashCode() : 0);
            return result;
        }

        @Override
        public String toString() {
            return id + "(" + term + ")" + (children.isEmpty() ? "" : "+");
        }
    }

    public static class Term {
        private String id;
        private String term;
        private boolean expandable;
        private boolean branchRoot;
        private int depth;

        private Term(EfoNode node) {
            this(node, 0);
        }

        private Term(Term other, int depth) {
            this.id = other.getId();
            this.term = other.getTerm();
            this.expandable = other.isExpandable();
            this.branchRoot = other.isBranchRoot();
            this.depth = depth;
        }

        private Term(EfoNode node, int depth) {
            this.id = node.id;
            this.term = node.term;
            this.expandable = !node.children.isEmpty();
            this.branchRoot = node.branchRoot;
            this.depth = depth;
        }

        public String getId() {
            return id;
        }

        public String getTerm() {
            return term;
        }

        public boolean isExpandable() {
            return expandable;
        }

        public boolean isBranchRoot() {
            return branchRoot;
        }

        public int getDepth() {
            return depth;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Term term = (Term) o;

            if (id != null ? !id.equals(term.id) : term.id != null) return false;

            return true;
        }

        @Override
        public int hashCode() {
            return id != null ? id.hashCode() : 0;
        }

        @Override
        public String toString() {
            return id + "(" + term + ")";
        }
    }

    private static class Loader {
        final private Logger log = LoggerFactory.getLogger(getClass());
        private OWLOntologyManager manager;
        private OWLOntology ontology;
        private OWLReasoner reasoner;
        private Map<String,EfoNode> efomap;

        private Loader()
        {
            log.info("Loading ontology");
            manager = OWLManager.createOWLOntologyManager();
            try {
                ontology = manager.loadOntology(new StreamInputSource(getClass().getClassLoader().getResourceAsStream("META-INF/efo.owl")));
            } catch(OWLOntologyCreationException e) {
                throw new RuntimeException("Can't load EF Ontology", e);
            }

        }

        private static class ClassAnnoVisitor implements OWLAnnotationVisitor {
            private String term;
            private boolean branchRoot;
            private boolean organizational;

            public void visit(OWLConstantAnnotation annotation) {
                if (annotation.isLabel()) {
                    OWLConstant c = annotation.getAnnotationValue();
                    if(term == null)
                        term = c.getLiteral();
                } else if(annotation.getAnnotationURI().toString().contains("branch_class")) {
                    branchRoot = Boolean.valueOf(annotation.getAnnotationValue().getLiteral());
                } else if(annotation.getAnnotationURI().toString().contains("organizational_class")) {
                    organizational = Boolean.valueOf(annotation.getAnnotationValue().getLiteral());
                } else if(annotation.getAnnotationURI().toString().contains("ArrayExpress_label")) {
                    term = annotation.getAnnotationValue().getLiteral();
                }
            }

            public void visit(OWLObjectAnnotation annotation) {
            }

            public String getTerm() {
                return term;
            }

            public boolean isBranchRoot() {
                return branchRoot;
            }

            public boolean isOrganizational() {
                return organizational;
            }
        }


        private void load(Map<String,EfoNode> efomap) {
            try {
                this.efomap = efomap;
{'fraction_non_alphanumeric': 0.09974259974259975, 'fraction_numerical': 0.002574002574002574, 'mean_word_length': 1.8308287795992715, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '374603', 'n_tokens_mistral': 3396, 'n_tokens_neox': 3241, 'n_words': 793}