Changeset 33645

Show
Ignore:
Timestamp:
11.11.2019 18:45:29 (4 weeks ago)
Author:
ak19
Message:

Fix to 2 bugs when sending data to MongoDB: 1. overlappingSentences was missing because overwritten by singleSentences. But it is still empty at present because of a bug. 2. Need to store an array of tuples not with each pair of a tuple stored as an array element.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • other-projects/maori-lang-detection/src/org/greenstone/atea/MongoDBAccess.java

    r33634 r33645  
    11package org.greenstone.atea; 
    22 
    3  
     3//import org.bson.BSONObject; 
     4     
    45import com.mongodb.client.MongoCollection;  
    56import com.mongodb.client.MongoDatabase;  
     
    201202    // https://stackoverflow.com/questions/15371839/how-to-add-an-array-to-a-mongodb-document-using-java 
    202203    List<BasicDBObject> sentencesList = new ArrayList<>(); 
    203     for(SentenceInfo sentence : webpage.singleSentences) { 
    204         sentencesList.add(new BasicDBObject("langCode", sentence.langCode)); 
    205         sentencesList.add(new BasicDBObject("confidence", sentence.confidenceLevel)); 
    206         sentencesList.add(new BasicDBObject("sentence", sentence)); 
     204    for(SentenceInfo sentenceInfo : webpage.singleSentences) { 
     205        //sentencesList.add(new BasicDBObject("langCode", sentenceInfo.langCode)); 
     206        //sentencesList.add(new BasicDBObject("confidence", sentenceInfo.confidenceLevel)); 
     207        //sentencesList.add(new BasicDBObject("sentence", sentenceInfo.sentence)); 
     208        BasicDBObject bsonRecord = new BasicDBObject("langCode", sentenceInfo.langCode); 
     209        bsonRecord.put("confidence", sentenceInfo.confidenceLevel); 
     210        bsonRecord.put("sentence", sentenceInfo.sentence); 
     211         
     212        sentencesList.add(bsonRecord); 
    207213    }    
    208214    document.put("singleSentences", sentencesList); 
    209215     
    210216    List<BasicDBObject> overlappingSentencesList = new ArrayList<>(); 
    211     for(SentenceInfo sentence : webpage.overlappingSentences) { 
    212         sentencesList.add(new BasicDBObject("langCode", sentence.langCode)); 
    213         sentencesList.add(new BasicDBObject("confidence", sentence.confidenceLevel)); 
    214         sentencesList.add(new BasicDBObject("sentence", sentence)); 
     217    for(SentenceInfo sentenceInfo : webpage.overlappingSentences) { 
     218        BasicDBObject bsonRecord = new BasicDBObject("langCode", sentenceInfo.langCode); 
     219        bsonRecord.put("confidence", sentenceInfo.confidenceLevel); 
     220        bsonRecord.put("sentence", sentenceInfo.sentence); 
     221         
     222        sentencesList.add(bsonRecord); 
    215223    }    
    216     document.put("singleSentences", overlappingSentencesList); 
    217  
     224    document.put("overlappingSentences", overlappingSentencesList); 
     225     
    218226    // also put the full text in there 
    219227    document.put("text", webpage.text);