Ejemplo n.º 1
0
            public override int nextDoc()
            {
                while (true)
                {
                    //System.out.println("  nextDoc cycle docUpto=" + docUpto + " numDocs=" + numDocs + " fp=" + in.getPosition() + " this=" + this);
                    if (docUpto == numDocs)
                    {
                        // System.out.println("    END");
                        return(docID_Renamed = NO_MORE_DOCS);
                    }
                    docUpto++;
                    if (indexOptions == IndexOptions.DOCS_ONLY)
                    {
                        accum += @in.readVInt();
                    }
                    else
                    {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int code = in.readVInt();
                        int code = @in.readVInt();
                        accum += (int)((uint)code >> 1);
                        //System.out.println("  docID=" + accum + " code=" + code);
                        if ((code & 1) != 0)
                        {
                            freq_Renamed = 1;
                        }
                        else
                        {
                            freq_Renamed = @in.readVInt();
                            Debug.Assert(freq_Renamed > 0);
                        }

                        if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
                        {
                            // Skip positions/payloads
                            for (int posUpto = 0; posUpto < freq_Renamed; posUpto++)
                            {
                                if (!storePayloads)
                                {
                                    @in.readVInt();
                                }
                                else
                                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int posCode = in.readVInt();
                                    int posCode = @in.readVInt();
                                    if ((posCode & 1) != 0)
                                    {
                                        payloadLen = @in.readVInt();
                                    }
                                    @in.skipBytes(payloadLen);
                                }
                            }
                        }
                        else if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS)
                        {
                            // Skip positions/offsets/payloads
                            for (int posUpto = 0; posUpto < freq_Renamed; posUpto++)
                            {
                                int posCode = @in.readVInt();
                                if (storePayloads && ((posCode & 1) != 0))
                                {
                                    payloadLen = @in.readVInt();
                                }
                                if ((@in.readVInt() & 1) != 0)
                                {
                                    // new offset length
                                    @in.readVInt();
                                }
                                if (storePayloads)
                                {
                                    @in.skipBytes(payloadLen);
                                }
                            }
                        }
                    }

                    if (liveDocs == null || liveDocs.get(accum))
                    {
                        //System.out.println("    return docID=" + accum + " freq=" + freq);
                        return(docID_Renamed = accum);
                    }
                }
            }
Ejemplo n.º 2
0
            public override int nextDoc()
            {
                while (posPending > 0)
                {
                    nextPosition();
                }
                while (true)
                {
                    //System.out.println("  nextDoc cycle docUpto=" + docUpto + " numDocs=" + numDocs + " fp=" + in.getPosition() + " this=" + this);
                    if (docUpto == numDocs)
                    {
                        //System.out.println("    END");
                        return(docID_Renamed = NO_MORE_DOCS);
                    }
                    docUpto++;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int code = in.readVInt();
                    int code = @in.readVInt();
                    accum += (int)((uint)code >> 1);
                    if ((code & 1) != 0)
                    {
                        freq_Renamed = 1;
                    }
                    else
                    {
                        freq_Renamed = @in.readVInt();
                        Debug.Assert(freq_Renamed > 0);
                    }

                    if (liveDocs == null || liveDocs.get(accum))
                    {
                        pos = 0;
                        startOffset_Renamed = storeOffsets ? 0 : -1;
                        posPending          = freq_Renamed;
                        //System.out.println("    return docID=" + accum + " freq=" + freq);
                        return(docID_Renamed = accum);
                    }

                    // Skip positions
                    for (int posUpto = 0; posUpto < freq_Renamed; posUpto++)
                    {
                        if (!storePayloads)
                        {
                            @in.readVInt();
                        }
                        else
                        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int skipCode = in.readVInt();
                            int skipCode = @in.readVInt();
                            if ((skipCode & 1) != 0)
                            {
                                payloadLength = @in.readVInt();
                                //System.out.println("    new payloadLen=" + payloadLength);
                            }
                        }

                        if (storeOffsets)
                        {
                            if ((@in.readVInt() & 1) != 0)
                            {
                                // new offset length
                                offsetLength = @in.readVInt();
                            }
                        }

                        if (storePayloads)
                        {
                            @in.skipBytes(payloadLength);
                        }
                    }
                }
            }
Ejemplo n.º 3
0
	  /// <summary>
	  /// Applies the affix rule to the given word, producing a list of stems if any are found
	  /// </summary>
	  /// <param name="strippedWord"> Word the affix has been removed and the strip added </param>
	  /// <param name="length"> valid length of stripped word </param>
	  /// <param name="affix"> HunspellAffix representing the affix rule itself </param>
	  /// <param name="prefixFlag"> when we already stripped a prefix, we cant simply recurse and check the suffix, unless both are compatible
	  ///                   so we must check dictionary form against both to add it as a stem! </param>
	  /// <param name="recursionDepth"> current recursion depth </param>
	  /// <param name="prefix"> true if we are removing a prefix (false if its a suffix) </param>
	  /// <returns> List of stems for the word, or an empty list if none are found </returns>
	  internal IList<CharsRef> applyAffix(char[] strippedWord, int length, int affix, int prefixFlag, int recursionDepth, bool prefix, bool circumfix)
	  {
		// TODO: just pass this in from before, no need to decode it twice
		affixReader.Position = 8 * affix;
		char flag = (char)(affixReader.readShort() & 0xffff);
		affixReader.skipBytes(2); // strip
		int condition = (char)(affixReader.readShort() & 0xffff);
		bool crossProduct = (condition & 1) == 1;
		condition = (int)((uint)condition >> 1);
		char append = (char)(affixReader.readShort() & 0xffff);

		IList<CharsRef> stems = new List<CharsRef>();

		IntsRef forms = dictionary.lookupWord(strippedWord, 0, length);
		if (forms != null)
		{
		  for (int i = 0; i < forms.length; i++)
		  {
			dictionary.flagLookup.get(forms.ints[forms.offset + i], scratch);
			char[] wordFlags = Dictionary.decodeFlags(scratch);
			if (Dictionary.hasFlag(wordFlags, flag))
			{
			  // confusing: in this one exception, we already chained the first prefix against the second,
			  // so it doesnt need to be checked against the word
			  bool chainedPrefix = dictionary.complexPrefixes && recursionDepth == 1 && prefix;
			  if (chainedPrefix == false && prefixFlag >= 0 && !Dictionary.hasFlag(wordFlags, (char)prefixFlag))
			  {
				// see if we can chain prefix thru the suffix continuation class (only if it has any!)
				dictionary.flagLookup.get(append, scratch);
				char[] appendFlags = Dictionary.decodeFlags(scratch);
				if (!hasCrossCheckedFlag((char)prefixFlag, appendFlags, false))
				{
				  continue;
				}
			  }

			  // if circumfix was previously set by a prefix, we must check this suffix,
			  // to ensure it has it, and vice versa
			  if (dictionary.circumfix != -1)
			  {
				dictionary.flagLookup.get(append, scratch);
				char[] appendFlags = Dictionary.decodeFlags(scratch);
				bool suffixCircumfix = Dictionary.hasFlag(appendFlags, (char)dictionary.circumfix);
				if (circumfix != suffixCircumfix)
				{
				  continue;
				}
			  }
			  stems.Add(newStem(strippedWord, length));
			}
		  }
		}

		// if a circumfix flag is defined in the dictionary, and we are a prefix, we need to check if we have that flag
		if (dictionary.circumfix != -1 && !circumfix && prefix)
		{
		  dictionary.flagLookup.get(append, scratch);
		  char[] appendFlags = Dictionary.decodeFlags(scratch);
		  circumfix = Dictionary.hasFlag(appendFlags, (char)dictionary.circumfix);
		}

		if (crossProduct)
		{
		  if (recursionDepth == 0)
		  {
			if (prefix)
			{
			  // we took away the first prefix.
			  // COMPLEXPREFIXES = true:  combine with a second prefix and another suffix 
			  // COMPLEXPREFIXES = false: combine with a suffix
			  stems.AddRange(stem(strippedWord, length, affix, flag, flag, ++recursionDepth, dictionary.complexPrefixes && dictionary.twoStageAffix, true, true, circumfix));
			}
			else if (dictionary.complexPrefixes == false && dictionary.twoStageAffix)
			{
			  // we took away a suffix.
			  // COMPLEXPREFIXES = true: we don't recurse! only one suffix allowed
			  // COMPLEXPREFIXES = false: combine with another suffix
			  stems.AddRange(stem(strippedWord, length, affix, flag, prefixFlag, ++recursionDepth, false, true, false, circumfix));
			}
		  }
		  else if (recursionDepth == 1)
		  {
			if (prefix && dictionary.complexPrefixes)
			{
			  // we took away the second prefix: go look for another suffix
			  stems.AddRange(stem(strippedWord, length, affix, flag, flag, ++recursionDepth, false, true, true, circumfix));
			}
			else if (prefix == false && dictionary.complexPrefixes == false && dictionary.twoStageAffix)
			{
			  // we took away a prefix, then a suffix: go look for another suffix
			  stems.AddRange(stem(strippedWord, length, affix, flag, prefixFlag, ++recursionDepth, false, true, false, circumfix));
			}
		  }
		}

		return stems;
	  }