⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serqlparser.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 **/        protected URI _parseQName(String uri)                throws ParseException        {                // QNames have the form PREFIX:LNAME, substitute the PREFIX                // with an actual namespace.                int colonIdx = uri.indexOf(":");                String prefix = uri.substring(0, colonIdx);                String localName = uri.substring(colonIdx + 1);                String namespace = _getNamespace(prefix);                if (namespace == null) {                        throw new ParseException("Prefix \"" + prefix + "\" not defined.");                }                return new URIImpl(namespace + localName);        }        /**	 * Parses a string representing a blank node URI (i.e. <tt>_:node1</tt>) and	 * creates a BNode object for it.	 **/        protected BNode _parseBNode(String bnode)                throws ParseException        {                return new BNodeImpl( bnode.substring(2) );        }        /**	 * Parses a new Literal from the supplied String.	 **/        protected Literal _parseLiteral(String literal)                throws ParseException        {                // Find string separation points                int endLabelIdx = _findEndOfLabel(literal);                int startLangIdx = literal.indexOf("@", endLabelIdx);                int startDtIdx = literal.indexOf("^^", Math.max(endLabelIdx, startLangIdx));                // Get label                String label = literal.substring(1, endLabelIdx);                label = NTriplesUtil.unescapeString(label);                if (startLangIdx != -1) {                        // Get language                        String language = literal.substring(startLangIdx + 1);                        return new LiteralImpl(label, language);                }                else if (startDtIdx != -1) {                        // Get datatype                        String dtString = literal.substring(startDtIdx + 2);                        URI datatype = _parseURI(dtString);                        // Normalize label when datatype is XML Schema built-in                        if (XmlDatatypeUtil.isBuiltInDatatype(datatype.getURI())) {                                try {                                        label = XmlDatatypeUtil.normalize(label, datatype.getURI());                                }                                catch (IllegalArgumentException e) {                                        throw new ParseException(e.getMessage());                                }                        }                        return new LiteralImpl(label, datatype);                }                else {                        return new LiteralImpl(label);                }        }        /**	 * Finds the end of the label in a literal string. This method	 * takes into account that characters can be escaped using	 * backslashes.	 *	 * @return The index of the double quote ending the label.	 **/        private int _findEndOfLabel(String literal)                throws ParseException        {                // First character of literal is guaranteed to be a double                // quote, start search at second character.                boolean previousWasBackslash = false;                for (int i = 1; i < literal.length(); i++) {                        char c = literal.charAt(i);                        if (c == '"' && !previousWasBackslash) {                                return i;                        }                        else if (c == '\\' && !previousWasBackslash) {                                // start of escape                                previousWasBackslash = true;                        }                        else if (previousWasBackslash) {                                // c was escaped                                previousWasBackslash = false;                        }                }                throw new ParseException("Could not find end of literal label");        }        /**	 * Creates a new ParseException with the supplied current and	 * expected tokens. See ParseException for details.	 **/        protected ParseException _createParseException(                Token currentTokenVal, String[] tokenImage)        {                // Append "<EOF>" in front of the supplied String array.                // ParseException.getMessage expects "<EOF>" as the first String                // in the String array.                int length = tokenImage.length;                // New String array has one element extra, therefore length of                // new String array is increased by one.                String[] newTokenImage = new String[length + 1];                // First element is "<EOF>"                newTokenImage[0] = "<EOF>";                // Copy Strings of the supplied String array to the new String array.                for (int i = 0; i < length; i++) {                        newTokenImage[i +1] = tokenImage[i];                }                int[][] expectedTokenSequences = new int[1][length];                for (int i = 0; i < length; i++) {                        expectedTokenSequences [0][i] = i +1;                }                return new ParseException(currentTokenVal, expectedTokenSequences, newTokenImage);        }  final public TableQuery parseTableQuery() throws ParseException {        Query qc;    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case USING:      namespace_list();      break;    default:      jj_la1[0] = jj_gen;      ;    }    qc = table_query_set();    jj_consume_token(0);                        // Check for unbound variables.                        _checkUnboundVars();                        // Check the variable scope tree for shared variables                        // in children that are not present in the parent.                        _checkVariableScoping();                        {if (true) return new TableQuery(qc);}    throw new Error("Missing return statement in function");  }  final public Query table_query_set() throws ParseException {        Query result = null;        Query rightArg = null;        boolean all = false;    result = table_query();    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case UNION:    case MINUS:    case INTERSECT:      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case UNION:        jj_consume_token(UNION);        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {        case ALL:          jj_consume_token(ALL);                                  all = true;          break;        default:          jj_la1[1] = jj_gen;          ;        }        rightArg = table_query_set();                                result = new Union(result, rightArg, all);        break;      case MINUS:        jj_consume_token(MINUS);        rightArg = table_query_set();                                result = new Minus(result, rightArg, all);        break;      case INTERSECT:        jj_consume_token(INTERSECT);        rightArg = table_query_set();                                result = new Intersect(result, rightArg, all);        break;      default:        jj_la1[2] = jj_gen;        jj_consume_token(-1);        throw new ParseException();      }      break;    default:      jj_la1[3] = jj_gen;      ;    }                        {if (true) return result;}    throw new Error("Missing return statement in function");  }  final public Query table_query() throws ParseException {        Query qc;    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case LPAREN:      jj_consume_token(LPAREN);      qc = table_query_set();      jj_consume_token(RPAREN);                                                   {if (true) return qc;}      break;    case SELECT:      qc = select_query();                              {if (true) return qc;}      break;    default:      jj_la1[4] = jj_gen;      jj_consume_token(-1);      throw new ParseException();    }    throw new Error("Missing return statement in function");  }  final public GraphQuery parseGraphQuery() throws ParseException {        Query qc;    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case USING:      namespace_list();      break;    default:      jj_la1[5] = jj_gen;      ;    }    qc = graph_query_set();    jj_consume_token(0);                        // Check for unbound variables.                        _checkUnboundVars();                        // Check the variable scope tree for shared variables                        // in children that are not present in the parent.                        _checkVariableScoping();                        {if (true) return new GraphQuery(qc, new HashMap(_namespaces));}    throw new Error("Missing return statement in function");  }  final public Query graph_query_set() throws ParseException {        Query result = null;        Query rightArg = null;        boolean all = false;    result = graph_query();    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case UNION:    case MINUS:    case INTERSECT:      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case UNION:        jj_consume_token(UNION);        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {        case ALL:          jj_consume_token(ALL);                                  all = true;          break;        default:          jj_la1[6] = jj_gen;          ;        }        rightArg = graph_query_set();                                result = new Union(result, rightArg, all);        break;      case MINUS:        jj_consume_token(MINUS);        rightArg = graph_query_set();                                result = new Minus(result, rightArg, all);        break;      case INTERSECT:        jj_consume_token(INTERSECT);        rightArg = graph_query_set();                                result = new Intersect(result, rightArg, all);        break;      default:        jj_la1[7] = jj_gen;        jj_consume_token(-1);        throw new ParseException();      }      break;    default:      jj_la1[8] = jj_gen;      ;    }                        {if (true) return result;}    throw new Error("Missing return statement in function");  }  final public Query graph_query() throws ParseException {        Query qc;    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case LPAREN:      jj_consume_token(LPAREN);      qc = graph_query_set();      jj_consume_token(RPAREN);                                                   {if (true) return qc;}      break;    case CONSTRUCT:      qc = construct_query();                                 {if (true) return qc;}      break;    default:      jj_la1[9] = jj_gen;      jj_consume_token(-1);      throw new ParseException();    }    throw new Error("Missing return statement in function");  }/*-------------------------------+| NAMESPACE DECLARATIONS         |+-------------------------------*/  final public void namespace_list() throws ParseException {    jj_consume_token(USING);    jj_consume_token(NAMESPACE);    namespace();    label_1:    while (true) {      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {      case COMMA:        ;        break;      default:        jj_la1[10] = jj_gen;        break label_1;      }      jj_consume_token(COMMA);      namespace();    }  }  final public void namespace() throws ParseException {        Token prefixToken;        ResourceExpr uri;    prefixToken = jj_consume_token(PREFIX_NAME);    jj_consume_token(EQ);    uri = full_uri();                        String prefix = prefixToken.image;                        _setNamespacePrefix(prefix, uri.getString());  }  final public Query select_query() throws ParseException {        boolean distinct = false;        List projection;        GraphPattern graphPattern = new GraphPattern();        boolean hasLimit = false, hasOffset = false;        int limit = -1, offset = -1;    jj_consume_token(SELECT);    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case DISTINCT:      jj_consume_token(DISTINCT);                       distinct = true;      break;    default:      jj_la1[11] = jj_gen;      ;    }    projection = projection();    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case FROM:      jj_consume_token(FROM);      graph_pattern(graphPattern);      break;    default:      jj_la1[12] = jj_gen;      ;    }    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case LIMIT:      jj_consume_token(LIMIT);      limit = pos_integer();                                          hasLimit = true;      break;    default:      jj_la1[13] = jj_gen;      ;    }    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {    case OFFSET:      jj_consume_token(OFFSET);      offset = pos_integer();                                            hasOffset = true;      break;    default:      jj_la1[14] = jj_gen;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -