Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

88
LINES

< > BotCompany Repo | #1029015 // deepDoubleWordIndex_search - does the full search [dev.]

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Compilation Failed (4190L/26K).

1  
// returns null if there are no letters in the query
2  
// otherwise returns actual search result
3  
static <A> Iterable<A> deepDoubleWordIndex_search(DoubleWordIndex<WithIntArray<A>> index, Map<A, S> texts, S query, O... _) {
4  
  optPar bool debug;
5  
  L<IntRange> ranges = index.wordRanges(query);
6  
  if (empty(ranges)) null;
7  
  int nRanges = l(ranges);
8  
  new Map<A, MultiSetMap<Int>> theMap; // for every snippet, a map of string position to word index
9  
10  
  // special case, just a single word in query
11  
  if (l(ranges) == 1 && first(ranges).start == 0 && first(ranges).end == l(query)) {
12  
    new Set<A> seen;
13  
    ret nestedIterator(containingIC(index.index1.words(), query), fullWord ->
14  
      mapI_notNulls_if1(index.index1.get(fullWord), e -> addAndReturnIfNew(seen, e!)));
15  
  }
16  
  
17  
  Set<A> baseSet = null;
18  
  /*if (int iWord = 1; i < nRanges-1; i++) { // go through all "full" words
19  
    IntRange r = ranges.get(iWord);
20  
    S word = substring(query, r);
21  
    Set<WithIntArray<S>> entries = index.index1.get(word);
22  
    if (baseSet == null) baseSet = ...
23  
  }*/
24  
  
25  
  for iWord to nRanges: { // go through words in query
26  
    IntRange r = ranges.get(iWord);
27  
    S word = substring(query, r);
28  
    Cl<S> l; // all matching words in index
29  
    WordIndex<WithIntArray<A>> indexToUse = index.index1;
30  
      
31  
    if (r.start == 0) { // look for ending of word - use reverse index
32  
      l = prefixSubSet(index.index2.words(), reversed(word));
33  
      if (empty(l)) ret emptyList();
34  
      if (debug) print("word=" + word + ", fullWords=" + l);
35  
      
36  
      // special loop that accounts for length of actual word
37  
      for (S fullWord : l)
38  
        for (WithIntArray<A> entry : index.index2.index.get(fullWord)) {
39  
          if (baseSet != null && !baseSet.contains(entry!)) continue;
40  
          MultiSetMap<Int> msm = theMap.get(entry!);
41  
          if (msm == null) theMap.put(entry!, msm = new MultiSetMap);
42  
          int ofs = l(fullWord)-l(word)-r.start;
43  
          for (int i : entry.array) {
44  
            int idx = i+ofs;
45  
            if (debug) print("Got idx " + idx);
46  
            if (idx >= 0)
47  
              msm.put(idx, iWord);
48  
          }
49  
        }
50  
      continue;
51  
    } else if (r.end == l(query)) { // look for start of word
52  
      l = prefixSubSet(index.index1.words(), word);
53  
    } else // look for complete word
54  
      l = ll(word);
55  
      
56  
    if (empty(l)) ret emptyList();
57  
    
58  
    if (debug) print("word=" + word + ", fullWords=" + l);
59  
      
60  
    for (S fullWord : l)
61  
      for (WithIntArray<A> entry : indexToUse.index.get(fullWord)) {
62  
        if (baseSet != null && !baseSet.contains(entry!)) continue;
63  
        if (debug) print("Got entry " + entry);
64  
        MultiSetMap<Int> msm = theMap.get(entry!);
65  
        if (msm == null) theMap.put(entry!, msm = new MultiSetMap);
66  
        for (int i : entry.array) {
67  
          int idx = i-r.start;
68  
          if (debug) print("Got idx " + idx);
69  
          if (idx >= 0)
70  
            msm.put(idx, iWord);
71  
        }
72  
      }
73  
  }
74  
  
75  
  if (debug) print("theMap size=" + l(theMap));
76  
  new L<A> out;
77  
  theLoop: for (A snippet, MultiSetMap<Int> msm : theMap) {
78  
    if (debug) print("snippet " + snippet);
79  
    for (int position, Set<Int> wordIndices : msm.data) {
80  
      if (debug) print("position " + position + ": " + l(wordIndices) + "/" + nRanges);
81  
      if (l(wordIndices) == nRanges) {
82  
        out.add(snippet);
83  
        continue theLoop;
84  
      }
85  
    }
86  
  }
87  
  ret out;
88  
}

Author comment

Began life as a copy of #1029012

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1029015
Snippet name: deepDoubleWordIndex_search - does the full search [dev.]
Eternal ID of this version: #1029015/3
Text MD5: e664b446ec80b8ae4a03b2f59000ed5f
Transpilation MD5: 59b8dad289496b5ccf11504d59da4d21
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-16 23:47:05
Source code size: 3469 bytes / 88 lines
Pitched / IR pitched: No / No
Views / Downloads: 186 / 271
Version history: 2 change(s)
Referenced in: [show references]