@@ -0,0 +1,3177 @@
+package pfr.plugins.refiners.maillinking;%0A%0Aimport java.util.*;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Aimport org.neo4j.graphdb.*;%0A%0Aimport pfr.PFR;%0Aimport pfr.annotations.PropertyDeclaration;%0Aimport pfr.annotations.RelationDeclaration;%0Aimport pfr.plugins.parsers.issuetracker.PfrPluginForIssueTracker;%0Aimport pfr.plugins.parsers.mail.PfrPluginForMailList;%0A%0A/**%0A * Created by laurence on 16-11-27.%0A */%0Apublic class MailToIssueLinker implements PFR%7B%0A    @RelationDeclaration%0A    public static final String MAIL_TO_ISSUE = %22mailToIssue%22;%0A%0A    GraphDatabaseService db = null;%0A    HashMap%3CString, Node%3E mailMap = new HashMap%3C%3E();%0A    HashMap%3CString, Node%3E nameToIssueMap = new HashMap%3C%3E();%0A    HashMap%3CNode, ArrayList%3CNode%3E%3E mailToIssueMap = new HashMap%3C%3E();%0A    @Override%0A    public void run(GraphDatabaseService graphDB) %7B%0A        this.db = graphDB;%0A        getMailAndIssueMap();%0A        extractIssueLink();%0A    %7D%0A    public void extractIssueLink() %7B%0A        for (String content : mailMap.keySet()) %7B%0A            String patternForLucene = %22https?://issues%5C%5C.apache%5C%5C.org(.*?)/(LUCENE-(%5C%5Cd+))%22;%0A            Pattern regex = Pattern.compile(patternForLucene);%0A            Matcher idMatcher = regex.matcher(content);%0A            HashSet%3CString%3E issueNameSet = new HashSet%3C%3E();%0A            while (idMatcher.find()) %7B%0A                String issueName = idMatcher.group(2);%0A                issueNameSet.add(issueName);%0A            %7D%0A            ArrayList%3CNode%3E issueList = new ArrayList%3C%3E();%0A            for (String name : issueNameSet) %7B%0A                Node node = nameToIssueMap.get(name);%0A                if (node != null) %7B%0A                    issueList.add(node);%0A                    //System.out.println(%22found in issue map%22);%0A                %7D%0A            %7D%0A            mailToIssueMap.put(mailMap.get(content), issueList);%0A        %7D%0A        try (Transaction tx = db.beginTx())%7B%0A            for (Node mailNode : mailToIssueMap.keySet())%7B%0A                for (Node issueNode:mailToIssueMap.get(mailNode))%7B%0A                    mailNode.createRelationshipTo(issueNode, RelationshipType.withName(MAIL_TO_ISSUE));%0A                %7D%0A            %7D%0A            tx.success();%0A        %7D%0A    %7D%0A%0A    public void getMailAndIssueMap() %7B%0A        try (Transaction tx = db.beginTx())%7B%0A            ResourceIterator%3CNode%3E nodes = db.getAllNodes().iterator();%0A            while (nodes.hasNext())%7B%0A                Node node = nodes.next();%0A                if (!node.getLabels().iterator().hasNext())%0A                    continue;%0A                if (node.hasLabel(Label.label(PfrPluginForMailList.MAIL)))%7B%0A                    String content = (String)node.getProperty(PfrPluginForMailList.MAIL_BODY);%0A                    mailMap.put(content, node);%0A                %7D%0A                else if (node.hasLabel(Label.label(PfrPluginForIssueTracker.ISSUE))) %7B%0A                    String name = (String)node.getProperty(PfrPluginForIssueTracker.ISSUE_NAME);%0A                    nameToIssueMap.put(name, node);%0A                    //System.out.println(node.getProperty(PfrPluginForIssueTracker.ISSUE_NAME));%0A                %7D%0A            %7D%0A            tx.success();%0A        %7D%0A    %7D%0A%7D%0A

add MailToIssueLinker