// Path: src/main/java/com/diskoverorta/vo/DocumentObject.java
// public class DocumentObject
// {
//     String docText = null;
//     public EntityObject entities = null;
//     public EntityMap entitiesMeta = null;
// 
//     public DocumentObject()
//     {
//         entities = new EntityObject();
//         entitiesMeta = new EntityMap();
//     }
// }
// 
// Path: src/main/java/com/diskoverorta/vo/EntityAPISet.java
// public class EntityAPISet
// {
//     public Set<String> Currency = null;
//     public Set<String> Date = null;
//     public Set<String> Location = null;
//     public Set<String> Organization = null;
//     public Set<String> Percent = null;
//     public Set<String> Person = null;
//     public Set<String> Time = null;
// 
//     public EntityAPISet()
//     {
// 
//     }
// }


import com.diskoverorta.vo.DocumentObject;
import com.diskoverorta.vo.EntityAPISet;
import com.diskoverorta.vo.EntityMap;
import com.diskoverorta.vo.EntityObject;
import java.util.*;
/*******************************************************************************
 *   Copyright 2015 Serendio Inc. ( http://www.serendio.com/ )
 *   Author - Praveen Jesudhas
 *    
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *******************************************************************************/
package com.diskoverorta.utils;



/**
 * Created by praveen on 25/11/14.
 */
public class EntityUtils
{
    public static EntityMap extractEntityMap(EntityObject eObj)
    {
        EntityMap eMap = new EntityMap();
        eMap.personCount = getListFrequency(eObj.person);
        eMap.organizationCount = getListFrequency(eObj.organization);
        eMap.locationCount = getListFrequency(eObj.location);
        eMap.personAlias = getAliasMap(eMap.personCount);
        eMap.organizationAlias = getAliasMap(eMap.organizationCount);
        eMap.locationAlias = getAliasMap(eMap.locationCount);

        return eMap;
    }
    public static Map<String,Integer> getListFrequency(List<String> elist)
    {
        Map<String,Integer> tempMap = new TreeMap<String,Integer>();
        for(int i = 0 ; i < elist.size() ; i++)
        {
            String temp  = elist.get(i).toLowerCase().trim();

            if(tempMap.containsKey(temp))
            {
                Integer val = tempMap.get(temp);
                tempMap.put(temp,val+1);
            }
            else
                tempMap.put(temp,1);
        }
        return tempMap;
    }
// Path: src/main/java/com/diskoverorta/vo/DocumentObject.java
// public class DocumentObject
// {
//     String docText = null;
//     public EntityObject entities = null;
//     public EntityMap entitiesMeta = null;
// 
//     public DocumentObject()
//     {
//         entities = new EntityObject();
//         entitiesMeta = new EntityMap();
//     }
// }
// 
// Path: src/main/java/com/diskoverorta/vo/EntityAPISet.java
// public class EntityAPISet
// {
//     public Set<String> Currency = null;
//     public Set<String> Date = null;
//     public Set<String> Location = null;
//     public Set<String> Organization = null;
//     public Set<String> Percent = null;
//     public Set<String> Person = null;
//     public Set<String> Time = null;
// 
//     public EntityAPISet()
//     {
// 
//     }
// }


// Path: src/main/java/com/diskoverorta/utils/EntityUtils.java
import com.diskoverorta.vo.DocumentObject;
import com.diskoverorta.vo.EntityAPISet;
import com.diskoverorta.vo.EntityMap;
import com.diskoverorta.vo.EntityObject;
import java.util.*;

/*******************************************************************************
 *   Copyright 2015 Serendio Inc. ( http://www.serendio.com/ )
 *   Author - Praveen Jesudhas
 *    
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *******************************************************************************/
package com.diskoverorta.utils;



/**
 * Created by praveen on 25/11/14.
 */
public class EntityUtils
{
    public static EntityMap extractEntityMap(EntityObject eObj)
    {
        EntityMap eMap = new EntityMap();
        eMap.personCount = getListFrequency(eObj.person);
        eMap.organizationCount = getListFrequency(eObj.organization);
        eMap.locationCount = getListFrequency(eObj.location);
        eMap.personAlias = getAliasMap(eMap.personCount);
        eMap.organizationAlias = getAliasMap(eMap.organizationCount);
        eMap.locationAlias = getAliasMap(eMap.locationCount);

        return eMap;
    }
    public static Map<String,Integer> getListFrequency(List<String> elist)
    {
        Map<String,Integer> tempMap = new TreeMap<String,Integer>();
        for(int i = 0 ; i < elist.size() ; i++)
        {
            String temp  = elist.get(i).toLowerCase().trim();

            if(tempMap.containsKey(temp))
            {
                Integer val = tempMap.get(temp);
                tempMap.put(temp,val+1);
            }
            else
                tempMap.put(temp,1);
        }
        return tempMap;
    }
    public static EntityAPISet getEntitySet(DocumentObject documentObject)