Package net.sf.jz3950.query

Examples of net.sf.jz3950.query.PrefixQuery


        super(name);
    }

    public void testType1Encoding() throws Exception
    {
        Type1Encoder.encode(new PrefixQuery("Voyager", "@attrset bib-1 @attr 1=4 \"brain\""), "utf-8");
    }
View Full Code Here


            if (localAttributeSet == null)
            {
                localAttributeSet = namespaceId;
            }

            attributePlusTermNode.setAttribute(localAttributeSet + "." + attributeType, new AttributeValue(localAttributeSet, attributeType + "." + attributeValue));
        }

        // See if we have an element name
        if (currentToken == PrefixQuery.TOKEN_ELEMENTNAME)
        {
View Full Code Here

            {
                if (relation.getBase() != null)
                {
                    if (relation.getBase().equalsIgnoreCase("src"))
                    {
                        attributePlusTermNode.setAttribute("bib-1.2", new AttributeValue("="));
                    }
                    else if (relation.getBase().equalsIgnoreCase("exact"))
                    {
                        attributePlusTermNode.setAttribute("bib-1.2", new AttributeValue("="));
                    }
                    else if (relation.getBase().equalsIgnoreCase("all"))
                    {
                        attributePlusTermNode.setAttribute("bib-1.2", new AttributeValue("="));
                    }
                    else if (relation.getBase().equalsIgnoreCase("any"))
                    {
                        attributePlusTermNode.setAttribute("bib-1.2", new AttributeValue("="));
                    }
                    else
                    {
                        attributePlusTermNode.setAttribute("bib-1.2", new AttributeValue(relation.getBase()));
                    }

                    logger.debug("Modifiers: " + relation.getModifiers());
                }
            }
View Full Code Here

                // Consume the attribute token
                currentToken = readToken(tokenizer);
            }
            else
            {
                throw new InvalidQueryException("Unexpected error processing RPN query, expected attribute type");
            }

            // Ensure that there is an equals
            if (currentToken == PrefixQuery.TOKEN_EQUALS)
            {
                // Consume it
                currentToken = readToken(tokenizer);
            }
            else
            {
                throw new InvalidQueryException("Unexpected error processing RPN query, expected =");
            }

            // Ensure there is a value
            if (currentToken == PrefixQuery.TOKEN_NUMBER)
            {
                attributeValue = java.math.BigInteger.valueOf((int) tokenizer.nval);
                // Consume It
                currentToken = readToken(tokenizer);
            }
            else if (currentToken == PrefixQuery.TOKEN_TERM)
            {
                // With the new attribute set architecture we will start to get string values... Deal here
                attributeValue = tokenizer.sval;
                // Consume It
                currentToken = readToken(tokenizer);
            }
            else
            {
                throw new InvalidQueryException("Unexpected error processing RPN query, expected str or num attribute");
            }

            if (localAttributeSet == null)
            {
                localAttributeSet = namespaceId;
            }

            attributePlusTermNode.setAttribute(localAttributeSet + "." + attributeType, new AttributeValue(localAttributeSet, attributeType + "." + attributeValue));
        }

        // See if we have an element name
        if (currentToken == PrefixQuery.TOKEN_ELEMENTNAME)
        {
            // Consume the element name token and move on to the actual element name
            currentToken = readToken(tokenizer);

            // Consume the actual element name
            currentToken = readToken(tokenizer);
        }

        // Process any terms following the attrs
        while ((currentToken == PrefixQuery.TOKEN_TERM) || (currentToken == PrefixQuery.TOKEN_NUMBER))
        {
            if (currentToken == PrefixQuery.TOKEN_TERM)
            {
                terms.add(tokenizer.sval);
            }
            else
            {
                terms.add("" + tokenizer.nval);
            }

            currentToken = readToken(tokenizer);
        }

        if (terms.size() > 1)
        {
            attributePlusTermNode.setTerm(terms);
        }
        else if (terms.size() == 1)
        {
            attributePlusTermNode.setTerm(terms.get(0));
        }
        else
        {
            throw new InvalidQueryException("No Terms");
        }

        return attributePlusTermNode;
    }
View Full Code Here

                    attributeValue = new BigInteger(result[2]);
                }
            }
            else
            {
                throw new InvalidQueryException("Unable to parse attribute triple \"" + attributeTripleStr + "\"");
            }

            return new Type1AttributeTriple(attributeSet, attributeType, attributeValue);
        }
View Full Code Here

    }

    public QueryModel toQueryModel() throws InvalidQueryException
    {
        StreamTokenizer tokenizer = createTokenizer(new StringReader(this.prefixString));
        QueryModel result = new QueryModel();
        int currentToken = readToken(tokenizer);

        if (currentToken == PrefixQuery.TOKEN_ATTRSET)
        {
            // Consume the Attrset token
            currentToken = readToken(tokenizer);

            String attributeSet = tokenizer.sval;

            // Consume the namespace value token
            currentToken = readToken(tokenizer);

            QueryModelNamespaceNode namespaceNode = new QueryModelNamespaceNode();
            result.setRoot(namespaceNode);
            namespaceNode.setAttributeSet(attributeSet);
            namespaceNode.setRoot(visitPrefixQuery(tokenizer, currentToken, attributeSet));
        }
        else
        {
            result.setRoot(visitPrefixQuery(tokenizer, currentToken, "bib-1"));
        }

        return result;
    }
View Full Code Here

        this.rootNode = rootNode;
    }

    public QueryModel toQueryModel() throws InvalidQueryException
    {
        return new QueryModel(translate(this.rootNode));
    }
View Full Code Here

        return node;
    }

    private static QueryModelAPTNode visitQueryNode(StreamTokenizer tokenizer, int currentToken, String namespaceId) throws InvalidQueryException
    {
        QueryModelAPTNode attributePlusTermNode = new QueryModelAPTNode();
        List<String> terms = new ArrayList<String>();

        while (currentToken == PrefixQuery.TOKEN_ATTR)
        {
            int attributeType = 0;
            Object attributeValue = null;
            String localAttributeSet = null;

            // Consume the @attr and see what's next
            currentToken = readToken(tokenizer);

            // See if there is an attrset, as in "@attr gils 1=2016"
            if (currentToken == PrefixQuery.TOKEN_TERM)
            {
                // It must be an attribute set identifier, since attr types are always numeric
                localAttributeSet = tokenizer.sval;
                currentToken = readToken(tokenizer);
            }

            // Process the attribute
            if (currentToken == PrefixQuery.TOKEN_NUMBER)
            {
                attributeType = (int) tokenizer.nval;
                // Consume the attribute token
                currentToken = readToken(tokenizer);
            }
            else
            {
                throw new InvalidQueryException("Unexpected error processing RPN query, expected attribute type");
            }

            // Ensure that there is an equals
            if (currentToken == PrefixQuery.TOKEN_EQUALS)
            {
                // Consume it
                currentToken = readToken(tokenizer);
            }
            else
            {
                throw new InvalidQueryException("Unexpected error processing RPN query, expected =");
            }

            // Ensure there is a value
            if (currentToken == PrefixQuery.TOKEN_NUMBER)
            {
                attributeValue = java.math.BigInteger.valueOf((int) tokenizer.nval);
                // Consume It
                currentToken = readToken(tokenizer);
            }
            else if (currentToken == PrefixQuery.TOKEN_TERM)
            {
                // With the new attribute set architecture we will start to get string values... Deal here
                attributeValue = tokenizer.sval;
                // Consume It
                currentToken = readToken(tokenizer);
            }
            else
            {
                throw new InvalidQueryException("Unexpected error processing RPN query, expected str or num attribute");
            }

            if (localAttributeSet == null)
            {
                localAttributeSet = namespaceId;
            }

            attributePlusTermNode.setAttribute(localAttributeSet + "." + attributeType, new AttributeValue(localAttributeSet, attributeType + "." + attributeValue));
        }

        // See if we have an element name
        if (currentToken == PrefixQuery.TOKEN_ELEMENTNAME)
        {
            // Consume the element name token and move on to the actual element name
            currentToken = readToken(tokenizer);

            // Consume the actual element name
            currentToken = readToken(tokenizer);
        }

        // Process any terms following the attrs
        while ((currentToken == PrefixQuery.TOKEN_TERM) || (currentToken == PrefixQuery.TOKEN_NUMBER))
        {
            if (currentToken == PrefixQuery.TOKEN_TERM)
            {
                terms.add(tokenizer.sval);
            }
            else
            {
                terms.add("" + tokenizer.nval);
            }

            currentToken = readToken(tokenizer);
        }

        if (terms.size() > 1)
        {
            attributePlusTermNode.setTerm(terms);
        }
        else if (terms.size() == 1)
        {
            attributePlusTermNode.setTerm(terms.get(0));
        }
        else
        {
            throw new InvalidQueryException("No Terms");
        }
View Full Code Here

            rpnStructure.which = RPNStructure_type.rpnrpnop_CID;
            rpnStructure.o = rpnOp;
        }
        else if (node instanceof QueryModelAPTNode)
        {
            QueryModelAPTNode aptNode = (QueryModelAPTNode) node;

            AttributesPlusTerm_type attributePlusTerm = new AttributesPlusTerm_type();
            attributePlusTerm.attributes = new ArrayList();

            for (String attributeId : aptNode.getAttributes().keySet())
            {
                Type1AttributeTriple attributeTriple = Type1AttributeTriple.parse(aptNode.getAttribute(attributeId).toString());

                AttributeElement_type attributeElement = new AttributeElement_type();
                attributeElement.attributeValue = new attributeValue_inline3_type();
                attributeElement.attributeType = BigInteger.valueOf(attributeTriple.attributeType);

                /*
                 * Use OID registry to lookup attr set oid if one is present. Don't fill out element attrset if it's the
                 * same as default attrset
                 */
                String elementAttributeSet = attributeTriple.attributeSet;

                if ((null != elementAttributeSet) && (!elementAttributeSet.equals(defaultNamespace)))
                {
                    attributeElement.attributeSet = ProtocolOIDRegister.getInstance().oidByName(elementAttributeSet);
                }

                if (attributeTriple.attributeValue instanceof BigInteger)
                {
                    attributeElement.attributeValue.which = attributeValue_inline3_type.numeric_CID;
                    attributeElement.attributeValue.o = BigInteger.valueOf(((BigInteger) attributeTriple.attributeValue).intValue());
                }
                else if (attributeTriple.attributeValue instanceof String)
                {
                    StringOrNumeric_type son = new StringOrNumeric_type();
                    son.which = StringOrNumeric_type.string_CID;
                    son.o = attributeTriple.attributeValue.toString();

                    complex_inline4_type cit = new complex_inline4_type();
                    cit.list = new ArrayList();
                    cit.list.add(son);

                    attributeElement.attributeValue.which = attributeValue_inline3_type.complex_CID;
                    attributeElement.attributeValue.o = cit;
                }
                else
                {
                    logger.warn("Unhandled type (" + attributeTriple.attributeValue.getClass().getName() + ") for attribute value");
                }

                attributePlusTerm.attributes.add(attributeElement);
            }

            try
            {
                /*
                 * Add new AttributeElement members for each attribute.
                 */
                attributePlusTerm.term = new Term_type();
                attributePlusTerm.term.which = Term_type.general_CID;
                attributePlusTerm.term.o = aptNode.getTerm().toString().getBytes(encoding);
            }
            catch (java.io.UnsupportedEncodingException e)
            {
                logger.warn("Problem converting search string to requested encoding", e);
                attributePlusTerm.term.o = aptNode.getTerm().toString().getBytes();
            }

            Operand_type operand = new Operand_type();
            operand.which = Operand_type.attrterm_CID;
            operand.o = attributePlusTerm;
View Full Code Here

        else if (node instanceof CQLTermNode)
        {
            logger.warn("FIXME: CQLTermNode will not be translated properly");

            CQLTermNode cqlTermNode = (CQLTermNode) node;
            QueryModelAPTNode attributePlusTermNode = new QueryModelAPTNode();
            attributePlusTermNode.setTerm(cqlTermNode.getTerm());

            if ((cqlTermNode.getQualifier() != null) && (cqlTermNode.getQualifier().length() > 0))
            {
                logger.debug("Using supplied qualifier: " + cqlTermNode.getQualifier());
                attributePlusTermNode.setAttribute("bib-1.1", cqlTermNode.getQualifier());
            }
            else
            {
                logger.debug("Using default qualifier: " + DEFAULT_QUALIFIER);
                attributePlusTermNode.setAttribute("bib-1.1", DEFAULT_QUALIFIER);
            }

            CQLRelation relation = cqlTermNode.getRelation();

            if (relation != null)
            {
                if (relation.getBase() != null)
                {
                    if (relation.getBase().equalsIgnoreCase("src"))
                    {
                        attributePlusTermNode.setAttribute("bib-1.2", new AttributeValue("="));
                    }
                    else if (relation.getBase().equalsIgnoreCase("exact"))
                    {
                        attributePlusTermNode.setAttribute("bib-1.2", new AttributeValue("="));
                    }
                    else if (relation.getBase().equalsIgnoreCase("all"))
                    {
                        attributePlusTermNode.setAttribute("bib-1.2", new AttributeValue("="));
                    }
                    else if (relation.getBase().equalsIgnoreCase("any"))
                    {
                        attributePlusTermNode.setAttribute("bib-1.2", new AttributeValue("="));
                    }
                    else
                    {
                        attributePlusTermNode.setAttribute("bib-1.2", new AttributeValue(relation.getBase()));
                    }

                    logger.debug("Modifiers: " + relation.getModifiers());
                }
            }
View Full Code Here

TOP

Related Classes of net.sf.jz3950.query.PrefixQuery

Copyright © 2018 www.massapicom. 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.