
io.mindmaps.graql.Graql Maven / Gradle / Ivy
/*
* MindmapsDB - A Distributed Semantic Database
* Copyright (C) 2016 Mindmaps Research Ltd
*
* MindmapsDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MindmapsDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MindmapsDB. If not, see .
*
*/
package io.mindmaps.graql;
import com.google.common.collect.ImmutableSet;
import io.mindmaps.MindmapsGraph;
import io.mindmaps.concept.Concept;
import io.mindmaps.graql.admin.Conjunction;
import io.mindmaps.graql.admin.Disjunction;
import io.mindmaps.graql.admin.PatternAdmin;
import io.mindmaps.graql.internal.pattern.Patterns;
import io.mindmaps.graql.internal.query.aggregate.Aggregates;
import io.mindmaps.graql.internal.query.predicate.Predicates;
import io.mindmaps.graql.internal.util.AdminConverter;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Stream;
public class Graql {
private Graql() {}
// QUERY BUILDING
/**
* @return a query builder without a specified graph
*/
public static QueryBuilder withoutGraph() {
return new QueryBuilder();
}
/**
* @param graph the graph to operate the query on
* @return a query builder using the specified graph
*/
public static QueryBuilder withGraph(MindmapsGraph graph) {
return new QueryBuilder(graph);
}
/**
* @param patterns an array of patterns to match in the graph
* @return a match query that will find matches of the given patterns
*/
public static MatchQuery match(Pattern... patterns) {
return withoutGraph().match(patterns);
}
/**
* @param patterns a collection of patterns to match in the graph
* @return a match query that will find matches of the given patterns
*/
public static MatchQuery match(Collection extends Pattern> patterns) {
return withoutGraph().match(patterns);
}
/**
* @param vars an array of variables to insert into the graph
* @return an insert query that will insert the given variables into the graph
*/
public static InsertQuery insert(Var... vars) {
return withoutGraph().insert(vars);
}
/**
* @param vars a collection of variables to insert into the graph
* @return an insert query that will insert the given variables into the graph
*/
public static InsertQuery insert(Collection extends Var> vars) {
return withoutGraph().insert(vars);
}
/**
* @param queryString a string representing a match query
* @return the parsed match query
*/
public static MatchQuery parseMatch(String queryString) {
return withoutGraph().parseMatch(queryString);
}
/**
* @param queryString a string representing an ask query
* @return a parsed ask query
*/
public static AskQuery parseAsk(String queryString) {
return withoutGraph().parseAsk(queryString);
}
/**
* @param queryString a string representing an insert query
* @return a parsed insert query
*/
public static InsertQuery parseInsert(String queryString) {
return withoutGraph().parseInsert(queryString);
}
/**
* @param queryString a string representing a delete query
* @return a parsed delete query
*/
public static DeleteQuery parseDelete(String queryString) {
return withoutGraph().parseDelete(queryString);
}
/**
* @param queryString a string representing an aggregate query
* @return a parsed aggregate query
*/
public static AggregateQuery> parseAggregate(String queryString) {
return withoutGraph().parseAggregate(queryString);
}
/**
* @param queryString a string representing a delete query
* @return a parsed compute query
*/
public static ComputeQuery parseCompute(String queryString) {
return withoutGraph().parseCompute(queryString);
}
/**
* @param inputStream a stream representing a list of patterns
* @return a stream of patterns
*/
public static Stream parsePatterns(InputStream inputStream) {
return withoutGraph().parsePatterns(inputStream);
}
/**
* @param queryString a string representing a query
* @return a query, the type will depend on the type of query.
*/
public static Query> parse(String queryString) {
return withoutGraph().parse(queryString);
}
// TEMPLATING
/**
* @param template a string representing a templated graql query
* @param data data to use in template
* @return a resolved graql query
*/
public static String parseTemplate(String template, Map data){
return withoutGraph().parseTemplate(template, data);
}
// PATTERNS AND VARS
/**
* @param name the name of the variable
* @return a new query variable
*/
public static Var var(String name) {
return Patterns.var(Objects.requireNonNull(name));
}
/**
* @return a new, anonymous query variable
*/
public static Var var() {
return Patterns.var();
}
/**
* @param id the id of a concept
* @return a query variable that identifies a concept by id
*/
public static Var id(String id) {
return var().id(id);
}
/**
* @param patterns an array of patterns to match
* @return a pattern that will match only when all contained patterns match
*/
public static Pattern and(Pattern... patterns) {
return and(Arrays.asList(patterns));
}
/**
* @param patterns a collection of patterns to match
* @return a pattern that will match only when all contained patterns match
*/
public static Pattern and(Collection extends Pattern> patterns) {
Conjunction conjunction = Patterns.conjunction(AdminConverter.getPatternAdmins(patterns));
return () -> conjunction;
}
/**
* @param patterns an array of patterns to match
* @return a pattern that will match when any contained pattern matches
*/
public static Pattern or(Pattern... patterns) {
return or(Arrays.asList(patterns));
}
/**
* @param patterns a collection of patterns to match
* @return a pattern that will match when any contained pattern matches
*/
public static Pattern or(Collection extends Pattern> patterns) {
Disjunction disjunction = Patterns.disjunction(AdminConverter.getPatternAdmins(patterns));
return () -> disjunction;
}
// AGGREGATES
/**
* Create an aggregate that will count the results of a query.
*/
public static Aggregate
© 2015 - 2025 Weber Informatics LLC | Privacy Policy