
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.graql.internal.util.AdminConverter;
import io.mindmaps.concept.Concept;
import io.mindmaps.graql.admin.PatternAdmin;
import io.mindmaps.graql.admin.Conjunction;
import io.mindmaps.graql.admin.Disjunction;
import io.mindmaps.graql.internal.query.Patterns;
import io.mindmaps.graql.internal.query.aggregate.Aggregates;
import io.mindmaps.graql.internal.query.predicate.*;
import java.util.*;
public class 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);
}
// 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