Examples of AssociationFeaturePojo


Examples of com.ikanow.infinit.e.data_model.store.feature.association.AssociationFeaturePojo

     
      Iterator<Map.Entry<ObjectId, AssociationFeaturePojo>> it = evtCommunity.entrySet().iterator();
      while (it.hasNext()) {
        Map.Entry<ObjectId, AssociationFeaturePojo> evtFeatureKV = it.next();       
        try {         
          AssociationFeaturePojo evtFeature = evtFeatureKV.getValue();
          long nSavedDocCount = evtFeature.getDoccount();

          ObjectId communityID = evtFeature.getCommunityId();
          //try to update
          BasicDBObject query = new BasicDBObject(AssociationFeaturePojo.index_, evtFeature.getIndex());
          query.put(AssociationFeaturePojo.communityId_, communityID);

          //Step1 try to update alias
          //update arrays
          BasicDBObject multiopAliasArrays = new BasicDBObject();                     
          // Entity1 Alias:
          if (null != evtFeature.getEntity1_index()) {
            evtFeature.addEntity1(evtFeature.getEntity1_index());
          }
          if (null != evtFeature.getEntity1())
          {
            BasicDBObject multiopE = new BasicDBObject(MongoDbManager.each_, evtFeature.getEntity1());
            multiopAliasArrays.put(AssociationFeaturePojo.entity1_, multiopE);
          }
          // Entity2 Alias:
          if (null != evtFeature.getEntity2_index()) {
            evtFeature.addEntity2(evtFeature.getEntity2_index());
          }
          if (null != evtFeature.getEntity2()) {
            BasicDBObject multiopE = new BasicDBObject(MongoDbManager.each_, evtFeature.getEntity2());
            multiopAliasArrays.put(AssociationFeaturePojo.entity2_, multiopE);
          }
          // verb/verb cat alias:
          if (null != evtFeature.getVerb_category()) {
            evtFeature.addVerb(evtFeature.getVerb_category());
          }
          if (null != evtFeature.getVerb()) {
            BasicDBObject multiopE = new BasicDBObject(MongoDbManager.each_, evtFeature.getVerb());
            multiopAliasArrays.put(AssociationFeaturePojo.verb_, multiopE);
          }
          BasicDBObject updateOp = new BasicDBObject()
          updateOp.put(MongoDbManager.addToSet_, multiopAliasArrays);
          // Document count for this event
          BasicDBObject updateFreqDocCount = new BasicDBObject(AssociationFeaturePojo.doccount_, nSavedDocCount);
          updateOp.put(MongoDbManager.inc_,updateFreqDocCount);

          BasicDBObject fields = new BasicDBObject(AssociationFeaturePojo.doccount_, 1);
          fields.put(AssociationFeaturePojo.entity1_, 1);
          fields.put(AssociationFeaturePojo.entity2_, 1);
          fields.put(AssociationFeaturePojo.verb_, 1);
          //(slightly annoying, since only want these if updating dc but won't know
          // until after i've got this object)

          fields.put(AssociationFeaturePojo.db_sync_time_, 1);
          fields.put(AssociationFeaturePojo.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 event 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() )
          {
            AssociationFeaturePojo egp = AssociationFeaturePojo.fromDb(dboUpdate, AssociationFeaturePojo.class);
            evtFeature.setDoccount(egp.getDoccount() + nSavedDocCount);
            evtFeature.setDb_sync_doccount(egp.getDb_sync_doccount());
            evtFeature.setDb_sync_time(egp.getDb_sync_time());
            if (null != egp.getEntity1()) {
              for (String ent: egp.getEntity1()) evtFeature.addEntity1(ent);
            }
            if (null != egp.getEntity2()) { 
              for (String ent: egp.getEntity2()) evtFeature.addEntity2(ent);
            }
            if (null != egp.getVerb()) {
              for (String verb: egp.getVerb()) evtFeature.addVerb(verb);
            }             
            if (_diagnosticMode) {
              System.out.println("EventAggregationUtils.updateEventFeatures, found: " + ((BasicDBObject)egp.toDb()).toString());
              System.out.println("EventAggregationUtils.updateEventFeatures, ^^^ found from query: " + query.toString() + " / " + updateOp.toString());
            }
            // (In background aggregation mode we update db_sync_prio when checking the -otherwise unused, unlike entities- document 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

Examples of com.ikanow.infinit.e.data_model.store.feature.association.AssociationFeaturePojo

          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

Examples of com.ikanow.infinit.e.data_model.store.feature.association.AssociationFeaturePojo

   
    // Loop over array and invoke the cleansing function for each one
    while ( dbc.hasNext() )
    {
      BasicDBObject dbo = (BasicDBObject) dbc.next();
      AssociationFeaturePojo evt = AssociationFeaturePojo.fromDb(dbo,AssociationFeaturePojo.class);
     
      // If this table has just been rebuilt from the document then the indexes are all wrong ...
      // recalculate and save
      if ('#' == evt.getIndex().charAt(0)) {
        AssociationPojo singleEvt = new AssociationPojo();
        singleEvt.setEntity1_index(evt.getEntity1_index());
        singleEvt.setEntity2_index(evt.getEntity2_index());
        singleEvt.setVerb_category(evt.getVerb_category());
        singleEvt.setGeo_index(evt.getGeo_index());
        evt.setIndex(AssociationAggregationUtils.getEventFeatureIndex(singleEvt));
        eventFeatureDB.update(new BasicDBObject("_id", dbo.get("_id")),
                      new BasicDBObject(MongoDbManager.set_,
                          new BasicDBObject(AssociationFeaturePojo.index_, evt.getIndex())), false, true);
          // (has to be a multi-update even though it's unique because it's sharded on index)
      }
     
      // Handle groups (system group is: "4c927585d591d31d7b37097a")
      if (null == evt.getCommunityId())
      {
        evt.setCommunityId(new ObjectId("4c927585d591d31d7b37097a"));
      }
      // Bulk add prep
      events.add(evt);
      nSynced++;
         
View Full Code Here

Examples of com.ikanow.infinit.e.data_model.store.feature.association.AssociationFeaturePojo

     
      ArrayList<AssociationFeaturePojo> events = new ArrayList<AssociationFeaturePojo>();
      LinkedList<String> eventIds = new LinkedList<String>();
      while (cur.hasNext())
      {
        AssociationFeaturePojo event = AssociationFeaturePojo.fromDb(cur.next(),AssociationFeaturePojo.class)
        events.add(event);
        eventIds.add(new StringBuffer(event.getIndex()).append(":").append(event.getCommunityId()).toString());
        eventFeatureDB.remove(new BasicDBObject("index", event.getIndex()));
      }
      ElasticSearchManager elasticManager = ElasticSearchManager.getIndex("association_index");
      elasticManager.bulkDeleteDocuments(eventIds);
     
    } catch (NumberFormatException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.