Package com.ikanow.infinit.e.data_model.store.feature.entity

Examples of com.ikanow.infinit.e.data_model.store.feature.entity.EntityFeaturePojo


        }
        catch (Exception e) {} // Try a different share
      }
    }//TESTED
    if (null == shareForNewAliases) { // Didn't find one, so going to have to create something
      EntityFeaturePojo discard = new EntityFeaturePojo();
      discard.setDisambiguatedName("DISCARD");
      discard.setType("SPECIAL");
      discard.setIndex("DISCARD");
      EntityFeaturePojo docDiscard = new EntityFeaturePojo();
      docDiscard.setDisambiguatedName("DOCUMENT_DISCARD");
      docDiscard.setType("SPECIAL");
      docDiscard.setIndex("DOCUMENT_DISCARD");
      contentForNewAliases = new BasicDBObject("DISCARD", discard.toDb());
      contentForNewAliases.put("DOCUMENT_DISCARD", docDiscard);
      ResponseObject response = new ResponseObject();
      shareForNewAliases = this.addShareJSON("Alias Share: " + communityIdStr, "An alias share for a specific community", "infinite-entity-alias", "{}", response);
      if ((null == shareForNewAliases) || !response.isSuccess()) {
View Full Code Here


            Map.Entry<String, Object> entry = (Map.Entry<String, Object>)entryObj;
           
            String masterAlias = entry.getKey();
           
            BasicDBObject entityFeatureObj = (BasicDBObject) entry.getValue();
            EntityFeaturePojo aliasInfo = null;
            try {
              aliasInfo = EntityFeaturePojo.fromDb(entityFeatureObj, EntityFeaturePojo.class);
            }
            catch (Exception e) {
              continue;
            }
            if (null == aliasInfo.getIndex()) {
              aliasInfo.setIndex(masterAlias);
            }

            if (null != aliasInfo) { // (allow getAlias to be null/empty)
              //(overwrite duplicates)
              masterAliases.put(aliasInfo.getIndex(), aliasInfo);
              if (null != aliasMapping) {
                List<SharePojo> shareList = aliasMapping.get(aliasInfo.getIndex());
                if (null == shareList) {
                  shareList = new LinkedList<SharePojo>();
                  aliasMapping.put(aliasInfo.getIndex(), shareList);
                }
                shareList.add(share);
              }
            }
          }
View Full Code Here

           
          }
          ObjectId communityId = doc.getCommunityId();
          if (null != communityId)
          {
            EntityFeaturePojo feature = entityInCommunity.get(communityId);
            if (null == feature)
            {
              feature = new EntityFeaturePojo();
              feature.setCommunityId(communityId);
              feature.setDimension(ent.getDimension());
              feature.setDisambiguatedName(ent.getDisambiguatedName());
              feature.setType(ent.getType());
              feature.addAlias(ent.getDisambiguatedName());             
              entityInCommunity.put(feature.getCommunityId(), feature);
            }
            if ( feature.getGeotag() == null )  {
              feature.setGeotag(ent.getGeotag());
              feature.setOntology_type(ent.getOntology_type());
            }
            if (null != ent.getSemanticLinks()) {
              feature.addToSemanticLinks(ent.getSemanticLinks());
            }
            feature.addAlias(ent.getActual_name());
            feature.setDoccount(feature.getDoccount() + 1);
            feature.setTotalfreq(feature.getTotalfreq() + ent.getFrequency());
          }
        }
      }//TESTED
      if (null != doc.getAssociations()) {
        Iterator<AssociationPojo> evtIt = doc.getAssociations().iterator();
        while (evtIt.hasNext())  { 
          AssociationPojo evt = evtIt.next();

          if (null != deletedEntities) { // check we're not using these entities in our associations
            if (null != evt.getEntity1_index() && deletedEntities.contains(evt.getEntity1_index())) {
              evtIt.remove();
              continue;
            }//TESTED (cut and paste from tested code below)
            if (null != evt.getEntity2_index() && deletedEntities.contains(evt.getEntity2_index())) {
              evtIt.remove();
              continue;
            }//TESTED
            if (null != evt.getGeo_index() && deletedEntities.contains(evt.getGeo_index())) {
              evt.setGeo_index(null);
            }//TESTED (trivial)
           
          }//TESTED
         
          boolean bAlreadyCountedFreq = false;         
          if ((null == evt.getEntity1_index()) && (null == evt.getEntity2_index())) {//skip this event if there is no ent1/en2
            continue;
          }
          // Calc index (this is not remotely unique, of course, but good enough for now...):
          String sEventFeatureIndex = AssociationAggregationUtils.getEventFeatureIndex(evt);
          evt.setIndex(sEventFeatureIndex); //(temp save for applyAggregationToDocs below)
         
          // Use index:
          Map<ObjectId, AssociationFeaturePojo> eventInCommunity = _aggregatedEvents.get(sEventFeatureIndex);
          if (null == eventInCommunity) {
            eventInCommunity = new HashMap<ObjectId, AssociationFeaturePojo>();
            _aggregatedEvents.put(sEventFeatureIndex, eventInCommunity);
            intraDocStore.add(sEventFeatureIndex);
          }
          else if (intraDocStore.contains(sEventFeatureIndex)) {
            bAlreadyCountedFreq = true;
          }
          else {
            intraDocStore.add(sEventFeatureIndex);
          }
          ObjectId communityId = doc.getCommunityId();
          if (null != communityId) {
            AssociationFeaturePojo feature = eventInCommunity.get(communityId);
            if (null == feature) {
              feature = new AssociationFeaturePojo();
              feature.setCommunityId(communityId);
              feature.setIndex(sEventFeatureIndex);
              feature.setEntity1_index(evt.getEntity1_index());
              feature.setEntity2_index(evt.getEntity2_index());
              feature.setVerb_category(evt.getVerb_category());
              feature.setAssociation_type(evt.getAssociation_type());
              feature.setGeo_index(evt.getGeo_index());
              eventInCommunity.put(feature.getCommunityId(), feature);
            }
            if (!bAlreadyCountedFreq) {
              feature.setDoccount(feature.getDoccount() + 1);
            }
            if (null != evt.getEntity1_index()) {
              feature.addEntity1(evt.getEntity1_index());
            }
            if (null != evt.getEntity2_index()) {
              feature.addEntity2(evt.getEntity2_index());
            }
            if (null != evt.getVerb()) {
              feature.addVerb(evt.getVerb());
            }
            if (null != evt.getEntity1()) {
              // Restrict length of entity string, in case it's a quotation
              if (evt.getEntity1().length() > AssociationFeaturePojo.entity_MAXSIZE) {
                int i = AssociationFeaturePojo.entity_MAXSIZE;
                for (; i > AssociationFeaturePojo.entity_MAXSIZE - 10; --i) {
                  char c = evt.getEntity1().charAt(i);
                  if (c < 0x30) {
                    break;
                  }
                }
                feature.addEntity1(evt.getEntity1().substring(0, i+1));
              }
              else {
                feature.addEntity1(evt.getEntity1());
              }//TESTED (both clauses, 2.1.4.3a)
            }
            if (null != evt.getEntity2()) {
              // Restrict length of entity string, in case it's a quotation
              if (evt.getEntity2().length() > AssociationFeaturePojo.entity_MAXSIZE) {
                int i = AssociationFeaturePojo.entity_MAXSIZE;
                for (; i > AssociationFeaturePojo.entity_MAXSIZE - 10; --i) {
                  char c = evt.getEntity2().charAt(i);
                  if (c < 0x30) {
                    break;
                  }
                }
                feature.addEntity2(evt.getEntity2().substring(0, i+1));
              }
              else {
                feature.addEntity2(evt.getEntity2());
              }//TESTED (both clauses, 2.1.4.3a)
            }
          }
        }//(end loop over associations)       
      }//TESTED
View Full Code Here

    for (DocumentPojo doc: docsToAdd) {
     
      if (null != doc.getEntities()) for (EntityPojo ent: doc.getEntities()) {
        Map<ObjectId, EntityFeaturePojo> entityInCommunity = _aggregatedEntities.get(ent.getIndex());
        if ((null != entityInCommunity) && !entityInCommunity.isEmpty()) { // (should always be true)
          EntityFeaturePojo entityFeature = null;
          if (1 == entityInCommunity.size()) {
            entityFeature = entityInCommunity.values().iterator().next();       
          }
          else {           
            entityFeature = entityInCommunity.get(doc.getCommunityId());
          }
          ent.setDoccount(entityFeature.getDoccount());
          ent.setTotalfrequency(entityFeature.getTotalfreq());
        }       
      }// (End loop over entities)
     
      //TODO (INF-1276): The listed INF has a workaround for this, need to decide whether to implement
      // a full solution along the lines of the code below.
View Full Code Here

         
          long nIndividualTime_ms = new Date().getTime(); // for stats

          // Update entities:
          // (duplicate a few entity fields so I can _first_ sync the entity, which corrupts it)
          EntityFeaturePojo docEnt = new EntityFeaturePojo();
          docEnt.setIndex(entity.getIndex());
          docEnt.setDoccount(entity.getDoccount());
          docEnt.setTotalfreq(entity.getTotalfreq());
          ObjectId communityId = entity.getCommunityId();
          EntityAggregationUtils.synchronizeEntityFeature(entity, communityId);
            // (this also removes db_sync_prio - and corrupts "entity", hence use "docEnt" below)
          EntityAggregationUtils.updateMatchingEntities(docEnt, communityId);
            // (some of the time I'll lose my lock in here - this is checked below)         
View Full Code Here

     
      Iterator<Map.Entry<ObjectId, EntityFeaturePojo>> it = entCommunity.entrySet().iterator();
      while (it.hasNext()) {
        Map.Entry<ObjectId, EntityFeaturePojo> entFeatureKV = it.next();
        try {         
          EntityFeaturePojo entFeature = entFeatureKV.getValue();
 
          long nSavedDocCount = entFeature.getDoccount();
          long nSavedFreqCount = entFeature.getTotalfreq();
            // (these should be constant across all communities but keep it here
            //  so can assign it using entFeature, it's v cheap so no need to get once like for sync vars)
         
          ObjectId communityID = entFeature.getCommunityId();
          if (null != communityID)
          {
            // For each community, see if the entity feature already exists *for that community*
           
            BasicDBObject query = new BasicDBObject(EntityFeaturePojo.index_, entFeature.getIndex());
            query.put(EntityFeaturePojo.communityId_, communityID);
            BasicDBObject updateOp = new BasicDBObject();
            // Add aliases:
            BasicDBObject updateOpA = new BasicDBObject();
            BasicDBObject multiopE = new BasicDBObject(MongoDbManager.each_, entFeature.getAlias());
            updateOpA.put(EntityFeaturePojo.alias_, multiopE);
            // Add link data, if there is any:
            if ((null != entFeature.getSemanticLinks()) && !entFeature.getSemanticLinks().isEmpty()) {
              BasicDBObject multiopF = new BasicDBObject(MongoDbManager.each_, entFeature.getSemanticLinks());             
              updateOpA.put(EntityFeaturePojo.linkdata_, multiopF);
            }
            updateOp.put(MongoDbManager.addToSet_, updateOpA);
            // Update frequency:
            BasicDBObject updateOpB = new BasicDBObject();
            updateOpB.put(EntityFeaturePojo.totalfreq_, nSavedFreqCount);
            updateOpB.put(EntityFeaturePojo.doccount_, nSavedDocCount);
            updateOp.put(MongoDbManager.inc_, updateOpB);
 
            //try to use find/modify to see if something comes back and set doc freq/totalfreq
            BasicDBObject fields = new BasicDBObject(EntityFeaturePojo.totalfreq_,1);
            fields.put(EntityFeaturePojo.doccount_, 1);
            fields.put(EntityFeaturePojo.alias_, 1);
            fields.put(EntityFeaturePojo.linkdata_, 1);
              //(slightly annoying, since only want these 2 largish fields if updating freq but won't know
              // until after i've got this object)           
            fields.put(EntityFeaturePojo.db_sync_time_, 1);
            fields.put(EntityFeaturePojo.db_sync_doccount_, 1);
 
            DBObject dboUpdate = null;
            if (_diagnosticMode) {
              dboUpdate = col.findOne(query,fields);
            }
            else {
              dboUpdate = col.findAndModify(query, fields, new BasicDBObject(), false, updateOp, false, true);
                // (can use findAndModify because specify index, ie the shard key)
                // (returns entity before the changes above, update the feature object below)
                // (also atomically creates the object if it doesn't exist so is "distributed-safe")
            }
            if ( ( dboUpdate != null ) && !dboUpdate.keySet().isEmpty() ) // (feature already exists)
            {
              // (Update the entity feature to be correct so that it can be accurately synchronized with the index)             
              EntityFeaturePojo gp = EntityFeaturePojo.fromDb(dboUpdate, EntityFeaturePojo.class);
              entFeature.setTotalfreq(gp.getTotalfreq() + nSavedFreqCount);
              entFeature.setDoccount(gp.getDoccount() + nSavedDocCount);
              entFeature.setDbSyncDoccount(gp.getDbSyncDoccount());
              entFeature.setDbSyncTime(gp.getDbSyncTime());
              if (null != gp.getAlias()) {
                entFeature.addAllAlias(gp.getAlias());
              }
              if (null != gp.getSemanticLinks()) {
                entFeature.addToSemanticLinks(gp.getSemanticLinks());
              }
              if (_diagnosticMode) {
                System.out.println("EntityAggregationUtils.updateEntityFeatures, found: " + ((BasicDBObject)gp.toDb()).toString());
                System.out.println("EntityAggregationUtils.updateEntityFeatures, ^^^ found from query: " + query.toString() + " / " + updateOp.toString());
              }
              // (In background aggregation mode we update db_sync_prio when checking the doc update schedule)
            }
            else // (the object in memory is now an accurate representation of the database, minus some fields we'll now add)
View Full Code Here

        // More alias handling
        String index = null;
        if (null != aliasTable) {
          index = (String) hit.field(EntityFeaturePojo.index_).value();
          EntityFeaturePojo alias = aliasTable.getAliasMaster(index);
          if (null != alias) { // Found!
            if (alias.getIndex().equalsIgnoreCase("discard")) { // Discard this entity
              continue;
            }
            else if ((null != alias.getDisambiguatedName()) && (null != alias.getType())) {
              // (these need to be present)

              //DEBUG (perf critical)
              //logger.debug("Alias! Replace " + index + " with " + alias.getIndex());

              index = alias.getIndex();
              disname = alias.getDisambiguatedName();
              type = alias.getType();
              if (null != alias.getDimension()) {
                dimension = alias.getDimension().toString();
              }
              else { // Guess from type
                dimension = DimensionUtility.getDimensionByType(type).toString();
              }
              // Reset values:
View Full Code Here

        for (String entIndex: aggregation.moments.entityList) {
         
          CrossVersionFacetBuilder.DateHistogramFacetBuilder fb = CrossVersionFacetBuilders.dateHistogramFacet("moments." + entIndex).
                          field(DocumentPojo.publishedDate_).interval(aggregation.moments.timesInterval);
         
          EntityFeaturePojo alias = null;
          if (null != aliasLookup) {
            alias = aliasLookup.getAliases(entIndex);
          }
          if (null == alias) { // no alias
            fb = fb.facetFilter(FilterBuilders.nestedFilter(DocumentPojo.entities_,
                      FilterBuilders.termFilter(EntityPojo.index_, entIndex)));
          }//TESTED
          else {
            QueryFilterBuilder qfb = null;
            if ((null != alias.getSemanticLinks()) && !alias.getSemanticLinks().isEmpty())  {
              BoolQueryBuilder qb = QueryBuilders.boolQuery();
              for (String textAlias: alias.getSemanticLinks()) {
                qb = qb.should(CrossVersionQueryBuilders.matchPhraseQuery(DocumentPojo.fullText_, textAlias));
              }
              qfb = FilterBuilders.queryFilter(qb);             
            }//TESTED
            if (!alias.getAlias().isEmpty()) {
              NestedFilterBuilder nfb = FilterBuilders.nestedFilter(DocumentPojo.entities_,
                          FilterBuilders.termsFilter(EntityPojo.index_, entIndex, alias.getAlias()));
              if (null == qfb) {
                fb = fb.facetFilter(nfb);
              }//TESTED
              else {
                BoolFilterBuilder bfb = FilterBuilders.boolFilter().should(nfb).should(qfb);
View Full Code Here

        boolean bTransformedByAlias = false; // when true need to re-check vs entity type filter
       
        // Now write the last few values (adjusted for aliases if necessary) into the JSON object
        if (null != sEnt1_index) {
          if (null != aliasLookup) {
            EntityFeaturePojo alias = aliasLookup.getAliasMaster(sEnt1_index);
            if (null != alias) {
              sEnt1_index = alias.getIndex();
              if (sEnt1_index.equalsIgnoreCase("discard")) {
                continue;
              }//TESTED
              bTransformedByAlias = true;
            }
          }         
          json.put(AssociationPojo.entity1_index_, sEnt1_index);
        }
        if (null != sEnt2_index) {
          if (null != aliasLookup) {
            EntityFeaturePojo alias = aliasLookup.getAliasMaster(sEnt2_index);
            if (null != alias) {
              sEnt2_index = alias.getIndex();
              if (sEnt2_index.equalsIgnoreCase("discard")) {
                continue;
              }//TESTED (cut and paste of ent index1)
              bTransformedByAlias = true;
            }           
          }         
          json.put(AssociationPojo.entity2_index_, sEnt2_index);         
        }
        if (null != sGeoIndex) {
          if (null != aliasLookup) {
            EntityFeaturePojo alias = aliasLookup.getAliasMaster(sGeoIndex);
            if (null != alias) {
              sGeoIndex = alias.getIndex();
              if (sGeoIndex.equalsIgnoreCase("discard")) {
                if ((sEnt1_index != null) && (sEnt2_index != null)) {
                  sGeoIndex = null; // event/fact is still valid even without the geo                 
                }//TESTED
                else continue; // event/fact now meaningless
View Full Code Here

    if ((null != entTypeFilter) || (null != aliasLookup)) {     
      String ent1Index = e.getString(AssociationPojo.entity1_index_);
      if (null != ent1Index) {
        String entType = null;
        if (null != aliasLookup) {
          EntityFeaturePojo alias = aliasLookup.getAliasMaster(ent1Index);
          if (null != alias) {           
            ent1Index = alias.getIndex();
            entType = alias.getType();           
            if (ent1Index.equalsIgnoreCase("discard")) {
              return false;
            }
            else { // rename
              if (bModifyAssocObj) {
                e.put(AssociationPojo.entity1_index_, alias.getIndex());
              }
            }
          }
        }//TESTED
        if (null == entType) {
          int nIndex = ent1Index.lastIndexOf('/');
          if (nIndex >= 0) {
            entType = ent1Index.substring(nIndex + 1);
          }
        }
        else {
          entType = entType.toLowerCase();
        }//TESTED (both clauses)
        if (null != entTypeFilter) {         
          if (bEntTypeFilterPositive) {
            if ((null != entType) && (!entTypeFilter.contains(entType))) {
              return false;
            }
          }
          else if ((null != entType) && (entTypeFilter.contains(entType))) {
            return false;
          }
        }
        //TESTED
       
      }//(end if ent1_index exists)

      String ent2Index = e.getString(AssociationPojo.entity2_index_);
      if (null != ent2Index) {
        String entType = null;
        if (null != aliasLookup) {
          EntityFeaturePojo alias = aliasLookup.getAliasMaster(ent2Index);
          if (null != alias) {
            ent2Index = alias.getIndex();
            entType = alias.getType();
            if (ent2Index.equalsIgnoreCase("discard")) {
              return false;
            }
            else { // rename
              if (bModifyAssocObj) {
                e.put(AssociationPojo.entity2_index_, alias.getIndex());
              }
            }
          }
        }//TESTED (cut and paste from ent1)
        if (null == entType) {
          int nIndex = ent2Index.lastIndexOf('/');
          if (nIndex >= 0) {
            entType = ent2Index.substring(nIndex + 1);
          }
        }
        else {
          entType = entType.toLowerCase();
        }//TESTED (cut and paste from ent1)
        if (null != entTypeFilter) {
          if (bEntTypeFilterPositive) {
            if ((null != entType) && (!entTypeFilter.contains(entType))) {
              return false;
            }
          }
          else if ((null != entType) && (entTypeFilter.contains(entType))) {
            return false;
          }
        }
      }//(end if ent2_index exists)
     
      String geoIndex = e.getString(AssociationPojo.geo_index_);
      if (null != geoIndex) {
        String entType = null;
        if (null != aliasLookup) {
          EntityFeaturePojo alias = aliasLookup.getAliasMaster(geoIndex);
          if (null != alias) {
            geoIndex = alias.getIndex();
            entType = alias.getType();
            if (geoIndex.equalsIgnoreCase("discard")) {
              if ((ent1Index == null) || (ent2Index == null)) {
                return false;               
              }
              else if (bModifyAssocObj) {
                e.remove(AssociationPojo.geo_index_);
              }
              else {
                return false;
              }
            }
            else { // rename
              if (bModifyAssocObj) {
                e.put(AssociationPojo.geo_index_, alias.getIndex());
              }
            }
          }
        }//TESTED (cut and paste from ent1)
        if (null == entType) {
View Full Code Here

TOP

Related Classes of com.ikanow.infinit.e.data_model.store.feature.entity.EntityFeaturePojo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.