Search in sources :

Example 11 with Contact

use of edu.stanford.muse.AddressBookManager.Contact in project epadd by ePADD.

the class EmailDocument method sentOrReceived.

/**
 * returns result of checking if message was sent or received by owner.
 * @return int value with SENT_MASK and RECEIVED_MASK set appropriately. both or neither could also be set.
 */
public int sentOrReceived(AddressBook addressBook) {
    if (addressBook == null)
        return EmailDocument.SENT_MASK;
    int result = 0;
    String fromAddr = "<NONE>";
    if (from != null && from.length > 0)
        fromAddr = ((InternetAddress) from[0]).getAddress().toLowerCase();
    Contact fromC = addressBook.lookupByEmail(fromAddr);
    Contact ownCI = addressBook.getContactForSelf();
    if (fromC != null) {
        if (fromC == ownCI)
            result |= EmailDocument.SENT_MASK;
    }
    Set<Contact> toCCBCC = new LinkedHashSet<>();
    List<Address> addrs = getToCCBCC();
    for (Address addr : addrs) if (addr instanceof InternetAddress)
        toCCBCC.add(addressBook.lookupByEmail(((InternetAddress) addr).getAddress()));
    // check if all members of the group are included
    for (Contact ci : toCCBCC) if (ci == ownCI) {
        result |= EmailDocument.RECEIVED_MASK;
        break;
    }
    if (// if neither sent or received then it is received by default.
    result == 0)
        return EmailDocument.RECEIVED_MASK;
    return result;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) Contact(edu.stanford.muse.AddressBookManager.Contact)

Example 12 with Contact

use of edu.stanford.muse.AddressBookManager.Contact in project epadd by ePADD.

the class EmailDocument method setOwners.

/*
    This method combines the contacts corresponding to the passed email addresses and set the resultant contact as owner.
     */
public static void setOwners(Archive archive, Set<String> emailAddresses) {
    AddressBook ab = archive.getAddressBook();
    // get contacts for these email addresses.
    Set<Contact> ofInterest = emailAddresses.stream().map(emailAddress -> ab.lookupByEmail(emailAddress)).collect(Collectors.toSet());
    if (ofInterest.size() == 1) {
        // if single element in the set ofInterest then simply set it as owner and recompute summary
        Contact newowner = ofInterest.iterator().next();
        ab.setContactForSelf(newowner);
        ab.fillL1_SummaryObject(archive.getAllDocs());
    } else {
        // if multiple elements in the set ofInterest then
        // combine them to create a new contact.
        Contact newone = new Contact();
        // MailingList ml=null;
        ofInterest.forEach(contact -> {
            newone.merge(contact);
        // if(ml==null && ab.mailingListMap.containsKey(contact))
        // ml = ab.mailingListMap.get(contact);
        });
        // set it as ML if any of the contact is ML.-- NOT DONE
        // add contact to contactListForIds
        ab.contactListForIds.add(newone);
        // remove all these contacts (obtained from the input email addresses)
        ab.removeContacts(ofInterest);
        // set the newly create contact as owner.
        ab.setContactForSelf(newone);
    // recompute L1 summary,not needed now. Just make sure that the caller is invoking it after completion of this method.
    // just to avoid unnecessary duplication of this call.
    // ab.fillL1_SummaryObject(archive.getAllDocs());
    }
}
Also used : Address(javax.mail.Address) CalendarUtil(edu.stanford.muse.email.CalendarUtil) java.util(java.util) AddressBook(edu.stanford.muse.AddressBookManager.AddressBook) Blob(edu.stanford.muse.datacache.Blob) MailingList(edu.stanford.muse.AddressBookManager.MailingList) Util(edu.stanford.muse.util.Util) JSPHelper(edu.stanford.muse.webapp.JSPHelper) EmailFetcherThread(edu.stanford.muse.email.EmailFetcherThread) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) InternetAddress(javax.mail.internet.InternetAddress) JSONException(org.json.JSONException) Contact(edu.stanford.muse.AddressBookManager.Contact) Logger(org.apache.logging.log4j.Logger) JSONObject(org.json.JSONObject) GeneralSecurityException(java.security.GeneralSecurityException) java.io(java.io) EmailUtils(edu.stanford.muse.util.EmailUtils) LogManager(org.apache.logging.log4j.LogManager) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) AddressBook(edu.stanford.muse.AddressBookManager.AddressBook) Contact(edu.stanford.muse.AddressBookManager.Contact)

Example 13 with Contact

use of edu.stanford.muse.AddressBookManager.Contact in project epadd by ePADD.

the class EmailDocument method getParticipatingContacts.

/* get all participating addrs in this email message,
 * including to, cc, bcc, etc.
 * exclude oneself. the sole exception is the special case
 * when own addrs contains both the sender and all receivers.
 * ownaddrs can be null or empty.
 */
public Set<Contact> getParticipatingContacts(AddressBook addressBook) {
    Set<Contact> result = new LinkedHashSet<>();
    Contact self = addressBook.getContactForSelf();
    // getParticipatingAddrsExcept(addressBook.getOwnAddrs());
    List<String> rawEmailAddrs = getAllAddrs();
    for (String s : rawEmailAddrs) {
        Contact c = addressBook.lookupByEmail(s);
        if (c != null)
            result.add(c);
    }
    return result;
}
Also used : Contact(edu.stanford.muse.AddressBookManager.Contact)

Example 14 with Contact

use of edu.stanford.muse.AddressBookManager.Contact in project epadd by ePADD.

the class NameInfoMemory method toHTML.

public String toHTML(boolean withWPLink) {
    // update this to include first/last date, sentiments and count, and link to a browse page with term="..." and sentiment="..."
    String cleanTitle = cleanTitle();
    // title has to be escaped because it may have things like & embedded. e.g. saw Texas A&M university'
    String result = "<a target=\"_blank\" href=\"browse?term=%22" + Util.URLEncode(cleanTitle) + "%22\">" + cleanTitle + "<a>" + " (" + Util.pluralize(times, "time") + ")<br>";
    result += "<span style = 'color:orange'>First Date: " + firstDatetoString() + "<br>Last Date: " + lastDatetoString() + "<br><span style = 'color:green'>";
    // add burst metric here.
    result += "<span style = 'color:green'>Frequency burst metric: ";
    if (sentimentCatToCount != null) {
        for (String sentiment : sentimentCatToCount.keySet()) {
            String sentimentlink = "browse?sentiment=" + sentiment + "&term=%22" + Util.URLEncode(cleanTitle) + "%22\">" + sentiment + "<a>";
            result += "<span style = 'color:aqua'><a target=\"new\" href=\"" + sentimentlink + " = " + sentimentCatToCount.get(sentiment) + ", ";
        }
    }
    result += "<br><span style = 'color:red'>";
    try {
        if (peopleToCount != null) {
            for (Contact ct : peopleToCount.keySet()) {
                // problem is with pickBestName
                result += ct.pickBestName() + " = " + peopleToCount.get(ct) + ", ";
            }
        }
    } catch (Exception e) {
        String exceptionString = ("EXCEPTION");
        result += exceptionString;
    }
    result += "<br><span style = 'color:blue'>";
    if (withWPLink) {
        // wp needs _ instead of spaces, though spaces work also
        String wpLink = "http://en.wikipedia.org/wiki/" + cleanTitle.replaceAll(" ", "_");
        result += " <a target=\"new\" href=\"" + wpLink + "\"><img style=\"position:relative;top:3px\" src=\"images/wikipedia.png\"/></a>";
    }
    return result;
}
Also used : Contact(edu.stanford.muse.AddressBookManager.Contact)

Example 15 with Contact

use of edu.stanford.muse.AddressBookManager.Contact in project epadd by ePADD.

the class NameTypesMemory method computeInfo.

public static void computeInfo(Map<String, NameInfoMemory> nameMap, Collection<EmailDocument> allDocs, Archive archive, Lexicon lex) throws IOException {
    Indexer.QueryType qt = Indexer.QueryType.FULL;
    // assign types to all the names
    if (allDocs == null)
        allDocs = (List) archive.getAllDocs();
    // compute name -> NameInfoMemory
    Map<String, Collection<Document>> sentimentToDocs = archive.getSentimentMap(lex, true);
    for (EmailDocument ed : allDocs) {
        String id = ed.getUniqueId();
        List<String> names = archive.getNamesForDocId(id, qt);
        List<Address> mentionedAddresses = ed.getToCCBCC();
        Set<String> sentimentsForDoc = new LinkedHashSet<>();
        for (String sentiment : sentimentToDocs.keySet()) {
            if (sentimentToDocs.get(sentiment).contains(ed))
                sentimentsForDoc.add(sentiment);
        }
        for (String name : names) {
            // canonical title
            String cTitle = name.trim().toLowerCase().replaceAll(" ", "_");
            NameInfoMemory I = nameMap.get(cTitle);
            if (I == null) {
                log.info("Warning: null info for name: " + name);
                continue;
            }
            // Map sentiment to its prominence in document.
            if (I.sentimentCatToCount == null)
                I.sentimentCatToCount = new LinkedHashMap<>();
            for (String sentiment : sentimentsForDoc) {
                if (// if the sentiment isn't there.
                !I.sentimentCatToCount.containsKey(sentiment))
                    I.sentimentCatToCount.put(sentiment, 1);
                else {
                    int sum = I.sentimentCatToCount.get(sentiment);
                    sum = sum + 1;
                    I.sentimentCatToCount.put(sentiment, sum);
                }
            }
            I.sentimentCatToCount = Util.reorderMapByValue(I.sentimentCatToCount);
            // obtain list of contacts to whom email is being sent.
            for (Address adr : mentionedAddresses) {
                InternetAddress emailadr = (InternetAddress) adr;
                String address_string = emailadr.getAddress();
                Contact associatedcontact = archive.addressBook.lookupByEmail(address_string);
                if (I.peopleToCount == null)
                    I.peopleToCount = new LinkedHashMap<>();
                if (// if the contact is not yet associated.
                !I.peopleToCount.containsKey(associatedcontact))
                    I.peopleToCount.put(associatedcontact, 1);
                else {
                    int sum = I.peopleToCount.get(associatedcontact);
                    sum = sum + 1;
                    I.peopleToCount.put(associatedcontact, sum);
                }
            }
            if (I.peopleToCount != null)
                I.peopleToCount = Util.reorderMapByValue(I.peopleToCount);
            // while (I.peopleToCount.containsKey(null)){ //clean peopleToCount
            // I.peopleToCount.remove(null);
            // System.out.println ("Cleaned peopleToCount.");
            // }
            // determine start and end dates of the term.
            Date documentDate = ed.getDate();
            if (I.firstDate == null)
                I.firstDate = documentDate;
            if (I.lastDate == null)
                I.lastDate = documentDate;
            if (I.firstDate.after(documentDate)) {
                I.firstDate = documentDate;
            }
            if (I.lastDate.before(documentDate))
                I.lastDate = documentDate;
        // System.out.println("Name " + name + " FirstDate: " + (I.firstDate.toString()) + " LastDate:" + (I.lastDate.toString()));
        }
    }
// compute map of sentiment -> docs for each sentiment in goodSentiments
// for every document, get canonical name of a person who is associated with it.
// for each docs in archive, get the list of names
// for each name, update the first/last date, get the list of docs, and count how many of them are in the intersection with each sentiment
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) Contact(edu.stanford.muse.AddressBookManager.Contact)

Aggregations

Contact (edu.stanford.muse.AddressBookManager.Contact)27 AddressBook (edu.stanford.muse.AddressBookManager.AddressBook)10 InternetAddress (javax.mail.internet.InternetAddress)7 Address (javax.mail.Address)6 JSONObject (org.json.JSONObject)5 Blob (edu.stanford.muse.datacache.Blob)4 Pair (edu.stanford.muse.util.Pair)4 Util (edu.stanford.muse.util.Util)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 JSONArray (org.json.JSONArray)4 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)3 Multimap (com.google.common.collect.Multimap)3 EmailUtils (edu.stanford.muse.util.EmailUtils)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 MailingList (edu.stanford.muse.AddressBookManager.MailingList)2 AnnotationManager (edu.stanford.muse.AnnotationManager.AnnotationManager)2 Config (edu.stanford.muse.Config)2 BlobStore (edu.stanford.muse.datacache.BlobStore)2