public static void main(String[] args) throws TwitterException, IOException {
   Twitter twitter = TwitterFactory.getSingleton();
   JLanguageTool langTool = new JLanguageTool(new AmericanEnglish());
   List<String> twts = new ArrayList<String>();
   for (String arg : args) {
     Query query = new Query(arg);
     QueryResult result;
     int counter = 0;
     do {
       result = twitter.search(query);
       List<Status> tweets = result.getTweets();
       for (Status tweet : tweets) {
         if (isEligible(tweet)) {
           System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
           System.out.println(tweet.getLang());
           twts.add(tweet.getText());
           counter++;
         }
       }
     } while ((query = result.nextQuery()) != null && counter < 5);
   }
   for (String str : twts) {
     List<RuleMatch> matches = langTool.check(str);
     for (RuleMatch match : matches) {
       System.out.println(
           "Potential error at line "
               + match.getLine()
               + ", column "
               + match.getColumn()
               + ": "
               + match.getMessage());
       System.out.println("Suggested correction: " + match.getSuggestedReplacements());
     }
   }
 }
예제 #2
0
  public List<ResourceName> queryMDS(PackageName packageName) {
    MDSInstance mdsInstance;
    List<ResourceName> resources = new ArrayList<ResourceName>();
    try {
      mdsInstance = storeInitializer.getMDSInstance();
      packageName = (packageName == null) ? PackageName.createPackageName("/") : packageName;
      NameCondition condition =
          ConditionFactory.createNameCondition(packageName.getAbsoluteName(), "%");
      ResourceQuery query = QueryFactory.createResourceQuery(mdsInstance, condition);

      Iterator<QueryResult> contents = query.execute();
      if (contents == null) {
        return resources;
      }
      while (contents.hasNext()) {
        QueryResult result = contents.next();
        if (result.getResultType() == QueryResult.ResultType.PACKAGE_RESULT) {
          PackageResult pack = (PackageResult) result;
          resources.add(pack.getPackageName());
        } else {
          DocumentResult doc = (DocumentResult) result;
          resources.add(doc.getDocumentName());
        }
      }
      return resources;
    } catch (MDSAccessException e) {
      throw new IllegalArgumentException("Could not connect to MDS, check login data", e);
    } catch (InvalidReferenceException e) {
      throw new IllegalArgumentException("Could not find/read " + packageName, e);
    } catch (InvalidReferenceTypeException e) {
      throw new IllegalArgumentException("No correct type!", e);
    }
  }
예제 #3
0
 private void sort(QueryResult result) {
   if (_orderings != null) {
     if (result.size() == 0) {
       return;
     }
     result.sortIds(newSodaQueryComparator());
   }
   if (_comparator != null) {
     if (result.size() == 0) {
       return;
     }
     result.sort(_comparator);
   }
 }
예제 #4
0
 public QueryResult queryOnPartition(String mapName, Predicate predicate, int partitionId) {
   final QueryResult result = new QueryResult();
   List<QueryEntry> list = new LinkedList<QueryEntry>();
   PartitionContainer container = getPartitionContainer(partitionId);
   RecordStore recordStore = container.getRecordStore(mapName);
   Map<Data, Record> records = recordStore.getReadonlyRecordMap();
   SerializationService serializationService = nodeEngine.getSerializationService();
   final PagingPredicate pagingPredicate =
       predicate instanceof PagingPredicate ? (PagingPredicate) predicate : null;
   Comparator<Map.Entry> wrapperComparator = SortingUtil.newComparator(pagingPredicate);
   for (Record record : records.values()) {
     Data key = record.getKey();
     Object value = record.getValue();
     if (value == null) {
       continue;
     }
     QueryEntry queryEntry = new QueryEntry(serializationService, key, key, value);
     if (predicate.apply(queryEntry)) {
       if (pagingPredicate != null) {
         Map.Entry anchor = pagingPredicate.getAnchor();
         if (anchor != null
             && SortingUtil.compare(
                     pagingPredicate.getComparator(),
                     pagingPredicate.getIterationType(),
                     anchor,
                     queryEntry)
                 >= 0) {
           continue;
         }
       }
       list.add(queryEntry);
     }
   }
   if (pagingPredicate != null) {
     Collections.sort(list, wrapperComparator);
     if (list.size() > pagingPredicate.getPageSize()) {
       list = list.subList(0, pagingPredicate.getPageSize());
     }
   }
   for (QueryEntry entry : list) {
     result.add(
         new QueryResultEntryImpl(entry.getKeyData(), entry.getKeyData(), entry.getValueData()));
   }
   return result;
 }
  public void grab(Date timeLimit) {
    log.info("Twitter grabber started...");
    Twitter twitter = new TwitterFactory().getInstance();

    List<Brand> brandList = handler.getBrandProvider().getAllBrands();
    ArticleProvider articleProvider = handler.getArticleProvider();

    for (Brand b : brandList) {
      Query query = new Query(b.getName());
      query.setRpp(PAGE_SIZE);
      query.setLang("ru");
      query.setResultType(Query.MIXED);

      List<Tweet> resultTweets = new LinkedList<Tweet>();
      QueryResult queryResult;
      int pageNumber = 1;

      try {
        do {
          query.setPage(pageNumber);
          queryResult = twitter.search(query);
          resultTweets.addAll(queryResult.getTweets());
          pageNumber++;
          log.info(pageNumber);
        } while (ISSUANCE_SIZE > resultTweets.size());
      } catch (TwitterException e) {
        throw new RuntimeException(e);
      }
      log.info("tweets in da111y: " + resultTweets.size());
      twitter = null;
      twitter = new TwitterFactory().getInstance();

      for (Tweet t : resultTweets) {
        articleProvider.writeArticleToDataStore(
            new Article(-1, b.getId(), 2, "", t.getText(), "", getSimpleTime(t.getCreatedAt()), 1));
      }
    }
    log.info("twitter grabber finished succesful.");
  }
예제 #6
0
  public void querySample() {
    try {
      // Set query batch size
      partnerConnection.setQueryOptions(250);

      // SOQL query to use
      String soqlQuery = "SELECT FirstName, LastName FROM Contact";
      // Make the query call and get the query results
      QueryResult qr = partnerConnection.query(soqlQuery);

      boolean done = false;
      int loopCount = 0;
      // Loop through the batches of returned results
      while (!done) {
        System.out.println("Records in results set " + loopCount++ + " - ");
        SObject[] records = qr.getRecords();
        // Process the query results
        for (int i = 0; i < records.length; i++) {
          SObject contact = records[i];
          Object firstName = contact.getField("FirstName");
          Object lastName = contact.getField("LastName");
          if (firstName == null) {
            System.out.println("Contact " + (i + 1) + ": " + lastName);
          } else {
            System.out.println("Contact " + (i + 1) + ": " + firstName + " " + lastName);
          }
        }
        if (qr.isDone()) {
          done = true;
        } else {
          qr = partnerConnection.queryMore(qr.getQueryLocator());
        }
      }
    } catch (ConnectionException ce) {
      ce.printStackTrace();
    }
    System.out.println("\nQuery execution completed.");
  }