index
int64
repo_id
string
file_path
string
content
string
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/client/GraknClient.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.client; import ai.grakn.Keyspace; import ai.grakn.graql.Query; import ai.grakn.util.SimpleURI; import java.util.List; import java.util.Optional; /** * Grakn http client. Extend this for more http endpoint. * * @author Domenico Corapi */ public interface GraknClient { int CONNECT_TIMEOUT_MS = 30 * 1000; int DEFAULT_MAX_RETRY = 3; static GraknClient of(SimpleURI url) { return new GraknClientImpl(url); } List<QueryResponse> graqlExecute(List<Query<?>> queryList, Keyspace keyspace) throws GraknClientException; Optional<Keyspace> keyspace(String keyspace) throws GraknClientException; }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/client/GraknClientException.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.client; import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.Response.StatusType; /** * Exceptions generated by the client * * @author Domenico Corapi */ public class GraknClientException extends Exception { private final boolean retriable; public GraknClientException(String s) { this(s, false); } public GraknClientException(String s, boolean retriable) { super(s); this.retriable = retriable; } public GraknClientException(String s, StatusType statusInfo) { this(s, statusInfo.getFamily().equals(Family.SERVER_ERROR)); } public boolean isRetriable() { return retriable; } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/client/GraknClientImpl.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.client; import ai.grakn.GraknTxType; import ai.grakn.Keyspace; import ai.grakn.graql.Query; import ai.grakn.util.REST; import ai.grakn.util.SimpleURI; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import mjson.Json; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.UriBuilder; import java.net.URI; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import static ai.grakn.util.REST.Request.Graql.ALLOW_MULTIPLE_QUERIES; import static ai.grakn.util.REST.Request.Graql.EXECUTE_WITH_INFERENCE; import static ai.grakn.util.REST.Request.Graql.LOADING_DATA; import static ai.grakn.util.REST.Request.Graql.TX_TYPE; import static ai.grakn.util.REST.Response.ContentType.APPLICATION_JSON; /** * Default implementation of {@link GraknClient}. * * @author Domenico Corapi */ public class GraknClientImpl implements GraknClient { private final Logger LOG = LoggerFactory.getLogger(GraknClientImpl.class); private final Client client; private final SimpleURI uri; GraknClientImpl(SimpleURI url) { this.client = Client.create(); this.client.setConnectTimeout(CONNECT_TIMEOUT_MS); this.client.setReadTimeout(CONNECT_TIMEOUT_MS * 2); this.uri = url; } @Override public List<QueryResponse> graqlExecute(List<Query<?>> queryList, Keyspace keyspace) throws GraknClientException { LOG.debug("Sending query list size {} to keyspace {}", queryList.size(), keyspace); String body = queryList.stream().map(Object::toString).reduce("; ", String::concat).substring(2); URI fullURI = UriBuilder.fromUri(uri.toURI()) .path(REST.resolveTemplate(REST.WebPath.KEYSPACE_GRAQL, keyspace.getValue())) .queryParam(ALLOW_MULTIPLE_QUERIES, true) .queryParam(EXECUTE_WITH_INFERENCE, false) //Making inference true could lead to non-deterministic loading of data .queryParam(LOADING_DATA, true) //Skip serialising responses for the sake of efficiency .queryParam(TX_TYPE, GraknTxType.BATCH) .build(); ClientResponse response = client.resource(fullURI) .accept(APPLICATION_JSON) .post(ClientResponse.class, body); try { Response.StatusType status = response.getStatusInfo(); String entity = response.getEntity(String.class); if (!status.getFamily().equals(Family.SUCCESSFUL)) { String queries = queryList.stream().map(Object::toString).collect(Collectors.joining("\n")); String error = Json.read(entity).at("exception").asString(); throw new GraknClientException("Failed graqlExecute. Error status: " + status.getStatusCode() + ", error info: " + error + "\nqueries: " + queries, response.getStatusInfo()); } LOG.debug("Received {}", status.getStatusCode()); return queryList.stream().map(q -> QueryResponse.INSTANCE).collect(Collectors.toList()); } finally { response.close(); } } @Override public Optional<Keyspace> keyspace(String keyspace) throws GraknClientException { URI fullURI = UriBuilder.fromUri(uri.toURI()) .path(REST.resolveTemplate(REST.WebPath.KB_KEYSPACE, keyspace)) .build(); ClientResponse response = client.resource(fullURI) .accept(APPLICATION_JSON) .get(ClientResponse.class); Response.StatusType status = response.getStatusInfo(); LOG.debug("Received {}", status.getStatusCode()); if (status.getStatusCode() == Status.NOT_FOUND.getStatusCode()) { return Optional.empty(); } String entity = response.getEntity(String.class); if (!status.getFamily().equals(Family.SUCCESSFUL)) { throw new GraknClientException("Failed keyspace. Error status: " + status.getStatusCode() + ", error info: " + entity, response.getStatusInfo()); } response.close(); return Optional.of(Keyspace.of(keyspace)); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/client/QueryResponse.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.client; /** * <p> * Simple class to encapsulate a query response. * This is required by the {@link com.netflix.hystrix.Hystrix} framework we use in {@link BatchExecutorClient} * </p> * * @author Filipe Peliz Pinto Teixeira */ public class QueryResponse { public static final QueryResponse INSTANCE = new QueryResponse(); private QueryResponse(){} }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/client/package-info.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ /** * The loader client - use this Java API to access the REST endpoint. */ package ai.grakn.client;
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/RemoteComputeJob.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote; import ai.grakn.ComputeJob; /** * Represents a compute query executing on a gRPC server. * * @author Felix Chapman * * @param <T> The returned result of the compute job */ final class RemoteComputeJob<T> implements ComputeJob<T> { private final T result; private RemoteComputeJob(T result) { this.result = result; } public static <T> RemoteComputeJob<T> of(T result) { return new RemoteComputeJob<>(result); } @Override public T get() { return result; } @Override public void kill() { throw new UnsupportedOperationException(); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/RemoteGrakn.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote; import ai.grakn.GraknSession; import ai.grakn.Keyspace; import ai.grakn.util.SimpleURI; /** * Entry-point and remote equivalent of {@link ai.grakn.Grakn}. Communicates with a running Grakn server using gRPC. * * <p> * In the future, this will likely become the default entry-point over {@link ai.grakn.Grakn}. For now, only a * subset of {@link GraknSession} and {@link ai.grakn.GraknTx} features are supported. * </p> * * @author Felix Chapman */ public final class RemoteGrakn { private RemoteGrakn() {} public static GraknSession session(SimpleURI uri, Keyspace keyspace) { return RemoteGraknSession.create(keyspace, uri); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/RemoteGraknSession.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote; import ai.grakn.GraknSession; import ai.grakn.GraknTxType; import ai.grakn.Keyspace; import ai.grakn.exception.GraknTxOperationException; import ai.grakn.grpc.GrpcUtil; import ai.grakn.rpc.generated.GraknGrpc; import ai.grakn.rpc.generated.GraknGrpc.GraknBlockingStub; import ai.grakn.rpc.generated.GraknGrpc.GraknStub; import ai.grakn.util.SimpleURI; import com.google.common.annotations.VisibleForTesting; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; /** * Remote implementation of {@link GraknSession} that communicates with a Grakn server using gRPC. * * @see RemoteGraknTx * @see RemoteGrakn * * @author Felix Chapman */ public class RemoteGraknSession implements GraknSession { private final Keyspace keyspace; private final SimpleURI uri; private final ManagedChannel channel; protected RemoteGraknSession(Keyspace keyspace, SimpleURI uri, ManagedChannel channel) { this.keyspace = keyspace; this.uri = uri; this.channel = channel; } @VisibleForTesting public static RemoteGraknSession create(Keyspace keyspace, SimpleURI uri, ManagedChannel channel) { return new RemoteGraknSession(keyspace, uri, channel); } public static RemoteGraknSession create(Keyspace keyspace, SimpleURI uri){ ManagedChannel channel = ManagedChannelBuilder.forAddress(uri.getHost(), uri.getPort()).usePlaintext(true).build(); return create(keyspace, uri, channel); } GraknStub stub() { return GraknGrpc.newStub(channel); } GraknBlockingStub blockingStub() { return GraknGrpc.newBlockingStub(channel); } @Override public RemoteGraknTx open(GraknTxType transactionType) { return RemoteGraknTx.create(this, GrpcUtil.openRequest(keyspace, transactionType)); } @Override public void close() throws GraknTxOperationException { channel.shutdown(); } @Override public String uri() { return uri.toString(); } @Override public Keyspace keyspace() { return keyspace; } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/RemoteGraknTx.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote; import ai.grakn.GraknSession; import ai.grakn.GraknTx; import ai.grakn.GraknTxType; import ai.grakn.QueryRunner; import ai.grakn.concept.Attribute; import ai.grakn.concept.AttributeType; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.concept.EntityType; import ai.grakn.concept.Label; import ai.grakn.concept.RelationshipType; import ai.grakn.concept.Role; import ai.grakn.concept.Rule; import ai.grakn.concept.SchemaConcept; import ai.grakn.concept.Type; import ai.grakn.exception.InvalidKBException; import ai.grakn.graql.Pattern; import ai.grakn.graql.QueryBuilder; import ai.grakn.graql.internal.query.QueryBuilderImpl; import ai.grakn.grpc.ConceptMethods; import ai.grakn.grpc.GrpcClient; import ai.grakn.grpc.GrpcUtil; import ai.grakn.kb.admin.GraknAdmin; import ai.grakn.remote.concept.RemoteConcepts; import ai.grakn.rpc.generated.GraknGrpc.GraknStub; import ai.grakn.rpc.generated.GrpcConcept; import ai.grakn.rpc.generated.GrpcGrakn.DeleteRequest; import ai.grakn.rpc.generated.GrpcGrakn.TxRequest; import javax.annotation.Nullable; import java.util.Collection; import java.util.Objects; import java.util.stream.Stream; import static ai.grakn.util.CommonUtil.toImmutableSet; /** * Remote implementation of {@link GraknTx} and {@link GraknAdmin} that communicates with a Grakn server using gRPC. * * <p> * Most of the gRPC legwork is handled in the embedded {@link GrpcClient}. This class is an adapter to that, * translating Java calls into gRPC messages. * </p> * * @author Felix Chapman */ public final class RemoteGraknTx implements GraknTx, GraknAdmin { private final RemoteGraknSession session; private final GraknTxType txType; private final GrpcClient client; private RemoteGraknTx(RemoteGraknSession session, GraknTxType txType, TxRequest openRequest, GraknStub stub) { this.session = session; this.txType = txType; this.client = GrpcClient.create(this::convert, stub); client.open(openRequest); } // TODO: ideally the transaction should not hold a reference to the session or at least depend on a session interface public static RemoteGraknTx create(RemoteGraknSession session, TxRequest openRequest) { GraknStub stub = session.stub(); return new RemoteGraknTx(session, GrpcUtil.convert(openRequest.getOpen().getTxType()), openRequest, stub); } public GrpcClient client() { return client; } @Override public EntityType putEntityType(Label label) { return client().putEntityType(label).asEntityType(); } @Override public <V> AttributeType<V> putAttributeType(Label label, AttributeType.DataType<V> dataType) { return client().putAttributeType(label, dataType).asAttributeType(); } @Override public Rule putRule(Label label, Pattern when, Pattern then) { return client().putRule(label, when, then).asRule(); } @Override public RelationshipType putRelationshipType(Label label) { return client().putRelationshipType(label).asRelationshipType(); } @Override public Role putRole(Label label) { return client().putRole(label).asRole(); } @Nullable @Override public <T extends Concept> T getConcept(ConceptId id) { return (T) client().getConcept(id).orElse(null); } @Nullable @Override public <T extends SchemaConcept> T getSchemaConcept(Label label) { return (T) client().getSchemaConcept(label).orElse(null); } @Nullable @Override public <T extends Type> T getType(Label label) { return getSchemaConcept(label); } @Override public <V> Collection<Attribute<V>> getAttributesByValue(V value) { return client().getAttributesByValue(value).map(Concept::<V>asAttribute).collect(toImmutableSet()); } @Nullable @Override public EntityType getEntityType(String label) { return getSchemaConcept(Label.of(label)); } @Nullable @Override public RelationshipType getRelationshipType(String label) { return getSchemaConcept(Label.of(label)); } @Nullable @Override public <V> AttributeType<V> getAttributeType(String label) { return getSchemaConcept(Label.of(label)); } @Nullable @Override public Role getRole(String label) { return getSchemaConcept(Label.of(label)); } @Nullable @Override public Rule getRule(String label) { return getSchemaConcept(Label.of(label)); } @Override public GraknAdmin admin() { return this; } @Override public GraknTxType txType() { return txType; } @Override public GraknSession session() { return session; } @Override public boolean isClosed() { return client.isClosed(); } @Override public QueryBuilder graql() { return new QueryBuilderImpl(this); } @Override public void close() { client.close(); } @Override public void commit() throws InvalidKBException { client.commit(); close(); } @Override public Stream<SchemaConcept> sups(SchemaConcept schemaConcept) { Stream<? extends Concept> sups = client.runConceptMethod(schemaConcept.getId(), ConceptMethods.GET_SUPER_CONCEPTS); return Objects.requireNonNull(sups).map(Concept::asSchemaConcept); } @Override public void delete() { DeleteRequest request = GrpcUtil.deleteRequest(GrpcUtil.openRequest(keyspace(), GraknTxType.WRITE).getOpen()); session.blockingStub().delete(request); close(); } @Override public QueryRunner queryRunner() { return RemoteQueryRunner.create(client); } private Concept convert(GrpcConcept.Concept concept) { ConceptId id = ConceptId.of(concept.getId().getValue()); switch (concept.getBaseType()) { case Entity: return RemoteConcepts.createEntity(this, id); case Relationship: return RemoteConcepts.createRelationship(this, id); case Attribute: return RemoteConcepts.createAttribute(this, id); case EntityType: return RemoteConcepts.createEntityType(this, id); case RelationshipType: return RemoteConcepts.createRelationshipType(this, id); case AttributeType: return RemoteConcepts.createAttributeType(this, id); case Role: return RemoteConcepts.createRole(this, id); case Rule: return RemoteConcepts.createRule(this, id); case MetaType: return RemoteConcepts.createMetaType(this, id); default: case UNRECOGNIZED: throw new IllegalArgumentException("Unrecognised " + concept); } } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/RemoteQueryRunner.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote; import ai.grakn.ComputeJob; import ai.grakn.QueryRunner; import ai.grakn.concept.Concept; import ai.grakn.graql.AggregateQuery; import ai.grakn.graql.ComputeQuery; import ai.grakn.graql.DefineQuery; import ai.grakn.graql.DeleteQuery; import ai.grakn.graql.GetQuery; import ai.grakn.graql.InsertQuery; import ai.grakn.graql.Query; import ai.grakn.graql.UndefineQuery; import ai.grakn.graql.admin.Answer; import ai.grakn.graql.analytics.ConnectedComponentQuery; import ai.grakn.graql.analytics.CorenessQuery; import ai.grakn.graql.analytics.CountQuery; import ai.grakn.graql.analytics.DegreeQuery; import ai.grakn.graql.analytics.KCoreQuery; import ai.grakn.graql.analytics.MaxQuery; import ai.grakn.graql.analytics.MeanQuery; import ai.grakn.graql.analytics.MedianQuery; import ai.grakn.graql.analytics.MinQuery; import ai.grakn.graql.analytics.PathQuery; import ai.grakn.graql.analytics.PathsQuery; import ai.grakn.graql.analytics.StdQuery; import ai.grakn.graql.analytics.SumQuery; import ai.grakn.grpc.GrpcClient; import com.google.common.collect.Iterators; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Stream; import java.util.stream.StreamSupport; /** * Remote implementation of {@link QueryRunner} that communicates with a Grakn server using gRPC. * * <p> * Like {@link RemoteGraknTx}, this class is an adapter that uses the {@link GrpcClient} for gRPC calls. * </p> * * @author Felix Chapman */ final class RemoteQueryRunner implements QueryRunner { private final GrpcClient client; private RemoteQueryRunner(GrpcClient client) { this.client = client; } public static RemoteQueryRunner create(GrpcClient client) { return new RemoteQueryRunner(client); } @Override public Stream<Answer> run(GetQuery query) { return runAnswerStream(query); } @Override public Stream<Answer> run(InsertQuery query) { return runAnswerStream(query); } @Override public void run(DeleteQuery query) { runVoid(query); } @Override public Answer run(DefineQuery query) { return runSingle(query, Answer.class); } @Override public void run(UndefineQuery query) { runVoid(query); } @Override public <T> T run(AggregateQuery<T> query) { return runSingleUnchecked(query); } @Override public <T> ComputeJob<T> run(ConnectedComponentQuery<T> query) { return runComputeUnchecked(query); } @Override public ComputeJob<Map<Long, Set<String>>> run(CorenessQuery query) { return runComputeUnchecked(query); } @Override public ComputeJob<Long> run(CountQuery query) { return runCompute(query, Long.class); } @Override public ComputeJob<Map<Long, Set<String>>> run(DegreeQuery query) { return runComputeUnchecked(query); } @Override public ComputeJob<Map<String, Set<String>>> run(KCoreQuery query) { return runComputeUnchecked(query); } @Override public ComputeJob<Optional<Number>> run(MaxQuery query) { return runComputeUnchecked(query); } @Override public ComputeJob<Optional<Double>> run(MeanQuery query) { return runComputeUnchecked(query); } @Override public ComputeJob<Optional<Number>> run(MedianQuery query) { return runComputeUnchecked(query); } @Override public ComputeJob<Optional<Number>> run(MinQuery query) { return runComputeUnchecked(query); } @Override public ComputeJob<Optional<List<Concept>>> run(PathQuery query) { return runComputeUnchecked(query); } @Override public ComputeJob<List<List<Concept>>> run(PathsQuery query) { return runComputeUnchecked(query); } @Override public ComputeJob<Optional<Double>> run(StdQuery query) { return runComputeUnchecked(query); } @Override public ComputeJob<Optional<Number>> run(SumQuery query) { return runComputeUnchecked(query); } private Iterator<Object> run(Query<?> query) { return client.execQuery(query); } private void runVoid(Query<?> query) { run(query).forEachRemaining(empty -> {}); } private Stream<Answer> runAnswerStream(Query<?> query) { Iterable<Object> iterable = () -> run(query); Stream<Object> stream = StreamSupport.stream(iterable.spliterator(), false); return stream.map(Answer.class::cast); } private <T> ComputeJob<T> runCompute(ComputeQuery<? extends T> query, Class<? extends T> clazz) { return RemoteComputeJob.of(runSingle(query, clazz)); } private <T> ComputeJob<T> runComputeUnchecked(ComputeQuery<? extends T> query) { return RemoteComputeJob.of(runSingleUnchecked(query)); } private <T> T runSingle(Query<? extends T> query, Class<? extends T> clazz) { return clazz.cast(Iterators.getOnlyElement(run(query))); } private <T> T runSingleUnchecked(Query<? extends T> query) { return (T) Iterators.getOnlyElement(run(query)); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/AutoValue_RemoteAttribute.java
package ai.grakn.remote.concept; import ai.grakn.concept.ConceptId; import ai.grakn.remote.RemoteGraknTx; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_RemoteAttribute<D> extends RemoteAttribute<D> { private final RemoteGraknTx tx; private final ConceptId getId; AutoValue_RemoteAttribute( RemoteGraknTx tx, ConceptId getId) { if (tx == null) { throw new NullPointerException("Null tx"); } this.tx = tx; if (getId == null) { throw new NullPointerException("Null getId"); } this.getId = getId; } @Override RemoteGraknTx tx() { return tx; } @Override public ConceptId getId() { return getId; } @Override public String toString() { return "RemoteAttribute{" + "tx=" + tx + ", " + "getId=" + getId + "}"; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RemoteAttribute) { RemoteAttribute<?> that = (RemoteAttribute<?>) o; return (this.tx.equals(that.tx())) && (this.getId.equals(that.getId())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.tx.hashCode(); h *= 1000003; h ^= this.getId.hashCode(); return h; } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/AutoValue_RemoteAttributeType.java
package ai.grakn.remote.concept; import ai.grakn.concept.ConceptId; import ai.grakn.remote.RemoteGraknTx; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_RemoteAttributeType<D> extends RemoteAttributeType<D> { private final RemoteGraknTx tx; private final ConceptId getId; AutoValue_RemoteAttributeType( RemoteGraknTx tx, ConceptId getId) { if (tx == null) { throw new NullPointerException("Null tx"); } this.tx = tx; if (getId == null) { throw new NullPointerException("Null getId"); } this.getId = getId; } @Override RemoteGraknTx tx() { return tx; } @Override public ConceptId getId() { return getId; } @Override public String toString() { return "RemoteAttributeType{" + "tx=" + tx + ", " + "getId=" + getId + "}"; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RemoteAttributeType) { RemoteAttributeType<?> that = (RemoteAttributeType<?>) o; return (this.tx.equals(that.tx())) && (this.getId.equals(that.getId())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.tx.hashCode(); h *= 1000003; h ^= this.getId.hashCode(); return h; } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/AutoValue_RemoteEntity.java
package ai.grakn.remote.concept; import ai.grakn.concept.ConceptId; import ai.grakn.remote.RemoteGraknTx; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_RemoteEntity extends RemoteEntity { private final RemoteGraknTx tx; private final ConceptId getId; AutoValue_RemoteEntity( RemoteGraknTx tx, ConceptId getId) { if (tx == null) { throw new NullPointerException("Null tx"); } this.tx = tx; if (getId == null) { throw new NullPointerException("Null getId"); } this.getId = getId; } @Override RemoteGraknTx tx() { return tx; } @Override public ConceptId getId() { return getId; } @Override public String toString() { return "RemoteEntity{" + "tx=" + tx + ", " + "getId=" + getId + "}"; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RemoteEntity) { RemoteEntity that = (RemoteEntity) o; return (this.tx.equals(that.tx())) && (this.getId.equals(that.getId())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.tx.hashCode(); h *= 1000003; h ^= this.getId.hashCode(); return h; } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/AutoValue_RemoteEntityType.java
package ai.grakn.remote.concept; import ai.grakn.concept.ConceptId; import ai.grakn.remote.RemoteGraknTx; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_RemoteEntityType extends RemoteEntityType { private final RemoteGraknTx tx; private final ConceptId getId; AutoValue_RemoteEntityType( RemoteGraknTx tx, ConceptId getId) { if (tx == null) { throw new NullPointerException("Null tx"); } this.tx = tx; if (getId == null) { throw new NullPointerException("Null getId"); } this.getId = getId; } @Override RemoteGraknTx tx() { return tx; } @Override public ConceptId getId() { return getId; } @Override public String toString() { return "RemoteEntityType{" + "tx=" + tx + ", " + "getId=" + getId + "}"; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RemoteEntityType) { RemoteEntityType that = (RemoteEntityType) o; return (this.tx.equals(that.tx())) && (this.getId.equals(that.getId())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.tx.hashCode(); h *= 1000003; h ^= this.getId.hashCode(); return h; } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/AutoValue_RemoteMetaType.java
package ai.grakn.remote.concept; import ai.grakn.concept.ConceptId; import ai.grakn.remote.RemoteGraknTx; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_RemoteMetaType extends RemoteMetaType { private final RemoteGraknTx tx; private final ConceptId getId; AutoValue_RemoteMetaType( RemoteGraknTx tx, ConceptId getId) { if (tx == null) { throw new NullPointerException("Null tx"); } this.tx = tx; if (getId == null) { throw new NullPointerException("Null getId"); } this.getId = getId; } @Override RemoteGraknTx tx() { return tx; } @Override public ConceptId getId() { return getId; } @Override public String toString() { return "RemoteMetaType{" + "tx=" + tx + ", " + "getId=" + getId + "}"; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RemoteMetaType) { RemoteMetaType that = (RemoteMetaType) o; return (this.tx.equals(that.tx())) && (this.getId.equals(that.getId())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.tx.hashCode(); h *= 1000003; h ^= this.getId.hashCode(); return h; } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/AutoValue_RemoteRelationship.java
package ai.grakn.remote.concept; import ai.grakn.concept.ConceptId; import ai.grakn.remote.RemoteGraknTx; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_RemoteRelationship extends RemoteRelationship { private final RemoteGraknTx tx; private final ConceptId getId; AutoValue_RemoteRelationship( RemoteGraknTx tx, ConceptId getId) { if (tx == null) { throw new NullPointerException("Null tx"); } this.tx = tx; if (getId == null) { throw new NullPointerException("Null getId"); } this.getId = getId; } @Override RemoteGraknTx tx() { return tx; } @Override public ConceptId getId() { return getId; } @Override public String toString() { return "RemoteRelationship{" + "tx=" + tx + ", " + "getId=" + getId + "}"; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RemoteRelationship) { RemoteRelationship that = (RemoteRelationship) o; return (this.tx.equals(that.tx())) && (this.getId.equals(that.getId())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.tx.hashCode(); h *= 1000003; h ^= this.getId.hashCode(); return h; } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/AutoValue_RemoteRelationshipType.java
package ai.grakn.remote.concept; import ai.grakn.concept.ConceptId; import ai.grakn.remote.RemoteGraknTx; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_RemoteRelationshipType extends RemoteRelationshipType { private final RemoteGraknTx tx; private final ConceptId getId; AutoValue_RemoteRelationshipType( RemoteGraknTx tx, ConceptId getId) { if (tx == null) { throw new NullPointerException("Null tx"); } this.tx = tx; if (getId == null) { throw new NullPointerException("Null getId"); } this.getId = getId; } @Override RemoteGraknTx tx() { return tx; } @Override public ConceptId getId() { return getId; } @Override public String toString() { return "RemoteRelationshipType{" + "tx=" + tx + ", " + "getId=" + getId + "}"; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RemoteRelationshipType) { RemoteRelationshipType that = (RemoteRelationshipType) o; return (this.tx.equals(that.tx())) && (this.getId.equals(that.getId())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.tx.hashCode(); h *= 1000003; h ^= this.getId.hashCode(); return h; } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/AutoValue_RemoteRole.java
package ai.grakn.remote.concept; import ai.grakn.concept.ConceptId; import ai.grakn.remote.RemoteGraknTx; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_RemoteRole extends RemoteRole { private final RemoteGraknTx tx; private final ConceptId getId; AutoValue_RemoteRole( RemoteGraknTx tx, ConceptId getId) { if (tx == null) { throw new NullPointerException("Null tx"); } this.tx = tx; if (getId == null) { throw new NullPointerException("Null getId"); } this.getId = getId; } @Override RemoteGraknTx tx() { return tx; } @Override public ConceptId getId() { return getId; } @Override public String toString() { return "RemoteRole{" + "tx=" + tx + ", " + "getId=" + getId + "}"; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RemoteRole) { RemoteRole that = (RemoteRole) o; return (this.tx.equals(that.tx())) && (this.getId.equals(that.getId())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.tx.hashCode(); h *= 1000003; h ^= this.getId.hashCode(); return h; } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/AutoValue_RemoteRule.java
package ai.grakn.remote.concept; import ai.grakn.concept.ConceptId; import ai.grakn.remote.RemoteGraknTx; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_RemoteRule extends RemoteRule { private final RemoteGraknTx tx; private final ConceptId getId; AutoValue_RemoteRule( RemoteGraknTx tx, ConceptId getId) { if (tx == null) { throw new NullPointerException("Null tx"); } this.tx = tx; if (getId == null) { throw new NullPointerException("Null getId"); } this.getId = getId; } @Override RemoteGraknTx tx() { return tx; } @Override public ConceptId getId() { return getId; } @Override public String toString() { return "RemoteRule{" + "tx=" + tx + ", " + "getId=" + getId + "}"; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RemoteRule) { RemoteRule that = (RemoteRule) o; return (this.tx.equals(that.tx())) && (this.getId.equals(that.getId())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.tx.hashCode(); h *= 1000003; h ^= this.getId.hashCode(); return h; } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteAttribute.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.Attribute; import ai.grakn.concept.AttributeType; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.concept.Thing; import ai.grakn.grpc.ConceptMethods; import ai.grakn.remote.RemoteGraknTx; import com.google.auto.value.AutoValue; import java.util.stream.Stream; /** * @author Felix Chapman * * @param <D> The data type of this attribute */ @AutoValue abstract class RemoteAttribute<D> extends RemoteThing<Attribute<D>, AttributeType<D>> implements Attribute<D> { public static <D> RemoteAttribute<D> create(RemoteGraknTx tx, ConceptId id) { return new AutoValue_RemoteAttribute<>(tx, id); } @Override public final D getValue() { return (D) runMethod(ConceptMethods.GET_VALUE); } @Override public final AttributeType.DataType<D> dataType() { return (AttributeType.DataType<D>) runMethod(ConceptMethods.GET_DATA_TYPE_OF_ATTRIBUTE); } @Override public final Stream<Thing> ownerInstances() { return runMethod(ConceptMethods.GET_OWNERS).map(Concept::asThing); } @Override final AttributeType<D> asMyType(Concept concept) { return concept.asAttributeType(); } @Override final Attribute<D> asSelf(Concept concept) { return concept.asAttribute(); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteAttributeType.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.Attribute; import ai.grakn.concept.AttributeType; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.grpc.ConceptMethods; import ai.grakn.remote.RemoteGraknTx; import com.google.auto.value.AutoValue; import javax.annotation.Nullable; import java.util.Optional; /** * @author Felix Chapman * * @param <D> The data type of this attribute type */ @AutoValue abstract class RemoteAttributeType<D> extends RemoteType<AttributeType<D>, Attribute<D>> implements AttributeType<D> { public static <D> RemoteAttributeType<D> create(RemoteGraknTx tx, ConceptId id) { return new AutoValue_RemoteAttributeType<>(tx, id); } @Override public final AttributeType<D> setRegex(@Nullable String regex) { return runVoidMethod(ConceptMethods.setRegex(Optional.ofNullable(regex))); } @Override public final Attribute<D> putAttribute(D value) { return asInstance(runMethod(ConceptMethods.putAttribute(value))); } @Nullable @Override public final Attribute<D> getAttribute(D value) { Optional<Concept> concept = runMethod(ConceptMethods.getAttribute(value)); return concept.map(Concept::<D>asAttribute).orElse(null); } @Nullable @Override public final AttributeType.DataType<D> getDataType() { return (AttributeType.DataType<D>) runMethod(ConceptMethods.GET_DATA_TYPE_OF_TYPE).orElse(null); } @Nullable @Override public final String getRegex() { return runMethod(ConceptMethods.GET_REGEX).orElse(null); } @Override final AttributeType<D> asSelf(Concept concept) { return concept.asAttributeType(); } @Override final boolean isSelf(Concept concept) { return concept.isAttributeType(); } @Override protected final Attribute<D> asInstance(Concept concept) { return concept.asAttribute(); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteConcept.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.Keyspace; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.exception.GraknTxOperationException; import ai.grakn.grpc.ConceptMethod; import ai.grakn.grpc.ConceptMethods; import ai.grakn.remote.RemoteGraknTx; import javax.annotation.Nullable; import java.util.Objects; /** * @author Felix Chapman */ abstract class RemoteConcept<Self extends Concept> implements Concept { abstract RemoteGraknTx tx(); @Override public abstract ConceptId getId(); @Override public final Keyspace keyspace() { return tx().keyspace(); } @Override public final void delete() throws GraknTxOperationException { runVoidMethod(ConceptMethods.DELETE); } @Override public final boolean isDeleted() { return !tx().client().getConcept(getId()).isPresent(); } protected final <T> T runMethod(ConceptMethod<T> property) { return Objects.requireNonNull(runNullableMethod(property)); } @Nullable private <T> T runNullableMethod(ConceptMethod<T> property) { return tx().client().runConceptMethod(getId(), property); } final Self runVoidMethod(ConceptMethod<Void> property) { runNullableMethod(property); return asSelf(this); } abstract Self asSelf(Concept concept); }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteConcepts.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.Attribute; import ai.grakn.concept.AttributeType; import ai.grakn.concept.ConceptId; import ai.grakn.concept.Entity; import ai.grakn.concept.EntityType; import ai.grakn.concept.Relationship; import ai.grakn.concept.RelationshipType; import ai.grakn.concept.Role; import ai.grakn.concept.Rule; import ai.grakn.concept.Type; import ai.grakn.remote.RemoteGraknTx; /** * Static factory methods for {@link RemoteConcept} instances, which communicate with a gRPC server using a * {@link RemoteGraknTx}. * * @author Felix Chapman */ public class RemoteConcepts { private RemoteConcepts() {} public static <D> Attribute<D> createAttribute(RemoteGraknTx tx, ConceptId id) { return RemoteAttribute.create(tx, id); } public static <D> AttributeType<D> createAttributeType(RemoteGraknTx tx, ConceptId id) { return RemoteAttributeType.create(tx, id); } public static Entity createEntity(RemoteGraknTx tx, ConceptId id) { return RemoteEntity.create(tx, id); } public static EntityType createEntityType(RemoteGraknTx tx, ConceptId id) { return RemoteEntityType.create(tx, id); } public static Type createMetaType(RemoteGraknTx tx, ConceptId id) { return RemoteMetaType.create(tx, id); } public static Relationship createRelationship(RemoteGraknTx tx, ConceptId id) { return RemoteRelationship.create(tx, id); } public static RelationshipType createRelationshipType(RemoteGraknTx tx, ConceptId id) { return RemoteRelationshipType.create(tx, id); } public static Role createRole(RemoteGraknTx tx, ConceptId id) { return RemoteRole.create(tx, id); } public static Rule createRule(RemoteGraknTx tx, ConceptId id) { return RemoteRule.create(tx, id); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteEntity.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.concept.Entity; import ai.grakn.concept.EntityType; import ai.grakn.remote.RemoteGraknTx; import com.google.auto.value.AutoValue; /** * @author Felix Chapman */ @AutoValue abstract class RemoteEntity extends RemoteThing<Entity, EntityType> implements Entity { public static RemoteEntity create(RemoteGraknTx tx, ConceptId id) { return new AutoValue_RemoteEntity(tx, id); } @Override final EntityType asMyType(Concept concept) { return concept.asEntityType(); } @Override final Entity asSelf(Concept concept) { return concept.asEntity(); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteEntityType.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.concept.Entity; import ai.grakn.concept.EntityType; import ai.grakn.grpc.ConceptMethods; import ai.grakn.remote.RemoteGraknTx; import com.google.auto.value.AutoValue; /** * @author Felix Chapman */ @AutoValue abstract class RemoteEntityType extends RemoteType<EntityType, Entity> implements EntityType { public static RemoteEntityType create(RemoteGraknTx tx, ConceptId id) { return new AutoValue_RemoteEntityType(tx, id); } @Override public final Entity addEntity() { return asInstance(runMethod(ConceptMethods.ADD_ENTITY)); } @Override final EntityType asSelf(Concept concept) { return concept.asEntityType(); } @Override final boolean isSelf(Concept concept) { return concept.isEntityType(); } @Override protected final Entity asInstance(Concept concept) { return concept.asEntity(); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteMetaType.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.concept.Thing; import ai.grakn.concept.Type; import ai.grakn.remote.RemoteGraknTx; import com.google.auto.value.AutoValue; /** * @author Felix Chapman */ @AutoValue abstract class RemoteMetaType extends RemoteType<Type, Thing> { public static RemoteMetaType create(RemoteGraknTx tx, ConceptId id) { return new AutoValue_RemoteMetaType(tx, id); } @Override final Type asSelf(Concept concept) { return concept.asType(); } @Override boolean isSelf(Concept concept) { return concept.isType(); } @Override protected final Thing asInstance(Concept concept) { return concept.asThing(); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteRelationship.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.concept.Relationship; import ai.grakn.concept.RelationshipType; import ai.grakn.concept.Role; import ai.grakn.concept.Thing; import ai.grakn.grpc.ConceptMethods; import ai.grakn.grpc.RolePlayer; import ai.grakn.remote.RemoteGraknTx; import com.google.auto.value.AutoValue; import java.util.Map; import java.util.Set; import java.util.stream.Stream; import static java.util.stream.Collectors.groupingBy; import static java.util.stream.Collectors.mapping; import static java.util.stream.Collectors.toSet; /** * @author Felix Chapman */ @AutoValue abstract class RemoteRelationship extends RemoteThing<Relationship, RelationshipType> implements Relationship { public static RemoteRelationship create(RemoteGraknTx tx, ConceptId id) { return new AutoValue_RemoteRelationship(tx, id); } @Override public final Map<Role, Set<Thing>> allRolePlayers() { return runMethod(ConceptMethods.GET_ROLE_PLAYERS) .collect(groupingBy(RolePlayer::role, mapping(RolePlayer::player, toSet()))); } @Override public final Stream<Thing> rolePlayers(Role... roles) { if (roles.length == 0) { return runMethod(ConceptMethods.GET_ROLE_PLAYERS).map(RolePlayer::player); } else { return runMethod(ConceptMethods.getRolePlayersByRoles(roles)).map(Concept::asThing); } } @Override public final Relationship addRolePlayer(Role role, Thing thing) { return runVoidMethod(ConceptMethods.setRolePlayer(RolePlayer.create(role, thing))); } @Override public final void removeRolePlayer(Role role, Thing thing) { runVoidMethod(ConceptMethods.removeRolePlayer(RolePlayer.create(role, thing))); } @Override final RelationshipType asMyType(Concept concept) { return concept.asRelationshipType(); } @Override final Relationship asSelf(Concept concept) { return concept.asRelationship(); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteRelationshipType.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.concept.Relationship; import ai.grakn.concept.RelationshipType; import ai.grakn.concept.Role; import ai.grakn.grpc.ConceptMethods; import ai.grakn.remote.RemoteGraknTx; import com.google.auto.value.AutoValue; import java.util.stream.Stream; /** * @author Felix Chapman */ @AutoValue abstract class RemoteRelationshipType extends RemoteType<RelationshipType, Relationship> implements RelationshipType { public static RemoteRelationshipType create(RemoteGraknTx tx, ConceptId id) { return new AutoValue_RemoteRelationshipType(tx, id); } @Override public final Relationship addRelationship() { return asInstance(runMethod(ConceptMethods.ADD_RELATIONSHIP)); } @Override public final Stream<Role> relates() { return runMethod(ConceptMethods.GET_RELATED_ROLES).map(Concept::asRole); } @Override public final RelationshipType relates(Role role) { return runVoidMethod(ConceptMethods.setRelatedRole(role)); } @Override public final RelationshipType deleteRelates(Role role) { return runVoidMethod(ConceptMethods.unsetRelatedRole(role)); } @Override final RelationshipType asSelf(Concept concept) { return concept.asRelationshipType(); } @Override final boolean isSelf(Concept concept) { return concept.isRelationshipType(); } @Override protected final Relationship asInstance(Concept concept) { return concept.asRelationship(); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteRole.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.concept.RelationshipType; import ai.grakn.concept.Role; import ai.grakn.concept.Type; import ai.grakn.grpc.ConceptMethods; import ai.grakn.remote.RemoteGraknTx; import com.google.auto.value.AutoValue; import java.util.stream.Stream; /** * @author Felix Chapman */ @AutoValue abstract class RemoteRole extends RemoteSchemaConcept<Role> implements Role { public static RemoteRole create(RemoteGraknTx tx, ConceptId id) { return new AutoValue_RemoteRole(tx, id); } @Override public final Stream<RelationshipType> relationshipTypes() { return runMethod(ConceptMethods.GET_RELATIONSHIP_TYPES_THAT_RELATE_ROLE).map(Concept::asRelationshipType); } @Override public final Stream<Type> playedByTypes() { return runMethod(ConceptMethods.GET_TYPES_THAT_PLAY_ROLE).map(Concept::asType); } @Override final Role asSelf(Concept concept) { return concept.asRole(); } @Override final boolean isSelf(Concept concept) { return concept.isRole(); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteRule.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.concept.Rule; import ai.grakn.concept.Type; import ai.grakn.graql.Pattern; import ai.grakn.grpc.ConceptMethods; import ai.grakn.remote.RemoteGraknTx; import com.google.auto.value.AutoValue; import javax.annotation.Nullable; import java.util.stream.Stream; /** * @author Felix Chapman */ @AutoValue abstract class RemoteRule extends RemoteSchemaConcept<Rule> implements Rule { public static RemoteRule create(RemoteGraknTx tx, ConceptId id) { return new AutoValue_RemoteRule(tx, id); } @Nullable @Override public final Pattern getWhen() { return runMethod(ConceptMethods.GET_WHEN).orElse(null); } @Nullable @Override public final Pattern getThen() { return runMethod(ConceptMethods.GET_THEN).orElse(null); } @Override public final Stream<Type> getHypothesisTypes() { throw new UnsupportedOperationException(); // TODO: remove from API } @Override public final Stream<Type> getConclusionTypes() { throw new UnsupportedOperationException(); // TODO: remove from API } @Override final Rule asSelf(Concept concept) { return concept.asRule(); } @Override final boolean isSelf(Concept concept) { return concept.isRule(); } }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteSchemaConcept.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.Concept; import ai.grakn.concept.Label; import ai.grakn.concept.LabelId; import ai.grakn.concept.Rule; import ai.grakn.concept.SchemaConcept; import ai.grakn.grpc.ConceptMethods; import javax.annotation.Nullable; import java.util.Optional; import java.util.stream.Stream; /** * @author Felix Chapman * * @param <Self> The exact type of this class */ abstract class RemoteSchemaConcept<Self extends SchemaConcept> extends RemoteConcept<Self> implements SchemaConcept { public final Self sup(Self type) { return runVoidMethod(ConceptMethods.setDirectSuperConcept(type)); } public final Self sub(Self type) { tx().client().runConceptMethod(type.getId(), ConceptMethods.setDirectSuperConcept(this)); return asSelf(this); } @Override public final Label getLabel() { return runMethod(ConceptMethods.GET_LABEL); } @Override public final Boolean isImplicit() { return runMethod(ConceptMethods.IS_IMPLICIT); } @Override public final Self setLabel(Label label) { return runVoidMethod(ConceptMethods.setLabel(label)); } @Nullable @Override public final Self sup() { Optional<Concept> concept = runMethod(ConceptMethods.GET_DIRECT_SUPER); return concept.filter(this::isSelf).map(this::asSelf).orElse(null); } @Override public final Stream<Self> sups() { return tx().admin().sups(this).filter(this::isSelf).map(this::asSelf); } @Override public final Stream<Self> subs() { return runMethod(ConceptMethods.GET_SUB_CONCEPTS).map(this::asSelf); } @Override public final LabelId getLabelId() { throw new UnsupportedOperationException(); // TODO: remove from API } @Override public final Stream<Rule> getRulesOfHypothesis() { throw new UnsupportedOperationException(); // TODO: remove from API } @Override public final Stream<Rule> getRulesOfConclusion() { throw new UnsupportedOperationException(); // TODO: remove from API } abstract boolean isSelf(Concept concept); }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteThing.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.Attribute; import ai.grakn.concept.AttributeType; import ai.grakn.concept.Concept; import ai.grakn.concept.Relationship; import ai.grakn.concept.Role; import ai.grakn.concept.Thing; import ai.grakn.concept.Type; import ai.grakn.grpc.ConceptMethod; import ai.grakn.grpc.ConceptMethods; import java.util.stream.Stream; /** * @author Felix Chapman * * @param <Self> The exact type of this class * @param <MyType> the type of an instance of this class */ abstract class RemoteThing<Self extends Thing, MyType extends Type> extends RemoteConcept<Self> implements Thing { @Override public final MyType type() { return asMyType(runMethod(ConceptMethods.GET_DIRECT_TYPE)); } @Override public final Stream<Relationship> relationships(Role... roles) { ConceptMethod<Stream<? extends Concept>> method; if (roles.length == 0) { method = ConceptMethods.GET_RELATIONSHIPS; } else { method = ConceptMethods.getRelationshipsByRoles(roles); } return runMethod(method).map(Concept::asRelationship); } @Override public final Stream<Role> plays() { return runMethod(ConceptMethods.GET_ROLES_PLAYED_BY_THING).map(Concept::asRole); } @Override public final Self attribute(Attribute attribute) { attributeRelationship(attribute); return asSelf(this); } @Override public final Relationship attributeRelationship(Attribute attribute) { return runMethod(ConceptMethods.setAttribute(attribute)).asRelationship(); } @Override public final Stream<Attribute<?>> attributes(AttributeType... attributeTypes) { ConceptMethod<Stream<? extends Concept>> method; if (attributeTypes.length == 0) { method = ConceptMethods.GET_ATTRIBUTES; } else { method = ConceptMethods.getAttributesByTypes(attributeTypes); } return runMethod(method).map(Concept::asAttribute); } @Override public final Stream<Attribute<?>> keys(AttributeType... attributeTypes) { ConceptMethod<Stream<? extends Concept>> method; if (attributeTypes.length == 0) { method = ConceptMethods.GET_KEYS; } else { method = ConceptMethods.getKeysByTypes(attributeTypes); } return runMethod(method).map(Concept::asAttribute); } @Override public final Self deleteAttribute(Attribute attribute) { return runVoidMethod(ConceptMethods.unsetAttribute(attribute)); } @Override public final boolean isInferred() { return runMethod(ConceptMethods.IS_INFERRED); } abstract MyType asMyType(Concept concept); }
0
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote
java-sources/ai/grakn/grakn-client/1.2.0/ai/grakn/remote/concept/RemoteType.java
/* * Grakn - A Distributed Semantic Database * Copyright (C) 2016-2018 Grakn Labs Limited * * Grakn is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Grakn 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 Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>. */ package ai.grakn.remote.concept; import ai.grakn.concept.AttributeType; import ai.grakn.concept.Concept; import ai.grakn.concept.Role; import ai.grakn.concept.Thing; import ai.grakn.concept.Type; import ai.grakn.exception.GraknTxOperationException; import ai.grakn.grpc.ConceptMethods; import java.util.stream.Stream; /** * @author Felix Chapman * * @param <Self> The exact type of this class * @param <Instance> the exact type of instances of this class */ abstract class RemoteType<Self extends Type, Instance extends Thing> extends RemoteSchemaConcept<Self> implements Type { @Override public final Self setAbstract(Boolean isAbstract) throws GraknTxOperationException { return runVoidMethod(ConceptMethods.setAbstract(isAbstract)); } @Override public final Self plays(Role role) throws GraknTxOperationException { return runVoidMethod(ConceptMethods.setRolePlayedByType(role)); } @Override public final Self key(AttributeType attributeType) throws GraknTxOperationException { return runVoidMethod(ConceptMethods.setKeyType(attributeType)); } @Override public final Self attribute(AttributeType attributeType) throws GraknTxOperationException { return runVoidMethod(ConceptMethods.setAttributeType(attributeType)); } @Override public final Stream<Role> plays() { return runMethod(ConceptMethods.GET_ROLES_PLAYED_BY_TYPE).map(Concept::asRole); } @Override public final Stream<AttributeType> attributes() { return runMethod(ConceptMethods.GET_ATTRIBUTE_TYPES).map(Concept::asAttributeType); } @Override public final Stream<AttributeType> keys() { return runMethod(ConceptMethods.GET_KEY_TYPES).map(Concept::asAttributeType); } @Override public final Stream<Instance> instances() { return runMethod(ConceptMethods.GET_INSTANCES).map(this::asInstance); } @Override public final Boolean isAbstract() { return runMethod(ConceptMethods.IS_ABSTRACT); } @Override public final Self deletePlays(Role role) { return runVoidMethod(ConceptMethods.unsetRolePlayedByType(role)); } @Override public final Self deleteAttribute(AttributeType attributeType) { return runVoidMethod(ConceptMethods.unsetAttributeType(attributeType)); } @Override public final Self deleteKey(AttributeType attributeType) { return runVoidMethod(ConceptMethods.unsetKeyType(attributeType)); } protected abstract Instance asInstance(Concept concept); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/API.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * <p> * We use this annotation to more clearly define our public api. * It is also useful finding dead code. * </p> * * @author Filipe Peliz Pinto Teixeira */ @Retention(RetentionPolicy.SOURCE) @Target(ElementType.METHOD) public @interface API { }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/AutoValue_GraknConfigKey.java
package ai.grakn; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_GraknConfigKey<T> extends GraknConfigKey<T> { private final String name; private final GraknConfigKey.KeyParser<T> parser; AutoValue_GraknConfigKey( String name, GraknConfigKey.KeyParser<T> parser) { if (name == null) { throw new NullPointerException("Null name"); } this.name = name; if (parser == null) { throw new NullPointerException("Null parser"); } this.parser = parser; } @Override public String name() { return name; } @Override GraknConfigKey.KeyParser<T> parser() { return parser; } @Override public String toString() { return "GraknConfigKey{" + "name=" + name + ", " + "parser=" + parser + "}"; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof GraknConfigKey) { GraknConfigKey<?> that = (GraknConfigKey<?>) o; return (this.name.equals(that.name())) && (this.parser.equals(that.parser())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.name.hashCode(); h *= 1000003; h ^= this.parser.hashCode(); return h; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/AutoValue_Keyspace.java
package ai.grakn; import com.fasterxml.jackson.annotation.JsonProperty; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_Keyspace extends Keyspace { private final String value; AutoValue_Keyspace( String value) { if (value == null) { throw new NullPointerException("Null value"); } this.value = value; } @JsonProperty(value = "name") @Override public String getValue() { return value; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Keyspace) { Keyspace that = (Keyspace) o; return (this.value.equals(that.getValue())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.value.hashCode(); return h; } private static final long serialVersionUID = 2726154016735929123L; }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/ComputeExecutor.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn; import ai.grakn.graql.ComputeQuery; import java.util.stream.Stream; /** * Class representing a job executing a {@link ComputeQuery} against a knowledge base. * @param <T> return type of ComputeQuery */ public interface ComputeExecutor<T> { /** * Get the result of the compute query job * * @throws RuntimeException if the job is killed */ Stream<T> stream(); /** * Stop the job executing. Any calls to {@link #stream()} will throw. */ void kill(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/GraknComputer.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn; import ai.grakn.concept.LabelId; import org.apache.tinkerpop.gremlin.process.computer.ComputerResult; import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; import org.apache.tinkerpop.gremlin.process.computer.MapReduce; import org.apache.tinkerpop.gremlin.process.computer.VertexProgram; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.Set; /** * <p> * {@link GraphComputer} Used For Analytics Algorithms * </p> * <p> * Wraps a Tinkerpop {@link GraphComputer} which enables the execution of pregel programs. * These programs are defined either via a {@link MapReduce} or a {@link VertexProgram}. * </p> * <p> * A {@link VertexProgram} is a computation executed on each vertex in parallel. * Vertices communicate with each other through message passing. * </p> * <p> * {@link MapReduce} processed the vertices in a parallel manner by aggregating values emitted by vertices. * MapReduce can be executed alone or used to collect the results after executing a VertexProgram. * </p> * * @author duckofyork * @author sheldonkhall * @author fppt */ public interface GraknComputer { /** * Execute the given vertex program using a graph computer. * * @param includesRolePlayerEdges whether the graph computer should include {@link ai.grakn.util.Schema.EdgeLabel#ROLE_PLAYER} edges * @param types instance types in the subgraph * @param program the vertex program * @param mapReduce a list of mapReduce job * @return the result of the computation * @see ComputerResult */ @CheckReturnValue ComputerResult compute(@Nullable VertexProgram program, @Nullable MapReduce mapReduce, @Nullable Set<LabelId> types, Boolean includesRolePlayerEdges); /** * Execute the given vertex program using a graph computer. * * @param types instance types in the subgraph * @param program the vertex program * @param mapReduce a list of mapReduce job * @return the result of the computation * @see ComputerResult */ @CheckReturnValue ComputerResult compute(@Nullable VertexProgram program, @Nullable MapReduce mapReduce, @Nullable Set<LabelId> types); /** * Kill all the jobs the graph computer has */ void killJobs(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/GraknConfigKey.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn; import ai.grakn.util.ErrorMessage; import com.google.auto.value.AutoValue; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; /** * Class for keys of properties in the file {@code grakn.properties}. * * @param <T> the type of the values of the key * @author Grakn Warriors */ @AutoValue public abstract class GraknConfigKey<T> { /** * Parser for a {@link GraknConfigKey}. * Describes how to {@link #read(String)} and {@link #write(Object)} properties. * * @param <T> The type of the property value */ public interface KeyParser<T> { T read(String string); default String write(T value) { return value.toString(); } } // These are helpful parser to describe how to parse parameters of certain types. public static final KeyParser<String> STRING = string -> string; public static final KeyParser<Integer> INT = Integer::parseInt; public static final KeyParser<Boolean> BOOL = Boolean::parseBoolean; public static final KeyParser<Long> LONG = Long::parseLong; public static final KeyParser<Path> PATH = Paths::get; public static final KeyParser<List<String>> CSV = new KeyParser<List<String>>() { @Override public List<String> read(String string) { Stream<String> split = Arrays.stream(string.split(",")); return split.map(String::trim).filter(t -> !t.isEmpty()).collect(Collectors.toList()); } @Override public String write(List<String> value) { return value.stream().collect(Collectors.joining(",")); } }; public static final GraknConfigKey<Integer> WEBSERVER_THREADS = key("webserver.threads", INT); public static final GraknConfigKey<String> SERVER_HOST_NAME = key("server.host"); public static final GraknConfigKey<Integer> SERVER_PORT = key("server.port", INT); public static final GraknConfigKey<Integer> GRPC_PORT = key("grpc.port", INT); public static final GraknConfigKey<String> STORAGE_HOSTNAME = key("storage.hostname", STRING); public static final GraknConfigKey<String> STORAGE_BATCH_LOADING = key("storage.batch-loading", STRING); public static final GraknConfigKey<String> STORAGE_KEYSPACE = key("storage.cassandra.keyspace", STRING); public static final GraknConfigKey<Integer> STORAGE_REPLICATION_FACTOR = key("storage.cassandra.replication-factor", INT); public static final GraknConfigKey<Integer> STORAGE_PORT = key("storage.port", INT); public static final GraknConfigKey<Integer> HADOOP_STORAGE_PORT = key("janusgraphmr.ioformat.conf.storage.port", INT); public static final GraknConfigKey<Integer> STORAGE_CQL_NATIVE_PORT = key("cassandra.input.native.port", INT); public static final GraknConfigKey<Path> STATIC_FILES_PATH = key("server.static-file-dir", PATH); public static final GraknConfigKey<Integer> SESSION_CACHE_TIMEOUT_MS = key("knowledge-base.schema-cache-timeout-ms", INT); public static final GraknConfigKey<Integer> TASKS_RETRY_DELAY = key("tasks.retry.delay", INT); public static final GraknConfigKey<Long> SHARDING_THRESHOLD = key("knowledge-base.sharding-threshold", LONG); public static final GraknConfigKey<String> KB_MODE = key("knowledge-base.mode"); public static final GraknConfigKey<String> KB_ANALYTICS = key("knowledge-base.analytics"); public static final GraknConfigKey<String> DATA_DIR = key("data-dir"); public static final GraknConfigKey<String> LOG_DIR = key("log.dirs"); public static final GraknConfigKey<Boolean> TEST_START_EMBEDDED_COMPONENTS = key("test.start.embedded.components", BOOL); /** * The name of the key, how it looks in the properties file */ public abstract String name(); /** * The parser used to read and write the property. */ abstract KeyParser<T> parser(); /** * Parse the value of a property. * * This function should return an empty optional if the key was not present and there is no default value. * * @param value the value of the property. Empty if the property isn't in the property file. * @param configFilePath path to the config file * @return the parsed value * * @throws RuntimeException if the value is not present and there is no default value */ public final T parse(String value, Path configFilePath) { if (value == null) { throw new RuntimeException(ErrorMessage.UNAVAILABLE_PROPERTY.getMessage(name(), configFilePath)); } return parser().read(value); } /** * Convert the value of the property into a string to store in a properties file */ public final String valueToString(T value) { return parser().write(value); } /** * Create a key for a string property */ public static GraknConfigKey<String> key(String value) { return key(value, STRING); } /** * Create a key with the given parser */ public static <T> GraknConfigKey<T> key(String value, KeyParser<T> parser) { return new AutoValue_GraknConfigKey<>(value, parser); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/GraknSession.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn; import javax.annotation.CheckReturnValue; /** * <p> * Builds a {@link GraknSession} * </p> * * <p> * This class facilitates the construction of Grakn Graphs by determining which session should be built. * The graphs produced by a session are singletons bound to a specific keyspace. * * </p> * * @author fppt */ public interface GraknSession extends AutoCloseable { /** * Gets a new transaction bound to the keyspace of this Session. * * @param transactionType The type of transaction to open see {@link GraknTxType} for more details * @return A new Grakn graph transaction * @see GraknTx */ @CheckReturnValue GraknTx transaction(GraknTxType transactionType); /** * Closes the main connection to the graph. This should be done at the end of using the graph. * */ void close(); /** * Use to determine which {@link Keyspace} this {@link GraknSession} is interacting with. * * @return The {@link Keyspace} of the knowledge base this {@link GraknSession} is interacting with. */ ai.grakn.Keyspace keyspace(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/GraknSystemProperty.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn; import javax.annotation.Nullable; /** * Enum representing system properties used by Grakn * * @author Felix Chapman */ public enum GraknSystemProperty { // TODO: clean and document how these behave and interact // what's the difference between grakn.dir and main.basedir? how do they relate to grakn.conf? etc. CURRENT_DIRECTORY("grakn.dir"), CONFIGURATION_FILE("grakn.conf"), TEST_PROFILE("grakn.test-profile"), // Only used in tests PROJECT_RELATIVE_DIR("main.basedir"), // Only used in tests GRAKN_PID_FILE("grakn.pidfile"), ENGINE_JAVAOPTS("engine.javaopts"), STORAGE_JAVAOPTS("storage.javaopts"); private String key; GraknSystemProperty(String key) { this.key = key; } /** * Return the key identifying the system property * @return the key identifying the system property */ public String key() { return key; } /** * Retrieve the value of the system property * @return the value of the system property, or null if the system property is not set */ @Nullable public String value() { return System.getProperty(key); } /** * Set the value of the system property * @param value the value to set on the system property */ public void set(String value) { System.setProperty(key, value); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/GraknTx.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn; import ai.grakn.concept.Attribute; import ai.grakn.concept.AttributeType; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.concept.EntityType; import ai.grakn.concept.Label; import ai.grakn.concept.RelationshipType; import ai.grakn.concept.Role; import ai.grakn.concept.Rule; import ai.grakn.concept.SchemaConcept; import ai.grakn.concept.Type; import ai.grakn.exception.GraknTxOperationException; import ai.grakn.exception.PropertyNotUniqueException; import ai.grakn.graql.Pattern; import ai.grakn.graql.QueryBuilder; import ai.grakn.kb.admin.GraknAdmin; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.Collection; /** * <p> * A {@link GraknTx} holding a database transaction * </p> * * <p> * This is produced by {@link Grakn#session(String, String)} and allows the user to construct and perform * basic look ups to the knowledge base. This also allows the execution of Graql queries. * </p> * * @author fppt * */ public interface GraknTx extends AutoCloseable{ //------------------------------------- Concept Construction ---------------------------------- /** * Create a new {@link EntityType} with super-type {@code entity}, or return a pre-existing {@link EntityType}, * with the specified label. * * @param label A unique label for the {@link EntityType} * @return A new or existing {@link EntityType} with the provided label * * @throws GraknTxOperationException if the graph is closed * @throws PropertyNotUniqueException if the {@param label} is already in use by an existing non-{@link EntityType}. */ default EntityType putEntityType(String label) { return putEntityType(Label.of(label)); } /** * Create a new {@link EntityType} with super-type {@code entity}, or return a pre-existing {@link EntityType}, * with the specified label. * * @param label A unique label for the {@link EntityType} * @return A new or existing {@link EntityType} with the provided label * * @throws GraknTxOperationException if the graph is closed * @throws PropertyNotUniqueException if the {@param label} is already in use by an existing non-{@link EntityType}. */ EntityType putEntityType(Label label); /** * Create a new non-unique {@link AttributeType} with super-type {@code resource}, or return a pre-existing * non-unique {@link AttributeType}, with the specified label and data type. * * @param label A unique label for the {@link AttributeType} * @param dataType The data type of the {@link AttributeType}. * Supported types include: DataType.STRING, DataType.LONG, DataType.DOUBLE, and DataType.BOOLEAN * @param <V> The data type of the resource type. Supported types include: String, Long, Double, Boolean. * This should match the parameter type * @return A new or existing {@link AttributeType} with the provided label and data type. * * @throws GraknTxOperationException if the graph is closed * @throws PropertyNotUniqueException if the {@param label} is already in use by an existing non-{@link AttributeType}. * @throws GraknTxOperationException if the {@param label} is already in use by an existing {@link AttributeType} which is * unique or has a different datatype. */ default <V> AttributeType<V> putAttributeType(String label, AttributeType.DataType<V> dataType) { return putAttributeType(Label.of(label), dataType); } /** * Create a new non-unique {@link AttributeType} with super-type {@code resource}, or return a pre-existing * non-unique {@link AttributeType}, with the specified label and data type. * * @param label A unique label for the {@link AttributeType} * @param dataType The data type of the {@link AttributeType}. * Supported types include: DataType.STRING, DataType.LONG, DataType.DOUBLE, and DataType.BOOLEAN * @param <V> The data type of the resource type. Supported types include: String, Long, Double, Boolean. * This should match the parameter type * @return A new or existing {@link AttributeType} with the provided label and data type. * * @throws GraknTxOperationException if the graph is closed * @throws PropertyNotUniqueException if the {@param label} is already in use by an existing non-{@link AttributeType}. * @throws GraknTxOperationException if the {@param label} is already in use by an existing {@link AttributeType} which is * unique or has a different datatype. */ <V> AttributeType<V> putAttributeType(Label label, AttributeType.DataType<V> dataType); /** * Create a {@link Rule} with super-type {@code rule}, or return a pre-existing {@link Rule}, with the * specified label. * * @param label A unique label for the {@link Rule} * @param when A string representing the when part of the {@link Rule} * @param then A string representing the then part of the {@link Rule} * @return new or existing {@link Rule} with the provided label. * * @throws GraknTxOperationException if the graph is closed * @throws PropertyNotUniqueException if the {@param label} is already in use by an existing non-{@link Rule}. */ default Rule putRule(String label, Pattern when, Pattern then) { return putRule(Label.of(label), when, then); } /** * Create a {@link Rule} with super-type {@code rule}, or return a pre-existing {@link Rule}, with the * specified label. * * @param label A unique label for the {@link Rule} * @return new or existing {@link Rule} with the provided label. * * @throws GraknTxOperationException if the graph is closed * @throws PropertyNotUniqueException if the {@param label} is already in use by an existing non-{@link Rule}. */ Rule putRule(Label label, Pattern when, Pattern then); /** * Create a {@link RelationshipType} with super-type {@code relation}, or return a pre-existing {@link RelationshipType}, * with the specified label. * * @param label A unique label for the {@link RelationshipType} * @return A new or existing {@link RelationshipType} with the provided label. * * @throws GraknTxOperationException if the graph is closed * @throws PropertyNotUniqueException if the {@param label} is already in use by an existing non-{@link RelationshipType}. */ default RelationshipType putRelationshipType(String label) { return putRelationshipType(Label.of(label)); } /** * Create a {@link RelationshipType} with super-type {@code relation}, or return a pre-existing {@link RelationshipType}, * with the specified label. * * @param label A unique label for the {@link RelationshipType} * @return A new or existing {@link RelationshipType} with the provided label. * * @throws GraknTxOperationException if the graph is closed * @throws PropertyNotUniqueException if the {@param label} is already in use by an existing non-{@link RelationshipType}. */ RelationshipType putRelationshipType(Label label); /** * Create a {@link Role} with super-type {@code role}, or return a pre-existing {@link Role}, with the * specified label. * * @param label A unique label for the {@link Role} * @return new or existing {@link Role} with the provided Id. * * @throws GraknTxOperationException if the graph is closed * @throws PropertyNotUniqueException if the {@param label} is already in use by an existing non-{@link Role}. */ default Role putRole(String label) { return putRole(Label.of(label)); } /** * Create a {@link Role} with super-type {@code role}, or return a pre-existing {@link Role}, with the * specified label. * * @param label A unique label for the {@link Role} * @return new or existing {@link Role} with the provided Id. * * @throws GraknTxOperationException if the graph is closed * @throws PropertyNotUniqueException if the {@param label} is already in use by an existing non-{@link Role}. */ Role putRole(Label label); //------------------------------------- Concept Lookup ---------------------------------- /** * Get the {@link Concept} with identifier provided, if it exists. * * @param id A unique identifier for the {@link Concept} in the graph. * @return The {@link Concept} with the provided id or null if no such {@link Concept} exists. * * @throws GraknTxOperationException if the graph is closed * @throws ClassCastException if the concept is not an instance of {@link T} */ @CheckReturnValue @Nullable <T extends Concept> T getConcept(ConceptId id); /** * Get the {@link SchemaConcept} with the label provided, if it exists. * * @param label A unique label which identifies the {@link SchemaConcept} in the graph. * @return The {@link SchemaConcept} with the provided label or null if no such {@link SchemaConcept} exists. * * @throws GraknTxOperationException if the graph is closed * @throws ClassCastException if the type is not an instance of {@link T} */ @CheckReturnValue @Nullable <T extends SchemaConcept> T getSchemaConcept(Label label); /** * Get the {@link Type} with the label provided, if it exists. * * @param label A unique label which identifies the {@link Type} in the graph. * @return The {@link Type} with the provided label or null if no such {@link Type} exists. * * @throws GraknTxOperationException if the graph is closed * @throws ClassCastException if the type is not an instance of {@link T} */ @CheckReturnValue @Nullable <T extends Type> T getType(Label label); /** * Get all {@link Attribute} holding the value provided, if they exist. * * @param value A value which an {@link Attribute} in the graph may be holding. * @param <V> The data type of the value. Supported types include: String, Long, Double, and Boolean. * @return The {@link Attribute}s holding the provided value or an empty collection if no such {@link Attribute} exists. * * @throws GraknTxOperationException if the graph is closed */ @CheckReturnValue <V> Collection<Attribute<V>> getAttributesByValue(V value); /** * Get the Entity Type with the label provided, if it exists. * * @param label A unique label which identifies the Entity Type in the graph. * @return The Entity Type with the provided label or null if no such Entity Type exists. * * @throws GraknTxOperationException if the graph is closed */ @CheckReturnValue @Nullable EntityType getEntityType(String label); /** * Get the {@link RelationshipType} with the label provided, if it exists. * * @param label A unique label which identifies the {@link RelationshipType} in the graph. * @return The {@link RelationshipType} with the provided label or null if no such {@link RelationshipType} exists. * * @throws GraknTxOperationException if the graph is closed */ @CheckReturnValue @Nullable RelationshipType getRelationshipType(String label); /** * Get the {@link AttributeType} with the label provided, if it exists. * * @param label A unique label which identifies the {@link AttributeType} in the graph. * @param <V> The data type of the value. Supported types include: String, Long, Double, and Boolean. * @return The {@link AttributeType} with the provided label or null if no such {@link AttributeType} exists. * * @throws GraknTxOperationException if the graph is closed */ @CheckReturnValue @Nullable <V> AttributeType<V> getAttributeType(String label); /** * Get the Role Type with the label provided, if it exists. * * @param label A unique label which identifies the Role Type in the graph. * @return The Role Type with the provided label or null if no such Role Type exists. * * @throws GraknTxOperationException if the graph is closed */ @CheckReturnValue @Nullable Role getRole(String label); /** * Get the {@link Rule} with the label provided, if it exists. * * @param label A unique label which identifies the {@link Rule} in the graph. * @return The {@link Rule} with the provided label or null if no such Rule Type exists. * * @throws GraknTxOperationException if the graph is closed */ @CheckReturnValue @Nullable Rule getRule(String label); //------------------------------------- Utilities ---------------------------------- /** * Returns access to the low-level details of the graph via GraknAdmin * @see GraknAdmin * * @return The admin interface which allows you to access more low level details of the graph. */ @CheckReturnValue GraknAdmin admin(); /** * Utility function used to check if the current transaction on the graph is a read only transaction * * @return true if the current transaction is read only */ @CheckReturnValue @API GraknTxType txType(); /** * Returns the {@link GraknSession} which was used to create this {@link GraknTx} * @return the owner {@link GraknSession} */ GraknSession session(); /** * Utility function to get {@link Keyspace} of the knowledge base. * * @return The {@link Keyspace} of the knowledge base. */ @CheckReturnValue default Keyspace keyspace() { return session().keyspace(); } /** * Utility function to determine whether the graph has been closed. * * @return True if the graph has been closed */ @CheckReturnValue boolean isClosed(); // TODO: what does this do when the graph is closed? /** * Returns a QueryBuilder * * @return returns a query builder to allow for the creation of graql queries * @see QueryBuilder */ @CheckReturnValue QueryBuilder graql(); /** * Closes the current transaction. Rendering this graph unusable. You must use the {@link GraknSession} to * get a new open transaction. */ void close(); /** * Reverts any changes done to the graph and closes the transaction. You must use the {@link GraknSession} to * get a new open transaction. */ default void abort(){ close(); } /** * Commits any changes to the graph and closes the transaction. You must use the {@link GraknSession} to * get a new open transaction. * */ void commit(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/GraknTxType.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn; /** * An enum that determines the type of Grakn Transaction. * * This class is used to describe how a transaction on {@link GraknTx} should behave. * When producing a graph using a {@link GraknSession} one of the following enums must be provided: * READ - A read only transaction. If you attempt to mutate the graph with such a transaction an exception will be thrown. * WRITE - A transaction which allows you to mutate the graph. * BATCH - A transaction which allows mutations to be performed more quickly but disables some consitency checks. * * @author Grakn Warriors */ public enum GraknTxType { READ(0), //Read only transaction where mutations to the graph are prohibited WRITE(1), //Write transaction where the graph can be mutated BATCH(2); //Batch transaction which enables faster writes by switching off some consistency checks private final int type; GraknTxType(int type) { this.type = type; } public int getId() { return type; } @Override public String toString() { return this.name(); } public static GraknTxType of(int value) { for (GraknTxType t : GraknTxType.values()) { if (t.type == value) return t; } return null; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/Keyspace.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn; import ai.grakn.engine.Jacksonisable; import ai.grakn.exception.GraknTxOperationException; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; import javax.annotation.CheckReturnValue; import java.io.Serializable; import java.util.regex.Pattern; /** * <p> * A {@link Keyspace} * </p> * * <p> * A class which represents the unique name of a Grakn Knowledge Base * </p> * * @author Filipe Peliz Pinto Teixeira */ @AutoValue public abstract class Keyspace implements Comparable<Keyspace>, Serializable, Jacksonisable { private static final int MAX_LENGTH = 48; private static final long serialVersionUID = 2726154016735929123L; @JsonProperty("name") public abstract String getValue(); @Override public int compareTo(Keyspace o) { if(equals(o)) return 0; return getValue().compareTo(o.getValue()); } /** * * @param value The string which potentially represents a unique {@link Keyspace} * @return The matching {@link Keyspace} */ @CheckReturnValue @JsonCreator public static Keyspace of(@JsonProperty("name") String value){ if(!Pattern.matches("[a-z_][a-z_0-9]*", value) || value.length() > MAX_LENGTH) { throw GraknTxOperationException.invalidKeyspace(value); } return new AutoValue_Keyspace(value); } @Override public final String toString() { return getValue(); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/QueryExecutor.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn; import ai.grakn.graql.AggregateQuery; import ai.grakn.graql.ComputeQuery; import ai.grakn.graql.DefineQuery; import ai.grakn.graql.DeleteQuery; import ai.grakn.graql.GetQuery; import ai.grakn.graql.InsertQuery; import ai.grakn.graql.UndefineQuery; import ai.grakn.graql.answer.Answer; import ai.grakn.graql.answer.ConceptMap; import ai.grakn.graql.answer.ConceptSet; import java.util.stream.Stream; /** * Interface for executing queries and getting a result. Examples of possible implementations are: running the query * against a tinkerpop graph, or sending the query to some server to execute via gRPC or a REST API. * * This class allows us to decouple query representation (in {@link ai.grakn.graql.Query}) from query execution * (here in {@link QueryExecutor}). */ public interface QueryExecutor { Stream<ConceptMap> run(DefineQuery query); Stream<ConceptMap> run(UndefineQuery query); Stream<ConceptMap> run(GetQuery query); Stream<ConceptMap> run(InsertQuery query); Stream<ConceptSet> run(DeleteQuery query); <T extends Answer> Stream<T> run(AggregateQuery<T> query); <T extends Answer> ComputeExecutor<T> run(ComputeQuery<T> query); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/package-info.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ /** * A core package for connecting to a Grakn knowledge graph. */ package ai.grakn;
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/Attribute.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.Iterator; import java.util.stream.Stream; /** * <p> * Represent a literal {@link Attribute} in the graph. * </p> * * <p> * Acts as an {@link Thing} when relating to other instances except it has the added functionality of: * 1. It is unique to its {@link AttributeType} based on it's value. * 2. It has an {@link AttributeType.DataType} associated with it which constrains the allowed values. * </p> * * @author fppt * * @param <D> The data type of this resource type. * Supported Types include: {@link String}, {@link Long}, {@link Double}, and {@link Boolean} */ public interface Attribute<D> extends Thing { //------------------------------------- Accessors ---------------------------------- /** * Retrieves the value of the {@link Attribute}. * * @return The value itself */ @CheckReturnValue D value(); /** * Retrieves the type of the {@link Attribute}, that is, the {@link AttributeType} of which this resource is an Thing. * * @return The {@link AttributeType of which this resource is an Thing. */ @Override AttributeType<D> type(); /** * Retrieves the data type of this {@link Attribute}'s {@link AttributeType}. * * @return The data type of this {@link Attribute}'s type. */ @CheckReturnValue AttributeType.DataType<D> dataType(); /** * Retrieves the set of all Instances that possess this {@link Attribute}. * * @return The list of all Instances that possess this {@link Attribute}. */ @CheckReturnValue Stream<Thing> owners(); /** * If the {@link Attribute} is unique, this method retrieves the Thing that possesses it. * * @return The Thing which is connected to a unique {@link Attribute}. */ @CheckReturnValue @Nullable default Thing owner() { Iterator<Thing> owners = owners().iterator(); if(owners.hasNext()) { return owners.next(); } else { return null; } } /** * Creates a relation from this instance to the provided {@link Attribute}. * * @param attribute The {@link Attribute} to which a relationship is created * @return The instance itself */ @Override Attribute has(Attribute attribute); /** * Removes the provided {@link Attribute} from this {@link Attribute} * @param attribute the {@link Attribute} to be removed * @return The {@link Attribute} itself */ @Override Attribute unhas(Attribute attribute); //------------------------------------- Other --------------------------------- @SuppressWarnings("unchecked") @Deprecated @CheckReturnValue @Override default Attribute asAttribute(){ return this; } @Deprecated @CheckReturnValue @Override default boolean isAttribute(){ return true; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/AttributeType.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import ai.grakn.exception.GraknTxOperationException; import ai.grakn.util.Schema; import com.google.common.collect.ImmutableMap; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.function.Function; import java.util.stream.Stream; /** * <p> * An ontological element which models and categorises the various {@link Attribute} in the graph. * </p> * * <p> * This ontological element behaves similarly to {@link ai.grakn.concept.Type} when defining how it relates to other * types. It has two additional functions to be aware of: * 1. It has a {@link DataType} constraining the data types of the values it's instances may take. * 2. Any of it's instances are unique to the type. * For example if you have an {@link AttributeType} modelling month throughout the year there can only be one January. * </p> * * @author fppt * * @param <D> The data type of this resource type. * Supported Types include: {@link String}, {@link Long}, {@link Double}, and {@link Boolean} */ public interface AttributeType<D> extends Type { //------------------------------------- Modifiers ---------------------------------- /** * Changes the {@link Label} of this {@link Concept} to a new one. * @param label The new {@link Label}. * @return The {@link Concept} itself */ AttributeType label(Label label); /** * Sets the {@link AttributeType} to be abstract - which prevents it from having any instances. * * @param isAbstract Specifies if the {@link AttributeType} is to be abstract (true) or not (false). * * @return The {@link AttributeType} itself. */ @Override AttributeType<D> isAbstract(Boolean isAbstract); /** * Sets the supertype of the {@link AttributeType} to be the AttributeType specified. * * @param type The super type of this {@link AttributeType}. * @return The {@link AttributeType} itself. */ AttributeType<D> sup(AttributeType<D> type); /** * Sets the Role which instances of this {@link AttributeType} may play. * * @param role The Role Type which the instances of this {@link AttributeType} are allowed to play. * @return The {@link AttributeType} itself. */ @Override AttributeType<D> plays(Role role); /** * Removes the ability of this {@link AttributeType} to play a specific {@link Role} * * @param role The {@link Role} which the {@link Thing}s of this {@link AttributeType} should no longer be allowed to play. * @return The {@link AttributeType} itself. */ @Override AttributeType<D> unplay(Role role); /** * Removes the ability for {@link Thing}s of this {@link AttributeType} to have {@link Attribute}s of type {@link AttributeType} * * @param attributeType the {@link AttributeType} which this {@link AttributeType} can no longer have * @return The {@link AttributeType} itself. */ @Override AttributeType<D> unhas(AttributeType attributeType); /** * Removes {@link AttributeType} as a key to this {@link AttributeType} * * @param attributeType the {@link AttributeType} which this {@link AttributeType} can no longer have as a key * @return The {@link AttributeType} itself. */ @Override AttributeType<D> unkey(AttributeType attributeType); /** * Set the regular expression that instances of the {@link AttributeType} must conform to. * * @param regex The regular expression that instances of this {@link AttributeType} must conform to. * @return The {@link AttributeType} itself. */ AttributeType<D> regex(String regex); /** * Set the value for the {@link Attribute}, unique to its type. * * @param value A value for the {@link Attribute} which is unique to its type * @return new or existing {@link Attribute} of this type with the provided value. */ Attribute<D> create(D value); /** * Creates a {@link RelationshipType} which allows this type and a resource type to be linked in a strictly one-to-one mapping. * * @param attributeType The resource type which instances of this type should be allowed to play. * @return The Type itself. */ @Override AttributeType<D> key(AttributeType attributeType); /** * Creates a {@link RelationshipType} which allows this type and a resource type to be linked. * * @param attributeType The resource type which instances of this type should be allowed to play. * @return The Type itself. */ @Override AttributeType<D> has(AttributeType attributeType); //------------------------------------- Accessors --------------------------------- /** * Returns the supertype of this {@link AttributeType}. * * @return The supertype of this {@link AttributeType}, */ @Override @Nullable AttributeType<D> sup(); /** * Get the {@link Attribute} with the value provided, and its type, or return NULL * @see Attribute * * @param value A value which an {@link Attribute} in the graph may be holding * @return The {@link Attribute} with the provided value and type or null if no such {@link Attribute} exists. */ @CheckReturnValue @Nullable Attribute<D> attribute(D value); /** * Returns a collection of super-types of this {@link AttributeType}. * * @return The super-types of this {@link AttributeType} */ @Override Stream<AttributeType<D>> sups(); /** * Returns a collection of subtypes of this {@link AttributeType}. * * @return The subtypes of this {@link AttributeType} */ @Override Stream<AttributeType<D>> subs(); /** * Returns a collection of all {@link Attribute} of this {@link AttributeType}. * * @return The resource instances of this {@link AttributeType} */ @Override Stream<Attribute<D>> instances(); /** * Get the data type to which instances of the {@link AttributeType} must conform. * * @return The data type to which instances of this {@link Attribute} must conform. */ @Nullable @CheckReturnValue DataType<D> dataType(); /** * Retrieve the regular expression to which instances of this {@link AttributeType} must conform, or {@code null} if no * regular expression is set. * * By default, an {@link AttributeType} does not have a regular expression set. * * @return The regular expression to which instances of this {@link AttributeType} must conform. */ @CheckReturnValue @Nullable String regex(); //------------------------------------- Other --------------------------------- @SuppressWarnings("unchecked") @Deprecated @CheckReturnValue @Override default AttributeType asAttributeType(){ return this; } @Deprecated @CheckReturnValue @Override default boolean isAttributeType(){ return true; } /** * A class used to hold the supported data types of resources and any other concepts. * This is used tp constrain value data types to only those we explicitly support. * @param <D> The data type. */ class DataType<D> { public static final DataType<String> STRING = new DataType<>( String.class.getName(), Schema.VertexProperty.VALUE_STRING, (v) -> v, o -> defaultConverter(o, String.class, Object::toString)); public static final DataType<Boolean> BOOLEAN = new DataType<>( Boolean.class.getName(), Schema.VertexProperty.VALUE_BOOLEAN, (v) -> v, o -> defaultConverter(o, Boolean.class, (v) -> Boolean.parseBoolean(v.toString()))); public static final DataType<Integer> INTEGER = new DataType<>( Integer.class.getName(), Schema.VertexProperty.VALUE_INTEGER, (v) -> v, o -> defaultConverter(o, Integer.class, (v) -> Integer.parseInt(v.toString()))); public static final DataType<Long> LONG = new DataType<>( Long.class.getName(), Schema.VertexProperty.VALUE_LONG, (v) -> v, o -> defaultConverter(o, Long.class, (v) -> Long.parseLong(v.toString()))); public static final DataType<Double> DOUBLE = new DataType<>( Double.class.getName(), Schema.VertexProperty.VALUE_DOUBLE, (v) -> v, o -> defaultConverter(o, Double.class, (v) -> Double.parseDouble(v.toString()))); public static final DataType<Float> FLOAT = new DataType<>( Float.class.getName(), Schema.VertexProperty.VALUE_FLOAT, (v) -> v, o -> defaultConverter(o, Float.class, (v) -> Float.parseFloat(v.toString()))); public static final DataType<LocalDateTime> DATE = new DataType<>( LocalDateTime.class.getName(), Schema.VertexProperty.VALUE_DATE, (d) -> d.atZone(ZoneId.of("Z")).toInstant().toEpochMilli(), (o) -> { if (o == null) return null; if (!(o instanceof Long)) { throw GraknTxOperationException.invalidAttributeValue(o, LONG); } return LocalDateTime.ofInstant(Instant.ofEpochMilli((long) o), ZoneId.of("Z")); }); public static final ImmutableMap<String, DataType<?>> SUPPORTED_TYPES = ImmutableMap.<String, DataType<?>>builder() .put(STRING.getName(), STRING) .put(BOOLEAN.getName(), BOOLEAN) .put(LONG.getName(), LONG) .put(DOUBLE.getName(), DOUBLE) .put(INTEGER.getName(), INTEGER) .put(FLOAT.getName(), FLOAT) .put(DATE.getName(), DATE) .build(); private final String dataType; private final Schema.VertexProperty vertexProperty; private final Function<D, Object> persistenceValueSupplier; private final Function<Object, D> valueSupplier; private DataType(String dataType, Schema.VertexProperty vertexProperty, Function<D, Object> savedValueProvider, Function<Object, D> valueSupplier){ this.dataType = dataType; this.vertexProperty = vertexProperty; this.persistenceValueSupplier = savedValueProvider; this.valueSupplier = valueSupplier; } private static <X> X defaultConverter(Object o, Class clazz, Function<Object, X> converter){ if(o == null){ return null; } else if(clazz.isInstance(o)){ //noinspection unchecked return (X) o; } else { return converter.apply(o); } } @CheckReturnValue public String getName(){ return dataType; } @CheckReturnValue public Schema.VertexProperty getVertexProperty(){ return vertexProperty; } @Override public String toString(){ return getName(); } /** * Converts the provided value into the data type and format which it will be saved in. * * @param value The value to be converted * @return The String representation of the value */ @CheckReturnValue public Object getPersistenceValue(D value){ return persistenceValueSupplier.apply(value); } /** * Converts the provided value into it's correct data type * * @param object The object to be converted into the value * @return The value of the string */ @CheckReturnValue public D getValue(Object object){ return valueSupplier.apply(object); } } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/AutoValue_Label.java
package ai.grakn.concept; import com.fasterxml.jackson.annotation.JsonValue; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_Label extends Label { private final String value; AutoValue_Label( String value) { if (value == null) { throw new NullPointerException("Null value"); } this.value = value; } @JsonValue @Override public String getValue() { return value; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Label) { Label that = (Label) o; return (this.value.equals(that.getValue())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.value.hashCode(); return h; } private static final long serialVersionUID = 2051578406740868932L; }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/AutoValue_LabelId.java
package ai.grakn.concept; import javax.annotation.CheckReturnValue; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_LabelId extends LabelId { private final Integer value; AutoValue_LabelId( Integer value) { if (value == null) { throw new NullPointerException("Null value"); } this.value = value; } @CheckReturnValue @Override public Integer getValue() { return value; } @Override public String toString() { return "LabelId{" + "value=" + value + "}"; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof LabelId) { LabelId that = (LabelId) o; return (this.value.equals(that.getValue())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.value.hashCode(); return h; } private static final long serialVersionUID = -1676610785035926909L; }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/Concept.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import ai.grakn.Keyspace; import ai.grakn.exception.GraknTxOperationException; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; import javax.annotation.CheckReturnValue; /** * <p> * The base concept implementation. * </p> * * <p> * A concept which can represent anything in the graph which wraps a tinkerpop {@link Vertex}. * This class forms the basis of assuring the graph follows the Grakn object model. * It provides methods to retrieve information about the Concept, and determine if it is a {@link Type} * ({@link EntityType}, {@link Role}, {@link RelationshipType}, {@link Rule} or {@link AttributeType}) * or an {@link Thing} ({@link Entity}, {@link Relationship} , {@link Attribute}). * </p> * * @author fppt * */ public interface Concept { //------------------------------------- Accessors ---------------------------------- /** * Get the unique ID associated with the Concept. * * @return A value the concept's unique id. */ @CheckReturnValue ConceptId id(); /** * Used for determining which {@link Keyspace} a {@link Concept} was created in and is bound to. * * @return The {@link Keyspace} this {@link Concept} belongs to. */ Keyspace keyspace(); //------------------------------------- Other --------------------------------- /** * Return as a {@link SchemaConcept} if the {@link Concept} is a {@link SchemaConcept}. * * @return A {@link SchemaConcept} if the {@link Concept} is a {@link SchemaConcept} */ @CheckReturnValue default SchemaConcept asSchemaConcept(){ throw GraknTxOperationException.invalidCasting(this, SchemaConcept.class); } /** * Return as a {@link Type} if the {@link Concept} is a {@link Type}. * * @return A {@link Type} if the {@link Concept} is a {@link Type} */ @CheckReturnValue default Type asType(){ throw GraknTxOperationException.invalidCasting(this, Type.class); } /** * Return as an {@link Thing} if the {@link Concept} is an {@link Thing}. * * @return An {@link Thing} if the {@link Concept} is an {@link Thing} */ @CheckReturnValue default Thing asThing(){ throw GraknTxOperationException.invalidCasting(this, Thing.class); } /** * Return as an {@link EntityType} if the {@link Concept} is an {@link EntityType}. * * @return A {@link EntityType} if the {@link Concept} is an {@link EntityType} */ @CheckReturnValue default EntityType asEntityType(){ throw GraknTxOperationException.invalidCasting(this, EntityType.class); } /** * Return as a {@link Role} if the {@link Concept} is a {@link Role}. * * @return A {@link Role} if the {@link Concept} is a {@link Role} */ @CheckReturnValue default Role asRole(){ throw GraknTxOperationException.invalidCasting(this, Role.class); } /** * Return as a {@link RelationshipType} if the {@link Concept} is a {@link RelationshipType}. * * @return A {@link RelationshipType} if the {@link Concept} is a {@link RelationshipType} */ @CheckReturnValue default RelationshipType asRelationshipType(){ throw GraknTxOperationException.invalidCasting(this, RelationshipType.class); } /** * Return as a {@link AttributeType} if the {@link Concept} is a {@link AttributeType} * * @return A {@link AttributeType} if the {@link Concept} is a {@link AttributeType} */ @CheckReturnValue default <D> AttributeType<D> asAttributeType(){ throw GraknTxOperationException.invalidCasting(this, AttributeType.class); } /** * Return as a {@link Rule} if the {@link Concept} is a {@link Rule}. * * @return A {@link Rule} if the {@link Concept} is a {@link Rule} */ @CheckReturnValue default Rule asRule(){ throw GraknTxOperationException.invalidCasting(this, Rule.class); } /** * Return as an {@link Entity}, if the {@link Concept} is an {@link Entity} {@link Thing}. * @return An {@link Entity} if the {@link Concept} is a {@link Thing} */ @CheckReturnValue default Entity asEntity(){ throw GraknTxOperationException.invalidCasting(this, Entity.class); } /** * Return as a {@link Relationship} if the {@link Concept} is a {@link Relationship} {@link Thing}. * * @return A {@link Relationship} if the {@link Concept} is a {@link Relationship} */ @CheckReturnValue default Relationship asRelationship(){ throw GraknTxOperationException.invalidCasting(this, Relationship.class); } /** * Return as a {@link Attribute} if the {@link Concept} is a {@link Attribute} {@link Thing}. * * @return A {@link Attribute} if the {@link Concept} is a {@link Attribute} */ @CheckReturnValue default <D> Attribute<D> asAttribute(){ throw GraknTxOperationException.invalidCasting(this, Attribute.class); } /** * Determine if the {@link Concept} is a {@link SchemaConcept} * * @return true if the{@link Concept} concept is a {@link SchemaConcept} */ @CheckReturnValue default boolean isSchemaConcept(){ return false; } /** * Determine if the {@link Concept} is a {@link Type}. * * @return true if the{@link Concept} concept is a {@link Type} */ @CheckReturnValue default boolean isType(){ return false; } /** * Determine if the {@link Concept} is an {@link Thing}. * * @return true if the {@link Concept} is an {@link Thing} */ @CheckReturnValue default boolean isThing(){ return false; } /** * Determine if the {@link Concept} is an {@link EntityType}. * * @return true if the {@link Concept} is an {@link EntityType}. */ @CheckReturnValue default boolean isEntityType(){ return false; } /** * Determine if the {@link Concept} is a {@link Role}. * * @return true if the {@link Concept} is a {@link Role} */ @CheckReturnValue default boolean isRole(){ return false; } /** * Determine if the {@link Concept} is a {@link RelationshipType}. * * @return true if the {@link Concept} is a {@link RelationshipType} */ @CheckReturnValue default boolean isRelationshipType(){ return false; } /** * Determine if the {@link Concept} is a {@link AttributeType}. * * @return true if the{@link Concept} concept is a {@link AttributeType} */ @CheckReturnValue default boolean isAttributeType(){ return false; } /** * Determine if the {@link Concept} is a {@link Rule}. * * @return true if the {@link Concept} is a {@link Rule} */ @CheckReturnValue default boolean isRule(){ return false; } /** * Determine if the {@link Concept} is an {@link Entity}. * * @return true if the {@link Concept} is a {@link Entity} */ @CheckReturnValue default boolean isEntity(){ return false; } /** * Determine if the {@link Concept} is a {@link Relationship}. * * @return true if the {@link Concept} is a {@link Relationship} */ @CheckReturnValue default boolean isRelationship(){ return false; } /** * Determine if the {@link Concept} is a {@link Attribute}. * * @return true if the {@link Concept} is a {@link Attribute} */ @CheckReturnValue default boolean isAttribute(){ return false; } /** * Delete the Concept. * * @throws GraknTxOperationException Throws an exception if this is a type with incoming concepts. */ void delete() throws GraknTxOperationException; /** * Return whether the concept has been deleted. * * <p> * Under some implementations, such as {@link TinkerGraph} this always returns false. * </p> */ boolean isDeleted(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/ConceptId.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import ai.grakn.GraknTx; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import javax.annotation.CheckReturnValue; import java.io.Serializable; /** * A class which represents an id of any {@link Concept} in the {@link GraknTx}. * Also contains a static method for producing concept IDs from Strings. * * @author Grakn Warriors */ public class ConceptId implements Comparable<ConceptId>, Serializable { private final String value; /** * A non-argument constructor for ConceptID, for serialisation of OLAP queries dependencies */ ConceptId() { this.value = null; } /** * The default constructor for ConceptID, which requires String value provided * @param value String representation of the Concept ID */ ConceptId(String value) { if(value == null) throw new NullPointerException("Provided ConceptId is NULL"); this.value = value; } /** * * @return Used for indexing purposes and for graql traversals */ @CheckReturnValue @JsonValue public String getValue() { return value; } @Override public int compareTo(ConceptId o) { return getValue().compareTo(o.getValue()); } /** * * @param value The string which potentially represents a Concept * @return The matching concept ID */ @CheckReturnValue @JsonCreator public static ConceptId of(String value){ return new ConceptId(value); } @Override public final String toString() { return value; } @Override public boolean equals(Object o) { if (o == this) return true; if (o == null || this.getClass() != o.getClass()) return false; ConceptId that = (ConceptId) o; return (this.value.equals(that.getValue())); } @Override public int hashCode() { int result = 31 * this.value.hashCode(); return result; } private static final long serialVersionUID = -1723590529071614152L; }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/Entity.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import javax.annotation.CheckReturnValue; /** * <p> * An instance of Entity Type {@link EntityType} * </p> * * <p> * This represents an entity in the graph. * Entities are objects which are defined by their {@link Attribute} and their links to * other entities via {@link Relationship} * </p> * * @author fppt */ public interface Entity extends Thing { //------------------------------------- Accessors ---------------------------------- /** * * @return The EntityType of this Entity * @see EntityType */ @Override EntityType type(); /** * Creates a relation from this instance to the provided {@link Attribute}. * * @param attribute The {@link Attribute} to which a relationship is created * @return The instance itself */ @Override Entity has(Attribute attribute); /** * Removes the provided {@link Attribute} from this {@link Entity} * @param attribute the {@link Attribute} to be removed * @return The {@link Entity} itself */ @Override Entity unhas(Attribute attribute); //------------------------------------- Other --------------------------------- @Deprecated @CheckReturnValue @Override default Entity asEntity(){ return this; } @Deprecated @CheckReturnValue @Override default boolean isEntity(){ return true; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/EntityType.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import ai.grakn.exception.GraknTxOperationException; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.stream.Stream; /** * <p> * {@link SchemaConcept} used to represent categories. * </p> * * <p> * An ontological element which represents categories instances can fall within. * Any instance of a Entity Type is called an {@link Entity}. * </p> * * @author fppt * */ public interface EntityType extends Type{ //------------------------------------- Modifiers ---------------------------------- /** * Changes the {@link Label} of this {@link Concept} to a new one. * @param label The new {@link Label}. * @return The {@link Concept} itself */ EntityType label(Label label); /** * Sets the EntityType to be abstract - which prevents it from having any instances. * * @param isAbstract Specifies if the EntityType is to be abstract (true) or not (false). * * @return The EntityType itself */ @Override EntityType isAbstract(Boolean isAbstract); /** * Sets the direct supertype of the EntityType to be the EntityType specified. * * @param type The supertype of this EntityType * @return The EntityType itself * * @throws GraknTxOperationException if this is a meta type * @throws GraknTxOperationException if the given supertype is already an indirect subtype of this type */ EntityType sup(EntityType type); /** * Sets the Role which instances of this EntityType may play. * * @param role The Role Type which the instances of this EntityType are allowed to play. * @return The EntityType itself */ @Override EntityType plays(Role role); /** * Removes the ability of this {@link EntityType} to play a specific {@link Role} * * @param role The {@link Role} which the {@link Thing}s of this {@link EntityType} should no longer be allowed to play. * @return The {@link EntityType} itself. */ @Override EntityType unplay(Role role); /** * Removes the ability for {@link Thing}s of this {@link EntityType} to have {@link Attribute}s of type {@link AttributeType} * * @param attributeType the {@link AttributeType} which this {@link EntityType} can no longer have * @return The {@link EntityType} itself. */ @Override EntityType unhas(AttributeType attributeType); /** * Removes {@link AttributeType} as a key to this {@link EntityType} * * @param attributeType the {@link AttributeType} which this {@link EntityType} can no longer have as a key * @return The {@link EntityType} itself. */ @Override EntityType unkey(AttributeType attributeType); /** * Creates and returns a new Entity instance, whose direct type will be this type. * @see Entity * * @return a new empty entity. * * @throws GraknTxOperationException if this is a meta type */ Entity create(); /** * Creates a {@link RelationshipType} which allows this type and a resource type to be linked in a strictly one-to-one mapping. * * @param attributeType The resource type which instances of this type should be allowed to play. * @return The Type itself. */ @Override EntityType key(AttributeType attributeType); /** * Creates a {@link RelationshipType} which allows this type and a resource type to be linked. * * @param attributeType The resource type which instances of this type should be allowed to play. * @return The Type itself. */ @Override EntityType has(AttributeType attributeType); //------------------------------------- Accessors ---------------------------------- /** * Returns the supertype of this EntityType. * * @return The supertype of this EntityType */ @Override @Nullable EntityType sup(); /** * Returns a collection of supertypes of this EntityType. * * @return All the super classes of this EntityType */ @Override Stream<? extends EntityType> sups(); /** * Returns a collection of subtypes of this EntityType. * * @return All the sub classes of this EntityType */ @Override Stream<? extends EntityType> subs(); /** * Returns a collection of all Entity instances for this EntityType. * * @see Entity * * @return All the instances of this EntityType. */ @Override Stream<Entity> instances(); //------------------------------------- Other --------------------------------- @Deprecated @CheckReturnValue @Override default EntityType asEntityType(){ return this; } @Deprecated @CheckReturnValue @Override default boolean isEntityType(){ return true; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/Label.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import ai.grakn.GraknTx; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import com.google.auto.value.AutoValue; import javax.annotation.CheckReturnValue; import java.io.Serializable; import java.util.function.Function; /** * <p> * A Label * </p> * * <p> * A class which represents the unique label of any {@link SchemaConcept} in the {@link GraknTx}. * Also contains a static method for producing {@link Label}s from Strings. * </p> * * @author fppt */ @AutoValue public abstract class Label implements Comparable<Label>, Serializable { private static final long serialVersionUID = 2051578406740868932L; @JsonValue public abstract String getValue(); /** * Rename a {@link Label} (does not modify the original {@link Label}) * @param mapper a function to apply to the underlying type label * @return the new type label */ @CheckReturnValue public Label map(Function<String, String> mapper) { return Label.of(mapper.apply(getValue())); } @Override public int compareTo(Label o) { return getValue().compareTo(o.getValue()); } /** * * @param value The string which potentially represents a Type * @return The matching Type Label */ @CheckReturnValue @JsonCreator public static Label of(String value){ return new AutoValue_Label(value); } @Override public final String toString() { // TODO: Consider using @AutoValue toString return getValue(); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/LabelId.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import ai.grakn.GraknTx; import com.google.auto.value.AutoValue; import javax.annotation.CheckReturnValue; import java.io.Serializable; /** * <p> * A Type Id * </p> * * <p> * A class which represents an id of any {@link SchemaConcept} in the {@link GraknTx}. * Also contains a static method for producing IDs from Integers. * </p> * * @author fppt */ @AutoValue public abstract class LabelId implements Comparable<LabelId>, Serializable { private static final long serialVersionUID = -1676610785035926909L; /** * * @return Used for indexing purposes and for graql traversals */ @CheckReturnValue public abstract Integer getValue(); @Override public int compareTo(LabelId o) { return getValue().compareTo(o.getValue()); } public boolean isValid(){ return getValue() != -1; } /** * * @param value The integer which potentially represents a Type * @return The matching type ID */ public static LabelId of(Integer value){ return new AutoValue_LabelId(value); } /** * @return a type id which does not match any type */ public static LabelId invalid(){ return new AutoValue_LabelId(-1); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/Relationship.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import ai.grakn.exception.PropertyNotUniqueException; import javax.annotation.CheckReturnValue; import java.util.Map; import java.util.Set; import java.util.stream.Stream; /** * <p> * Encapsulates relationships between {@link Thing} * </p> * * <p> * A relation which is an instance of a {@link RelationshipType} defines how instances may relate to one another. * It represents how different entities relate to one another. * {@link Relationship} are used to model n-ary relationships between instances. * </p> * * @author fppt * */ public interface Relationship extends Thing { //------------------------------------- Modifiers ---------------------------------- /** * Creates a relation from this instance to the provided {@link Attribute}. * * @param attribute The {@link Attribute} to which a relationship is created * @return The instance itself */ @Override Relationship has(Attribute attribute); //------------------------------------- Accessors ---------------------------------- /** * Retrieve the associated {@link RelationshipType} for this {@link Relationship}. * @see RelationshipType * * @return The associated {@link RelationshipType} for this {@link Relationship}. */ @Override RelationshipType type(); /** * Retrieve a list of all Instances involved in the {@link Relationship}, and the {@link Role} they play. * @see Role * * @return A list of all the role types and the instances playing them in this {@link Relationship}. */ @CheckReturnValue Map<Role, Set<Thing>> rolePlayersMap(); /** * Retrieves a list of every {@link Thing} involved in the {@link Relationship}, filtered by {@link Role} played. * @param roles used to filter the returned instances only to ones that play any of the role types. * If blank, returns all role players. * @return a list of every {@link Thing} involved in the {@link Relationship}. */ @CheckReturnValue Stream<Thing> rolePlayers(Role... roles); /** * Expands this {@link Relationship} to include a new role player which is playing a specific role. * * @param role The Role Type of the new role player. * @param player The new role player. * @return The {@link Relationship} itself. * * @throws PropertyNotUniqueException if the concept is only allowed to play this role once. */ Relationship assign(Role role, Thing player); /** * Removes the provided {@link Attribute} from this {@link Relationship} * @param attribute the {@link Attribute} to be removed * @return The {@link Relationship} itself */ @Override Relationship unhas(Attribute attribute); /** * Removes the {@link Thing} which is playing a {@link Role} in this {@link Relationship}. * If the {@link Thing} is not playing any {@link Role} in this {@link Relationship} nothing happens. * * @param role The {@link Role} being played by the {@link Thing} * @param player The {@link Thing} playing the {@link Role} in this {@link Relationship} */ void unassign(Role role, Thing player); //------------------------------------- Other --------------------------------- @Deprecated @CheckReturnValue @Override default Relationship asRelationship(){ return this; } @Deprecated @CheckReturnValue @Override default boolean isRelationship(){ return true; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/RelationshipType.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import ai.grakn.exception.GraknTxOperationException; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.stream.Stream; /** * <p> * An ontological element which categorises how {@link Thing}s may relate to each other. * </p> * * <p> * A {@link RelationshipType} defines how {@link Type} may relate to one another. * They are used to model and categorise n-ary {@link Relationship}s. * </p> * * @author fppt * */ public interface RelationshipType extends Type { //------------------------------------- Modifiers ---------------------------------- /** * Changes the {@link Label} of this {@link Concept} to a new one. * @param label The new {@link Label}. * @return The {@link Concept} itself */ RelationshipType label(Label label); /** * Creates and returns a new {@link Relationship} instance, whose direct type will be this type. * @see Relationship * * @return a new empty relation. * * @throws GraknTxOperationException if this is a meta type */ Relationship create(); /** * Sets the supertype of the {@link RelationshipType} to be the {@link RelationshipType} specified. * * @param type The supertype of this {@link RelationshipType} * @return The {@link RelationshipType} itself. */ RelationshipType sup(RelationshipType type); /** * Creates a {@link RelationshipType} which allows this type and a resource type to be linked in a strictly one-to-one mapping. * * @param attributeType The resource type which instances of this type should be allowed to play. * @return The Type itself. */ @Override RelationshipType key(AttributeType attributeType); /** * Creates a {@link RelationshipType} which allows this type and a resource type to be linked. * * @param attributeType The resource type which instances of this type should be allowed to play. * @return The Type itself. */ @Override RelationshipType has(AttributeType attributeType); //------------------------------------- Accessors ---------------------------------- /** * Retrieves a list of the RoleTypes that make up this {@link RelationshipType}. * @see Role * * @return A list of the RoleTypes which make up this {@link RelationshipType}. */ @CheckReturnValue Stream<Role> roles(); //------------------------------------- Edge Handling ---------------------------------- /** * Sets a new Role for this {@link RelationshipType}. * @see Role * * @param role A new role which is part of this relationship. * @return The {@link RelationshipType} itself. */ RelationshipType relates(Role role); //------------------------------------- Other ---------------------------------- /** * Unrelated a Role from this {@link RelationshipType} * @see Role * * @param role The Role to unrelate from the {@link RelationshipType}. * @return The {@link RelationshipType} itself. */ RelationshipType unrelate(Role role); //---- Inherited Methods /** * Sets the {@link RelationshipType} to be abstract - which prevents it from having any instances. * * @param isAbstract Specifies if the concept is to be abstract (true) or not (false). * @return The {@link RelationshipType} itself. */ @Override RelationshipType isAbstract(Boolean isAbstract); /** * Returns the direct supertype of this {@link RelationshipType}. * @return The direct supertype of this {@link RelationshipType} */ @Override @Nullable RelationshipType sup(); /** * Returns a collection of supertypes of this {@link RelationshipType}. * @return All the supertypes of this {@link RelationshipType} */ @Override Stream<RelationshipType> sups(); /** * Returns a collection of subtypes of this {@link RelationshipType}. * * @return All the sub types of this {@link RelationshipType} */ @Override Stream<RelationshipType> subs(); /** * Sets the Role which instances of this {@link RelationshipType} may play. * * @param role The Role which the instances of this Type are allowed to play. * @return The {@link RelationshipType} itself. */ @Override RelationshipType plays(Role role); /** * Removes the ability of this {@link RelationshipType} to play a specific {@link Role} * * @param role The {@link Role} which the {@link Thing}s of this {@link Rule} should no longer be allowed to play. * @return The {@link Rule} itself. */ @Override RelationshipType unplay(Role role); /** * Removes the ability for {@link Thing}s of this {@link RelationshipType} to have {@link Attribute}s of type {@link AttributeType} * * @param attributeType the {@link AttributeType} which this {@link RelationshipType} can no longer have * @return The {@link RelationshipType} itself. */ @Override RelationshipType unhas(AttributeType attributeType); /** * Removes {@link AttributeType} as a key to this {@link RelationshipType} * * @param attributeType the {@link AttributeType} which this {@link RelationshipType} can no longer have as a key * @return The {@link RelationshipType} itself. */ @Override RelationshipType unkey(AttributeType attributeType); /** * Retrieve all the {@link Relationship} instances of this {@link RelationshipType} * @see Relationship * * @return All the {@link Relationship} instances of this {@link RelationshipType} */ @Override Stream<Relationship> instances(); //------------------------------------- Other --------------------------------- @Deprecated @CheckReturnValue @Override default RelationshipType asRelationshipType(){ return this; } @Deprecated @CheckReturnValue @Override default boolean isRelationshipType(){ return true; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/Role.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.stream.Stream; /** * <p> * An {@link SchemaConcept} which defines a role which can be played in a {@link RelationshipType} * </p> * * <p> * This ontological element defines the {@link Role} which make up a {@link RelationshipType}. * It behaves similarly to {@link SchemaConcept} when relating to other types. * </p> * * @author fppt * */ public interface Role extends SchemaConcept { //------------------------------------- Modifiers ---------------------------------- /** * Changes the {@link Label} of this {@link Concept} to a new one. * @param label The new {@link Label}. * @return The {@link Concept} itself */ Role label(Label label); /** * Sets the super of this Role. * * @param type The super of this Role * @return The Role itself */ Role sup(Role type); //------------------------------------- Accessors ---------------------------------- /** * Returns the super of this Role. * * @return The super of this Role */ @Nullable @Override Role sup(); /** * @return All the super-types of this this {@link Role} */ @Override Stream<Role> sups(); /** * Returns the sub of this Role. * * @return The sub of this Role */ @Override Stream<Role> subs(); /** * Returns the {@link RelationshipType}s that this {@link Role} takes part in. * @see RelationshipType * * @return The {@link RelationshipType} which this {@link Role} takes part in. */ @CheckReturnValue Stream<RelationshipType> relationships(); /** * Returns a collection of the {@link Type}s that can play this {@link Role}. * @see Type * * @return A list of all the {@link Type}s which can play this {@link Role}. */ @CheckReturnValue Stream<Type> players(); //------------------------------------- Other --------------------------------- @Deprecated @CheckReturnValue @Override default Role asRole(){ return this; } @Deprecated @CheckReturnValue @Override default boolean isRole(){ return true; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/Rule.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import ai.grakn.graql.Pattern; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.stream.Stream; /** * A {@link SchemaConcept} used to model and categorise {@link Rule}s. */ public interface Rule extends SchemaConcept { //------------------------------------- Accessors ---------------------------------- /** * Retrieves the when part of the {@link Rule} * When this query is satisfied the "then" part of the rule is executed. * * @return A string representing the left hand side Graql query. */ @CheckReturnValue @Nullable Pattern when(); /** * Retrieves the then part of the {@link Rule}. * This query is executed when the "when" part of the rule is satisfied * * @return A string representing the right hand side Graql query. */ @CheckReturnValue @Nullable Pattern then(); /** * Retrieve a set of {@link Type}s that constitute a part of the hypothesis of this {@link Rule}. * * @return A collection of Concept {@link Type}s that constitute a part of the hypothesis of the {@link Rule} */ @CheckReturnValue Stream<Type> whenTypes(); /** * Retrieve a set of {@link Type}s that constitue a part of the conclusion of the {@link Rule}. * * @return A collection of {@link Type}s that constitute a part of the conclusion of the {@link Rule} */ @CheckReturnValue Stream<Type> thenTypes(); //------------------------------------- Modifiers ---------------------------------- /** * Changes the {@link Label} of this {@link Concept} to a new one. * @param label The new {@link Label}. * @return The {@link Concept} itself */ Rule label(Label label); /** * * @return The super of this {@link Rule} */ @Nullable @Override Rule sup(); /** * * @param superRule The super of this {@link Rule} * @return The {@link Rule} itself */ Rule sup(Rule superRule); /** * @return All the super-types of this this {@link Rule} */ @Override Stream<Rule> sups(); /** * * @return All the sub of this {@link Rule} */ @Override Stream<Rule> subs(); //------------------------------------- Other --------------------------------- @Deprecated @CheckReturnValue @Override default Rule asRule(){ return this; } @Deprecated @CheckReturnValue @Override default boolean isRule(){ return true; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/SchemaConcept.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import ai.grakn.kb.admin.GraknAdmin; import ai.grakn.util.Schema; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.stream.Stream; /** * <p> * Facilitates construction of ontological elements. * </p> * * <p> * Allows you to create schema or ontological elements. * These differ from normal graph constructs in two ways: * 1. They have a unique {@link Label} which identifies them * 2. You can link them together into a hierarchical structure * </p> * * * @author fppt */ public interface SchemaConcept extends Concept { //------------------------------------- Modifiers ---------------------------------- /** * Changes the {@link Label} of this {@link Concept} to a new one. * @param label The new {@link Label}. * @return The {@link Concept} itself */ SchemaConcept label(Label label); //------------------------------------- Accessors --------------------------------- /** * Returns the unique id of this Type. * * @return The unique id of this type */ @CheckReturnValue LabelId labelId(); /** * Returns the unique label of this Type. * * @return The unique label of this type */ @CheckReturnValue Label label(); /** * * @return The direct super of this concept */ @CheckReturnValue @Nullable SchemaConcept sup(); /** * @return All super-concepts of this {@link SchemaConcept } including itself and excluding the meta * {@link Schema.MetaSchema#THING}. * * <p> * If you want to include {@link Schema.MetaSchema#THING}, use {@link GraknAdmin#sups(SchemaConcept)}. * </p> * * @see Schema.MetaSchema#THING */ Stream<? extends SchemaConcept> sups(); /** * Get all indirect subs of this concept. * * The indirect subs are the concept itself and all indirect subs of direct subs. * * @return All the indirect sub-types of this {@link SchemaConcept} */ @CheckReturnValue Stream<? extends SchemaConcept> subs(); /** * Return whether the {@link SchemaConcept} was created implicitly. * * By default, {@link SchemaConcept} are not implicit. * * @return returns true if the type was created implicitly through the {@link Attribute} syntax */ @CheckReturnValue Boolean isImplicit(); /** * Return the collection of {@link Rule} for which this {@link SchemaConcept} serves as a hypothesis. * @see Rule * * @return A collection of {@link Rule} for which this {@link SchemaConcept} serves as a hypothesis */ @CheckReturnValue Stream<Rule> whenRules(); /** * Return the collection of {@link Rule} for which this {@link SchemaConcept} serves as a conclusion. * @see Rule * * @return A collection of {@link Rule} for which this {@link SchemaConcept} serves as a conclusion */ @CheckReturnValue Stream<Rule> thenRules(); //------------------------------------- Other --------------------------------- @Deprecated @CheckReturnValue @Override default SchemaConcept asSchemaConcept(){ return this; } @Deprecated @CheckReturnValue @Override default boolean isSchemaConcept(){ return true; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/Thing.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import javax.annotation.CheckReturnValue; import java.util.stream.Stream; /** * <p> * A data instance in the graph belonging to a specific {@link Type} * </p> * * <p> * Instances represent data in the graph. * Every instance belongs to a {@link Type} which serves as a way of categorising them. * Instances can relate to one another via {@link Relationship} * </p> * * @see Entity * @see Relationship * @see Attribute * @see Rule * * @author fppt * */ public interface Thing extends Concept{ //------------------------------------- Accessors ---------------------------------- /** * Return the Type of the Concept. * * @return A Type which is the type of this concept. This concept is an instance of that type. */ @CheckReturnValue Type type(); /** * Retrieves a Relations which the Thing takes part in, which may optionally be narrowed to a particular set * according to the Role you are interested in. * @see Role * @see Relationship * * @param roles An optional parameter which allows you to specify the role of the relations you wish to retrieve. * @return A set of Relations which the concept instance takes part in, optionally constrained by the Role Type. */ @CheckReturnValue Stream<Relationship> relationships(Role... roles); /** * Determine the {@link Role}s that this {@link Thing} is currently playing. * @see Role * * @return A set of all the {@link Role}s which this {@link Thing} is currently playing. */ @CheckReturnValue Stream<Role> roles(); /** * Creates a {@link Relationship} from this {@link Thing} to the provided {@link Attribute}. * <p> * This has the same effect as {@link #relhas(Attribute)}, but returns the instance itself to allow * method chaining. * </p> * @param attribute The {@link Attribute} to which a {@link Relationship} is created * @return The instance itself */ Thing has(Attribute attribute); /** * Creates a {@link Relationship} from this instance to the provided {@link Attribute}. * <p> * This has the same effect as {@link #has(Attribute)}, but returns the new {@link Relationship}. * </p> * @param attribute The {@link Attribute} to which a {@link Relationship} is created * @return The {@link Relationship} connecting the {@link Thing} and the {@link Attribute} */ Relationship relhas(Attribute attribute); /** * Retrieves a collection of {@link Attribute} attached to this {@link Thing} * @see Attribute * * @param attributeTypes {@link AttributeType}s of the {@link Attribute}s attached to this entity * @return A collection of {@link AttributeType}s attached to this Thing. */ @CheckReturnValue Stream<Attribute<?>> attributes(AttributeType... attributeTypes); /** * Retrieves a collection of {@link Attribute} attached to this {@link Thing} as a key * @see Attribute * * @param attributeTypes {@link AttributeType}s of the {@link Attribute}s attached to this entity * @return A collection of {@link AttributeType}s attached to this Thing. */ @CheckReturnValue Stream<Attribute<?>> keys(AttributeType... attributeTypes); /** * Removes the provided {@link Attribute} from this {@link Thing} * @param attribute the {@link Attribute} to be removed * @return The {@link Thing} itself */ Thing unhas(Attribute attribute); /** * Used to indicate if this {@link Thing} has been created as the result of a {@link Rule} inference. * @see Rule * * @return true if this {@link Thing} exists due to a rule */ boolean isInferred(); //------------------------------------- Other --------------------------------- @Deprecated @CheckReturnValue @Override default Thing asThing(){ return this; } @Deprecated @CheckReturnValue @Override default boolean isThing(){ return true; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/Type.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.concept; import ai.grakn.exception.GraknTxOperationException; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.stream.Stream; /** * <p> * A Type represents any ontological element in the graph. * </p> * * <p> * Types are used to model the behaviour of {@link Thing} and how they relate to each other. * They also aid in categorising {@link Thing} to different types. * </p> * * @see EntityType * @see Role * @see RelationshipType * @see AttributeType * * @author fppt * */ public interface Type extends SchemaConcept { //------------------------------------- Modifiers ---------------------------------- /** * Changes the {@link Label} of this {@link Concept} to a new one. * @param label The new {@link Label}. * @return The {@link Concept} itself */ Type label(Label label); /** * Sets the Entity Type to be abstract - which prevents it from having any instances. * * @param isAbstract Specifies if the concept is to be abstract (true) or not (false). * @return The concept itself * * @throws GraknTxOperationException if this is a meta-type */ Type isAbstract(Boolean isAbstract) throws GraknTxOperationException; /** * * @param role The Role Type which the instances of this Type are allowed to play. * @return The Type itself. * * @throws GraknTxOperationException if this is a meta-type */ Type plays(Role role) throws GraknTxOperationException; /** * Creates a {@link RelationshipType} which allows this type and a {@link AttributeType} to be linked in a strictly one-to-one mapping. * * @param attributeType The {@link AttributeType} which instances of this type should be allowed to play. * @return The Type itself. * * @throws GraknTxOperationException if this is a meta-type */ Type key(AttributeType attributeType) throws GraknTxOperationException; /** * Creates a {@link RelationshipType} which allows this type and a {@link AttributeType} to be linked. * * @param attributeType The {@link AttributeType} which instances of this type should be allowed to play. * @return The Type itself. * * @throws GraknTxOperationException if this is a meta-type */ Type has(AttributeType attributeType) throws GraknTxOperationException; //------------------------------------- Accessors --------------------------------- /** * * @return A list of Role Types which instances of this Type can indirectly play. */ Stream<Role> playing(); /** * * @return The {@link AttributeType}s which this {@link Type} is linked with. */ @CheckReturnValue Stream<AttributeType> attributes(); /** * * @return The {@link AttributeType}s which this {@link Type} is linked with as a key. */ @CheckReturnValue Stream<AttributeType> keys(); /** * * @return The direct super of this Type */ @CheckReturnValue @Nullable Type sup(); /** * * @return All the the super-types of this {@link Type} */ @Override Stream<? extends Type> sups(); /** * Get all indirect sub-types of this type. * * The indirect sub-types are the type itself and all indirect sub-types of direct sub-types. * * @return All the indirect sub-types of this Type */ @CheckReturnValue Stream<? extends Type> subs(); /** * Get all indirect instances of this type. * * The indirect instances are the direct instances and all indirect instances of direct sub-types. * * @return All the indirect instances of this type. */ @CheckReturnValue Stream<? extends Thing> instances(); /** * Return if the type is set to abstract. * * By default, types are not abstract. * * @return returns true if the type is set to be abstract. */ @CheckReturnValue Boolean isAbstract(); //------------------------------------- Other ---------------------------------- /** * Removes the ability of this {@link Type} to play a specific {@link Role} * * @param role The {@link Role} which the {@link Thing}s of this {@link Type} should no longer be allowed to play. * @return The {@link Type} itself. */ Type unplay(Role role); /** * Removes the ability for {@link Thing}s of this {@link Type} to have {@link Attribute}s of type {@link AttributeType} * * @param attributeType the {@link AttributeType} which this {@link Type} can no longer have * @return The {@link Type} itself. */ Type unhas(AttributeType attributeType); /** * Removes {@link AttributeType} as a key to this {@link Type} * * @param attributeType the {@link AttributeType} which this {@link Type} can no longer have as a key * @return The {@link Type} itself. */ Type unkey(AttributeType attributeType); @Deprecated @CheckReturnValue @Override default Type asType(){ return this; } @Deprecated @CheckReturnValue @Override default boolean isType(){ return true; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/concept/package-info.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ /** * Provides the meta-schema interfaces and definitions. */ package ai.grakn.concept;
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/engine/AutoValue_TaskId.java
package ai.grakn.engine; import com.fasterxml.jackson.annotation.JsonValue; import javax.annotation.CheckReturnValue; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_TaskId extends TaskId { private final String value; AutoValue_TaskId( String value) { if (value == null) { throw new NullPointerException("Null value"); } this.value = value; } @CheckReturnValue @JsonValue @Override public String value() { return value; } @Override public String toString() { return "TaskId{" + "value=" + value + "}"; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof TaskId) { TaskId that = (TaskId) o; return (this.value.equals(that.value())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.value.hashCode(); return h; } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/engine/GraknConfig.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.engine; import ai.grakn.GraknConfigKey; import ai.grakn.GraknSystemProperty; import ai.grakn.util.CommonUtil; import ai.grakn.util.SimpleURI; import com.fasterxml.jackson.annotation.JsonValue; import com.google.common.base.Charsets; import com.google.common.io.Files; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Properties; import java.util.stream.Collectors; /** * Singleton class used to read config file and make all the settings available to the Grakn Engine classes. * * @author Marco Scoppetta */ public class GraknConfig { private final Properties prop; /** * The path to the config file currently in use. Default: ./conf/main/grakn.properties */ private static final Path DEFAULT_CONFIG_FILE = Paths.get(".", "conf", "main", "grakn.properties"); public static final Path PROJECT_PATH = CommonUtil.getProjectPath(); public static final Path CONFIG_FILE_PATH = getConfigFilePath(PROJECT_PATH); private static final Logger LOG = LoggerFactory.getLogger(GraknConfig.class); protected static final String GRAKN_ASCII = loadGraknAsciiFile(PROJECT_PATH, Paths.get(".","services","grakn", "grakn-ascii.txt")); private static GraknConfig defaultConfig = null; public static GraknConfig empty() { return GraknConfig.of(new Properties()); } public static GraknConfig create() { if(defaultConfig == null){ defaultConfig = GraknConfig.read(CONFIG_FILE_PATH.toFile()); } return defaultConfig; } public static GraknConfig read(File path) { Properties prop = new Properties(); try (FileInputStream inputStream = new FileInputStream(path)) { prop.load(inputStream); } catch (IOException e) { LOG.error("Could not load engine properties from {}", path, e); } LOG.info("Project directory in use: {}", PROJECT_PATH); LOG.info("Configuration file in use: {}", CONFIG_FILE_PATH); return GraknConfig.of(prop); } /** * Clone a GraknConfig properties into a new GraknConfig object * @param properties * @return new GraknConfig object with a copy of internal properties */ public static GraknConfig of(Properties properties) { Properties localProps = new Properties(); properties.forEach((key, value)-> localProps.setProperty((String)key, (String)value)); return new GraknConfig(localProps); } private GraknConfig(Properties prop) { this.prop = prop; } public void write(File path) throws IOException { try(FileOutputStream os = new FileOutputStream(path)) { prop.store(os, null); } } public <T> void setConfigProperty(GraknConfigKey<T> key, T value) { prop.setProperty(key.name(), key.valueToString(value)); } /** * Check if the JVM argument "-Dgrakn.conf" (which represents the path to the config file to use) is set. * If it is not set, it sets it to the default one. */ private static Path getConfigFilePath(Path projectPath) { String pathString = GraknSystemProperty.CONFIGURATION_FILE.value(); Path path; if (pathString == null) { path = DEFAULT_CONFIG_FILE; } else { path = Paths.get(pathString); } return projectPath.resolve(path); } /** * @param pathKey A config key for a path * @return The requested string as a full path. If it is specified as a relative path, * this method will return the path prepended with the project path. */ public Path getPath(GraknConfigKey<Path> pathKey) { return PROJECT_PATH.resolve(getProperty(pathKey)); } @JsonValue public Properties properties() { return prop; } public <T> T getProperty(GraknConfigKey<T> key) { return key.parse(prop.getProperty(key.name()), CONFIG_FILE_PATH); } public SimpleURI uri() { return new SimpleURI(getProperty(GraknConfigKey.SERVER_HOST_NAME), getProperty(GraknConfigKey.SERVER_PORT)); } private static String loadGraknAsciiFile(Path projectPath, Path graknAsciiPath) { Path asciiPath = projectPath.resolve(graknAsciiPath); try { File asciiFile = asciiPath.toFile(); return Files.readLines(asciiFile, Charsets.UTF_8).stream().collect(Collectors.joining("\n")); } catch (IOException e) { // couldn't find Grakn ASCII art. Let's just fail gracefully LOG.warn("Oops, unable to find Grakn ASCII art. Will just display nothing then."); return ""; } } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/engine/Jacksonisable.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.engine; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /** * <p> * Jacksonisable Object * </p> * * <p> * Use to pass the necessary annotation to all objects which we use Jackson for serliasation and deserilisation * </p> * * @author Filipe Peliz Pinto Teixeira */ @JsonIgnoreProperties(value={ "@id", "roles", "types", "graql", "rules", "base-type" }, allowGetters=true) public interface Jacksonisable { }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/engine/KeyspaceStore.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.engine; import ai.grakn.Keyspace; import ai.grakn.concept.Label; import java.util.Set; /** * <p> * Manages the system keyspace. * </p> * * <p> * Used to populate the system schema the first time the system keyspace * is created. * </p> * * <p> * Used to populate the system keyspace with all newly create keyspaces as a * user opens them. We have no way to determining whether a keyspace with a * given name already exists or not. We maintain the list in our Grakn system * keyspace. An element is added to that list when there is an attempt to create * a graph from a factory bound to the keyspace name. The list is simply the * instances of the system entity type 'keyspace'. Nothing is ever removed from * that list. The set of known keyspaces is maintained in a static map so we * don't connect to the system keyspace every time a factory produces a new * graph. That means that we can't have several different factories (e.g. Janus * and in-memory Tinkerpop) at the same time sharing keyspace names. We can't * identify the factory builder by engineUrl and config because we don't know * what's inside the config, which is residing remotely at the engine! * </p> * * @author borislav, fppt * */ public interface KeyspaceStore { // This will eventually be configurable and obtained the same way the factory is obtained // from engine. For now, we just make sure Engine and Core use the same system keyspace name. // If there is a more natural home for this constant, feel free to put it there! (Boris) Keyspace SYSTEM_KB_KEYSPACE = Keyspace.of("graknsystem"); Label KEYSPACE_RESOURCE = Label.of("keyspace-name"); /** * Checks if the keyspace exists in the system. The persisted graph is checked each time because the graph * may have been deleted in another JVM. * * @param keyspace The {@link Keyspace} which might be in the system * @return true if the keyspace is in the system */ boolean containsKeyspace(Keyspace keyspace); /** * This removes the keyspace of the deleted graph from the system graph * * @param keyspace the {@link Keyspace} to be removed from the system graph * * @return if the keyspace existed */ boolean deleteKeyspace(Keyspace keyspace); Set<Keyspace> keyspaces(); /** * Load the system schema into a newly created system keyspace. Because the schema * only consists of types, the inserts are idempotent and it is safe to load it * multiple times. */ void loadSystemSchema(); void addKeyspace(Keyspace keyspace); void closeStore(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/engine/TaskId.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.engine; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import com.google.auto.value.AutoValue; import javax.annotation.CheckReturnValue; import java.util.UUID; /** * An identifier for a task * * @author Felix Chapman */ @AutoValue public abstract class TaskId { @CheckReturnValue @JsonCreator public static TaskId of(String value) { return new AutoValue_TaskId(value); } @CheckReturnValue public static TaskId generate() { return new AutoValue_TaskId(UUID.randomUUID().toString()); } /** * Get the string value of the task ID */ @CheckReturnValue @JsonValue public abstract String value(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/engine/package-info.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ /** * Implements the REST controllers, task management and post processing features. */ package ai.grakn.engine;
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/exception/GraknBackendException.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.exception; import ai.grakn.Keyspace; import ai.grakn.concept.Concept; import java.net.URI; import static ai.grakn.util.ErrorMessage.BACKEND_EXCEPTION; import static ai.grakn.util.ErrorMessage.COULD_NOT_REACH_ENGINE; import static ai.grakn.util.ErrorMessage.ENGINE_STARTUP_ERROR; import static ai.grakn.util.ErrorMessage.INITIALIZATION_EXCEPTION; /** * <p> * Backend Grakn Exception * </p> * * <p> * Failures which occur server side are wrapped in this exception. This can include but is not limited to: * - Cassandra Timeouts * - Malformed Requests * </p> * * @author fppt */ public class GraknBackendException extends GraknException { private final String NAME = "GraknBackendException"; protected GraknBackendException(String error, Exception e) { super(error, e); } @Override public String getName() { return NAME; } GraknBackendException(String error){ super(error); } public static GraknBackendException create(String error) { return new GraknBackendException(error); } /** * Thrown when the persistence layer throws an unexpected exception. * This can include timeouts */ public static GraknBackendException unknown(Exception e){ return new GraknBackendException(BACKEND_EXCEPTION.getMessage(), e); } /** * Thrown when engine cannot be reached. */ public static GraknBackendException cannotReach(URI uri){ return create(COULD_NOT_REACH_ENGINE.getMessage(uri)); } public static GraknBackendException serverStartupException(String message, Exception e){ return new GraknBackendException(ENGINE_STARTUP_ERROR.getMessage(message), e); } /** * Thrown when trying to convert a {@link Concept} into a response object and failing to do so. */ public static GraknBackendException convertingUnknownConcept(Concept concept){ return create(String.format("Cannot convert concept {%s} into response object due to it being of an unknown base type", concept)); } public static GraknBackendException initializationException(Keyspace keyspace) { return create(INITIALIZATION_EXCEPTION.getMessage(keyspace)); } public static GraknBackendException noSuchKeyspace(Keyspace keyspace) { return create("No such keyspace " + keyspace); } /** * Thrown when there is a migration failure due to a backend failure */ public static GraknBackendException migrationFailure(String exception){ return create("Error on backend has stopped migration: " + exception); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/exception/GraknException.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.exception; /** * <p> * Root Grakn Exception * </p> * * <p> * Encapsulates any exception which is thrown by the Grakn stack. * This includes failures server side, failed graph mutations, and failed querying attempts * </p> * * @author fppt */ public abstract class GraknException extends RuntimeException { protected GraknException(String error){ super(error); } protected GraknException(String error, Exception e){ super(error, e); } public abstract String getName(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/exception/GraknServerException.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.exception; import ai.grakn.Keyspace; import static ai.grakn.util.ErrorMessage.CANNOT_DELETE_KEYSPACE; import static ai.grakn.util.ErrorMessage.MISSING_MANDATORY_BODY_REQUEST_PARAMETERS; import static ai.grakn.util.ErrorMessage.MISSING_MANDATORY_REQUEST_PARAMETERS; import static ai.grakn.util.ErrorMessage.MISSING_REQUEST_BODY; import static ai.grakn.util.ErrorMessage.UNSUPPORTED_CONTENT_TYPE; import static org.apache.http.HttpStatus.SC_BAD_REQUEST; import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR; import static org.apache.http.HttpStatus.SC_NOT_ACCEPTABLE; /** * <p> * Grakn Server Exception * </p> * * <p> * Wraps backend exception which require a status code which needs to be returned to the client. * </p> * * @author fppt */ public class GraknServerException extends GraknBackendException { private final int status; private GraknServerException(String error, Exception e, int status) { super(error, e); this.status = status; } private GraknServerException(String error, int status){ super(error); this.status = status; } /** * Gets the error status code if one is available */ public int getStatus(){ return status; } /** * Thrown when a request has an invalid parameter */ public static GraknServerException requestInvalidParameter(String parameter, String value){ String message = String.format("Invalid value %s for parameter %s", value, parameter); return new GraknServerException(message, SC_BAD_REQUEST); } /** * Thrown when a request is missing mandatory parameters */ public static GraknServerException requestMissingParameters(String parameter){ return new GraknServerException(MISSING_MANDATORY_REQUEST_PARAMETERS.getMessage(parameter), SC_BAD_REQUEST); } /** * Thrown when a request is missing mandatory parameters in the body */ public static GraknServerException requestMissingBodyParameters(String parameter){ return new GraknServerException( MISSING_MANDATORY_BODY_REQUEST_PARAMETERS.getMessage(parameter), SC_BAD_REQUEST); } /** * Thrown when a request is missing the body */ public static GraknServerException requestMissingBody(){ return new GraknServerException(MISSING_REQUEST_BODY.getMessage(), SC_BAD_REQUEST); } /** * Thrown the content type specified in a request is invalid */ public static GraknServerException unsupportedContentType(String contentType){ return new GraknServerException(UNSUPPORTED_CONTENT_TYPE.getMessage(contentType), SC_NOT_ACCEPTABLE); } /** * Thrown when engine cannot delete a keyspace as expected */ public static GraknServerException couldNotDelete(Keyspace keyspace){ return new GraknServerException(CANNOT_DELETE_KEYSPACE.getMessage(keyspace), SC_INTERNAL_SERVER_ERROR); } /** * Thrown when an internal server error occurs. This is likely due to incorrect configs */ public static GraknServerException internalError(String errorMessage){ return new GraknServerException(errorMessage, SC_INTERNAL_SERVER_ERROR); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/exception/GraknTxOperationException.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.exception; import ai.grakn.GraknTx; import ai.grakn.concept.Attribute; import ai.grakn.concept.AttributeType; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.concept.Label; import ai.grakn.concept.Role; import ai.grakn.concept.SchemaConcept; import ai.grakn.concept.Thing; import ai.grakn.concept.Type; import ai.grakn.util.ErrorMessage; import ai.grakn.util.Schema; import com.google.common.base.Preconditions; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Element; import javax.annotation.Nullable; import java.util.stream.Collectors; import static ai.grakn.util.ErrorMessage.CLOSE_FAILURE; import static ai.grakn.util.ErrorMessage.HAS_INVALID; import static ai.grakn.util.ErrorMessage.INVALID_DIRECTION; import static ai.grakn.util.ErrorMessage.INVALID_PROPERTY_USE; import static ai.grakn.util.ErrorMessage.LABEL_TAKEN; import static ai.grakn.util.ErrorMessage.META_TYPE_IMMUTABLE; import static ai.grakn.util.ErrorMessage.NO_TYPE; import static ai.grakn.util.ErrorMessage.REGEX_NOT_STRING; import static ai.grakn.util.ErrorMessage.RESERVED_WORD; import static ai.grakn.util.ErrorMessage.UNKNOWN_CONCEPT; /** * <p> * Illegal Mutation Exception * </p> * * <p> * This exception is thrown to prevent the user from incorrectly mutating the graph. * For example, when attempting to create instances for an abstract type, this exception is thrown. * </p> * * @author fppt */ public class GraknTxOperationException extends GraknException{ private final String NAME = "GraknTxOperationException"; GraknTxOperationException(String error){ super(error); } protected GraknTxOperationException(String error, Exception e){ super(error, e); } @Override public String getName() { return NAME; } public static GraknTxOperationException create(String error) { return new GraknTxOperationException(error); } /** * Thrown when attempting to mutate a {@link ai.grakn.util.Schema.MetaSchema} */ public static GraknTxOperationException metaTypeImmutable(Label metaLabel){ return create(META_TYPE_IMMUTABLE.getMessage(metaLabel)); } /** * Throw when trying to add instances to an abstract Type */ public static GraknTxOperationException addingInstancesToAbstractType(Type type){ return create(ErrorMessage.IS_ABSTRACT.getMessage(type.label())); } /** * Thrown when a {@link Thing} is not allowed to have {@link Attribute} of that {@link AttributeType} */ public static GraknTxOperationException hasNotAllowed(Thing thing, Attribute attribute){ return create(HAS_INVALID.getMessage(thing.type().label(), attribute.type().label())); } /** * Thrown when attempting to set a regex on a {@link Attribute} whose type {@link AttributeType} is not of the * data type {@link AttributeType.DataType#STRING} */ public static GraknTxOperationException cannotSetRegex(AttributeType attributeType){ return create(REGEX_NOT_STRING.getMessage(attributeType.label())); } /** * Thrown when a {@link Type} has incoming edges and therefore cannot be deleted */ public static GraknTxOperationException cannotBeDeleted(SchemaConcept schemaConcept){ return create(ErrorMessage.CANNOT_DELETE.getMessage(schemaConcept.label())); } /** * Thrown when {@code type} has {@code attributeType} as a {@link Type#key(AttributeType)} and a {@link Type#has(AttributeType)} */ public static GraknTxOperationException duplicateHas(Type type, AttributeType attributeType){ return create(ErrorMessage.CANNOT_BE_KEY_AND_ATTRIBUTE.getMessage(type.label(), attributeType.label())); } /** * Thrown when setting {@code superType} as the super type of {@code type} and a loop is created */ public static GraknTxOperationException loopCreated(SchemaConcept type, SchemaConcept superElement){ return create(ErrorMessage.SUPER_LOOP_DETECTED.getMessage(type.label(), superElement.label())); } /** * Thrown when casting concepts incorrectly. For example when doing {@link Concept#asEntityType()} on a * {@link ai.grakn.concept.Entity} */ public static GraknTxOperationException invalidCasting(Object concept, Class type){ return create(ErrorMessage.INVALID_OBJECT_TYPE.getMessage(concept, type)); } /** * Thrown when creating a {@link Attribute} whose value {@link Object} does not match it's {@link AttributeType}'s * {@link ai.grakn.concept.AttributeType.DataType} */ public static GraknTxOperationException invalidAttributeValue(Object object, AttributeType.DataType dataType){ return create(ErrorMessage.INVALID_DATATYPE.getMessage(object, dataType.getName())); } /** * Thrown when using an unsupported datatype with resources */ public static GraknTxOperationException unsupportedDataType(Object value) { String supported = AttributeType.DataType.SUPPORTED_TYPES.keySet().stream().collect(Collectors.joining(",")); return create(ErrorMessage.INVALID_DATATYPE.getMessage(value.getClass().getName(), supported)); } /** * Thrown when attempting to mutate a property which is immutable */ public static GraknTxOperationException immutableProperty(Object oldValue, Object newValue, Enum vertexProperty){ return create(ErrorMessage.IMMUTABLE_VALUE.getMessage(oldValue, newValue, vertexProperty.name())); } /** * Thrown when trying to set a {@code value} on the {@code resource} which does not conform to it's regex */ public static GraknTxOperationException regexFailure(AttributeType attributeType, String value, String regex){ return create(ErrorMessage.REGEX_INSTANCE_FAILURE.getMessage(regex, attributeType.label(), value)); } /** * Thrown when attempting to open a transaction which is already open */ public static GraknTxOperationException transactionOpen(GraknTx tx){ return create(ErrorMessage.TRANSACTION_ALREADY_OPEN.getMessage(tx.keyspace())); } /** * Thrown when attempting to open an invalid type of transaction */ public static GraknTxOperationException transactionInvalid(Object tx){ return create("Unknown type of transaction [" + tx + "]"); } /** * Thrown when attempting to mutate a read only transaction */ public static GraknTxOperationException transactionReadOnly(GraknTx tx){ return create(ErrorMessage.TRANSACTION_READ_ONLY.getMessage(tx.keyspace())); } /** * Thrown when attempting to mutate the schema while the transaction is in batch mode */ public static GraknTxOperationException schemaMutation(){ return create(ErrorMessage.SCHEMA_LOCKED.getMessage()); } /** * Thrown when attempting to use the graph when the transaction is closed */ public static GraknTxOperationException transactionClosed(@Nullable GraknTx tx, @Nullable String reason){ if(reason == null){ Preconditions.checkNotNull(tx); return create(ErrorMessage.TX_CLOSED.getMessage(tx.keyspace())); } else { return create(reason); } } /** * Thrown when the graph can not be closed due to an unknown reason. */ public static GraknTxOperationException closingFailed(GraknTx tx, Exception e){ return new GraknTxOperationException(CLOSE_FAILURE.getMessage(tx.keyspace()), e); } /** * Thrown when an thing does not have a type */ public static GraknTxOperationException noType(Thing thing){ return create(NO_TYPE.getMessage(thing.id())); } /** * Thrown when attempting to traverse an edge in an invalid direction */ public static GraknTxOperationException invalidDirection(Direction direction){ return create(INVALID_DIRECTION.getMessage(direction)); } /** * Thrown when trying to create something using a label reserved by the system */ public static GraknTxOperationException reservedLabel(Label label){ return create(RESERVED_WORD.getMessage(label.getValue())); } /** * Thrown when trying to add a {@link Schema.VertexProperty} to a {@link Concept} which does not accept that type * of {@link Schema.VertexProperty} */ public static GraknTxOperationException invalidPropertyUse(Concept concept, Schema.VertexProperty property) { return create(INVALID_PROPERTY_USE.getMessage(concept, property)); } /** * Thrown when trying to build a {@link Concept} using an invalid graph construct */ public static GraknTxOperationException unknownConcept(String type){ return create(UNKNOWN_CONCEPT.getMessage(type)); } /** * Thrown when changing the {@link Label} of an {@link SchemaConcept} which is owned by another {@link SchemaConcept} */ public static GraknTxOperationException labelTaken(Label label){ return create(LABEL_TAKEN.getMessage(label)); } /** * Thrown when creating an invalid {@link ai.grakn.Keyspace} */ public static GraknTxOperationException invalidKeyspace(String keyspace){ return create("Keyspace [" + keyspace + "] is invalid. " + "Grakn Keyspaces cannot start with a number and can only be lower case containing alphanumeric values and underscore characters." + "Grakn Keyspaces can also not be longer than 48 characters"); } /** * Thrown when changing the super of a {@link Type} will result in a {@link Role} disconnection which is in use. */ public static GraknTxOperationException changingSuperWillDisconnectRole(Type oldSuper, Type newSuper, Role role){ return create(String.format("Cannot change the super type {%s} to {%s} because {%s} is connected to role {%s} which {%s} is not connected to.", oldSuper.label(), newSuper.label(), oldSuper.label(), role.label(), newSuper.label())); } /** * Thrown when a {@link Thing} is missing a {@link Type} */ public static GraknTxOperationException missingType(ConceptId id) { return create(String.format("Thing {%s} is missing a type", id)); } /** * Thrown when creating a label which starts with a reserved character {@link Schema.ImplicitType#RESERVED} */ public static GraknTxOperationException invalidLabelStart(Label label){ return create(String.format("Cannot create a label {%s} starting with character {%s} as it is a reserved starting character", label, Schema.ImplicitType.RESERVED.getValue())); } /** * Thrown when attempting to create a {@link Thing} via the execution of a {@link ai.grakn.concept.Rule} when * the {@link Thing} already exists. */ public static GraknTxOperationException nonInferredThingExists(Thing thing){ return create(String.format("Thing {%s} was already created and cannot be set to inferred", thing)); } /** * Thrown when trying to build a {@link Concept} from an invalid vertex or edge */ public static GraknTxOperationException invalidElement(Element element){ return create(String.format("Cannot build a concept from element {%s} due to it being deleted.", element)); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/exception/GraqlQueryException.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.exception; import ai.grakn.concept.AttributeType; import ai.grakn.concept.Concept; import ai.grakn.concept.ConceptId; import ai.grakn.concept.Label; import ai.grakn.concept.SchemaConcept; import ai.grakn.concept.Type; import ai.grakn.graql.Var; import ai.grakn.graql.VarPattern; import ai.grakn.graql.admin.Atomic; import ai.grakn.graql.admin.ReasonerQuery; import ai.grakn.graql.admin.UniqueVarProperty; import ai.grakn.graql.admin.VarPatternAdmin; import ai.grakn.graql.macro.Macro; import ai.grakn.util.ErrorMessage; import java.time.format.DateTimeParseException; import java.util.Collection; import java.util.List; import static ai.grakn.util.ErrorMessage.INSERT_ABSTRACT_NOT_TYPE; import static ai.grakn.util.ErrorMessage.INSERT_RECURSIVE; import static ai.grakn.util.ErrorMessage.INSERT_UNDEFINED_VARIABLE; import static ai.grakn.util.ErrorMessage.INVALID_COMPUTE_ARGUMENT; import static ai.grakn.util.ErrorMessage.INVALID_COMPUTE_CONDITION; import static ai.grakn.util.ErrorMessage.INVALID_COMPUTE_METHOD; import static ai.grakn.util.ErrorMessage.INVALID_COMPUTE_METHOD_ALGORITHM; import static ai.grakn.util.ErrorMessage.INVALID_VALUE; import static ai.grakn.util.ErrorMessage.MISSING_COMPUTE_CONDITION; import static ai.grakn.util.ErrorMessage.NEGATIVE_OFFSET; import static ai.grakn.util.ErrorMessage.NON_POSITIVE_LIMIT; import static ai.grakn.util.ErrorMessage.UNEXPECTED_RESULT; import static ai.grakn.util.ErrorMessage.VARIABLE_NOT_IN_QUERY; import static ai.grakn.util.GraqlSyntax.Compute; import static ai.grakn.util.GraqlSyntax.Compute.ALGORITHMS_ACCEPTED; import static ai.grakn.util.GraqlSyntax.Compute.ARGUMENTS_ACCEPTED; import static ai.grakn.util.GraqlSyntax.Compute.CONDITIONS_ACCEPTED; import static ai.grakn.util.GraqlSyntax.Compute.CONDITIONS_REQUIRED; import static ai.grakn.util.GraqlSyntax.Compute.METHODS_ACCEPTED; /** * <p> * Graql Query Exception * </p> * <p> * Occurs when the query is syntactically correct but semantically incorrect. * For example limiting the results of a query -1 * </p> * * @author fppt */ public class GraqlQueryException extends GraknException { private final String NAME = "GraqlQueryException"; private GraqlQueryException(String error) { super(error); } private GraqlQueryException(String error, Exception cause) { super(error, cause); } @Override public String getName() { return NAME; } public static GraqlQueryException create(String formatString, Object... args) { return new GraqlQueryException(String.format(formatString, args)); } public static GraqlQueryException noPatterns() { return new GraqlQueryException(ErrorMessage.NO_PATTERNS.getMessage()); } public static GraqlQueryException incorrectAggregateArgumentNumber( String name, int minArgs, int maxArgs, List<Object> args) { String expectedArgs = (minArgs == maxArgs) ? Integer.toString(minArgs) : minArgs + "-" + maxArgs; String message = ErrorMessage.AGGREGATE_ARGUMENT_NUM.getMessage(name, expectedArgs, args.size()); return new GraqlQueryException(message); } public static GraqlQueryException conflictingProperties( VarPatternAdmin varPattern, UniqueVarProperty property, UniqueVarProperty other) { String message = ErrorMessage.CONFLICTING_PROPERTIES.getMessage( varPattern.getPrintableName(), property.graqlString(), other.graqlString() ); return new GraqlQueryException(message); } public static GraqlQueryException idNotFound(ConceptId id) { return new GraqlQueryException(ErrorMessage.ID_NOT_FOUND.getMessage(id)); } public static GraqlQueryException labelNotFound(Label label) { return new GraqlQueryException(ErrorMessage.LABEL_NOT_FOUND.getMessage(label)); } public static GraqlQueryException kCoreOnRelationshipType(Label label) { return create("cannot compute coreness of relationship type %s.", label.getValue()); } public static GraqlQueryException deleteSchemaConcept(SchemaConcept schemaConcept) { return create("cannot delete schema concept %s. Use `undefine` instead.", schemaConcept); } public static GraqlQueryException insertUnsupportedProperty(String propertyName) { return GraqlQueryException.create("inserting property '%s' is not supported, try `define`", propertyName); } public static GraqlQueryException defineUnsupportedProperty(String propertyName) { return GraqlQueryException.create("defining property '%s' is not supported, try `insert`", propertyName); } public static GraqlQueryException mustBeAttributeType(Label attributeType) { return new GraqlQueryException(ErrorMessage.MUST_BE_ATTRIBUTE_TYPE.getMessage(attributeType)); } public static GraqlQueryException cannotGetInstancesOfNonType(Label label) { return GraqlQueryException.create("%s is not a type and so does not have instances", label); } public static GraqlQueryException notARelationType(Label label) { return new GraqlQueryException(ErrorMessage.NOT_A_RELATION_TYPE.getMessage(label)); } public static GraqlQueryException notARoleType(Label roleId) { return new GraqlQueryException(ErrorMessage.NOT_A_ROLE_TYPE.getMessage(roleId, roleId)); } public static GraqlQueryException insertPredicate() { return new GraqlQueryException(ErrorMessage.INSERT_PREDICATE.getMessage()); } public static GraqlQueryException insertRecursive(VarPatternAdmin var) { return new GraqlQueryException(INSERT_RECURSIVE.getMessage(var.getPrintableName())); } public static GraqlQueryException insertUndefinedVariable(VarPatternAdmin var) { return new GraqlQueryException(INSERT_UNDEFINED_VARIABLE.getMessage(var.getPrintableName())); } public static GraqlQueryException createInstanceOfMetaConcept(Var var, Type type) { return new GraqlQueryException(var + " cannot be an instance of meta-type " + type.label()); } public static GraqlQueryException insertMetaType(Label label, SchemaConcept schemaConcept) { return new GraqlQueryException(ErrorMessage.INSERT_METATYPE.getMessage(label, schemaConcept.label())); } /** * Thrown when a concept is inserted with multiple properties when it can only have one. * <p> * For example: {@code insert $x isa movie; $x isa person;} * </p> */ public static GraqlQueryException insertMultipleProperties( VarPattern varPattern, String property, Object value1, Object value2 ) { String message = "a concept `%s` cannot have multiple properties `%s` and `%s` for `%s`"; return create(message, varPattern, value1, value2, property); } /** * Thrown when a property is inserted on a concept that already exists and that property can't be overridden. * <p> * For example: {@code match $x isa name; insert $x val "Bob";} * </p> */ public static GraqlQueryException insertPropertyOnExistingConcept(String property, Object value, Concept concept) { return create("cannot insert property `%s %s` on existing concept `%s`", property, value, concept); } /** * Thrown when a property is inserted on a concept that doesn't support that property. * <p> * For example, an entity with a value: {@code insert $x isa movie, val "The Godfather";} * </p> */ public static GraqlQueryException insertUnexpectedProperty(String property, Object value, Concept concept) { return create("unexpected property `%s %s` for concept `%s`", property, value, concept); } /** * Thrown when a concept does not have all expected properties required to insert it. * <p> * For example, an attribute without a value: {@code insert $x isa name;} * </p> */ public static GraqlQueryException insertNoExpectedProperty(String property, VarPatternAdmin var) { return create("missing expected property `%s` in `%s`", property, var); } /** * Thrown when attempting to insert a concept that already exists. * <p> * For example: {@code match $x isa movie; insert $x isa name, val "Bob";} * </p> */ public static GraqlQueryException insertExistingConcept(VarPatternAdmin pattern, Concept concept) { return create("cannot overwrite properties `%s` on concept `%s`", pattern, concept); } public static GraqlQueryException varNotInQuery(Var var) { return new GraqlQueryException(VARIABLE_NOT_IN_QUERY.getMessage(var)); } public static GraqlQueryException noTx() { return new GraqlQueryException(ErrorMessage.NO_TX.getMessage()); } public static GraqlQueryException multipleTxs() { return new GraqlQueryException(ErrorMessage.MULTIPLE_TX.getMessage()); } public static GraqlQueryException nonPositiveLimit(long limit) { return new GraqlQueryException(NON_POSITIVE_LIMIT.getMessage(limit)); } public static GraqlQueryException negativeOffset(long offset) { return new GraqlQueryException(NEGATIVE_OFFSET.getMessage(offset)); } public static GraqlQueryException invalidValueClass(Object value) { return new GraqlQueryException(INVALID_VALUE.getMessage(value.getClass())); } public static GraqlQueryException wrongNumberOfMacroArguments(Macro macro, List<Object> values) { return new GraqlQueryException("Wrong number of arguments [" + values.size() + "] to macro " + macro.name()); } public static GraqlQueryException wrongMacroArgumentType(Macro macro, String value) { return new GraqlQueryException("Value [" + value + "] is not a " + macro.name() + " needed for this macro"); } public static GraqlQueryException unknownAggregate(String name) { return new GraqlQueryException(ErrorMessage.UNKNOWN_AGGREGATE.getMessage(name)); } public static GraqlQueryException maxIterationsReached(Class<?> clazz) { return new GraqlQueryException(ErrorMessage.MAX_ITERATION_REACHED .getMessage(clazz.toString())); } public static GraqlQueryException statisticsAttributeTypesNotSpecified() { return new GraqlQueryException(ErrorMessage.ATTRIBUTE_TYPE_NOT_SPECIFIED.getMessage()); } public static GraqlQueryException instanceDoesNotExist() { return new GraqlQueryException(ErrorMessage.INSTANCE_DOES_NOT_EXIST.getMessage()); } public static GraqlQueryException kValueSmallerThanTwo() { return new GraqlQueryException(ErrorMessage.K_SMALLER_THAN_TWO.getMessage()); } public static GraqlQueryException attributeMustBeANumber(AttributeType.DataType dataType, Label attributeType) { return new GraqlQueryException(attributeType + " must have data type of `long` or `double`, but was " + dataType.getName()); } public static GraqlQueryException attributesWithDifferentDataTypes(Collection<? extends Label> attributeTypes) { return new GraqlQueryException("resource types " + attributeTypes + " have different data types"); } public static GraqlQueryException unificationAtomIncompatibility() { return new GraqlQueryException(ErrorMessage.UNIFICATION_ATOM_INCOMPATIBILITY.getMessage()); } public static GraqlQueryException nonAtomicQuery(ReasonerQuery query) { return new GraqlQueryException(ErrorMessage.NON_ATOMIC_QUERY.getMessage(query)); } public static GraqlQueryException nonGroundNeqPredicate(ReasonerQuery query) { return new GraqlQueryException(ErrorMessage.NON_GROUND_NEQ_PREDICATE.getMessage(query)); } public static GraqlQueryException incompleteResolutionPlan(ReasonerQuery reasonerQuery) { return new GraqlQueryException(ErrorMessage.INCOMPLETE_RESOLUTION_PLAN.getMessage(reasonerQuery)); } public static GraqlQueryException rolePatternAbsent(Atomic relation) { return new GraqlQueryException(ErrorMessage.ROLE_PATTERN_ABSENT.getMessage(relation)); } public static GraqlQueryException nonExistentUnifier() { return new GraqlQueryException(ErrorMessage.NON_EXISTENT_UNIFIER.getMessage()); } public static GraqlQueryException illegalAtomConversion(Atomic atom, Class<?> targetType) { return new GraqlQueryException(ErrorMessage.ILLEGAL_ATOM_CONVERSION.getMessage(atom, targetType)); } public static GraqlQueryException valuePredicateAtomWithMultiplePredicates() { return new GraqlQueryException("Attempting creation of ValuePredicate atom with more than single predicate"); } public static GraqlQueryException getUnifierOfNonAtomicQuery() { return new GraqlQueryException("Attempted to obtain unifiers on non-atomic queries."); } public static GraqlQueryException invalidQueryCacheEntry(ReasonerQuery query) { return new GraqlQueryException(ErrorMessage.INVALID_CACHE_ENTRY.getMessage(query.toString())); } public static GraqlQueryException noAtomsSelected(ReasonerQuery query) { return new GraqlQueryException(ErrorMessage.NO_ATOMS_SELECTED.getMessage(query.toString())); } public static GraqlQueryException conceptNotAThing(Object value) { return new GraqlQueryException(ErrorMessage.CONCEPT_NOT_THING.getMessage(value)); } public static GraqlQueryException nonRoleIdAssignedToRoleVariable(VarPatternAdmin var) { return new GraqlQueryException(ErrorMessage.ROLE_ID_IS_NOT_ROLE.getMessage(var.toString())); } public static GraqlQueryException cannotParseDateFormat(String originalFormat) { return new GraqlQueryException("Cannot parse date format " + originalFormat + ". See DateTimeFormatter#ofPattern"); } public static GraqlQueryException cannotParseDateString(String originalDate, String originalFormat, DateTimeParseException cause) { throw new GraqlQueryException("Cannot parse date value " + originalDate + " with format " + originalFormat, cause); } public static GraqlQueryException noLabelSpecifiedForHas(VarPattern varPattern) { return create("'has' argument '%s' requires a label", varPattern); } public static GraqlQueryException insertRolePlayerWithoutRoleType() { return new GraqlQueryException(ErrorMessage.INSERT_RELATION_WITHOUT_ROLE_TYPE.getMessage()); } public static GraqlQueryException insertAbstractOnNonType(SchemaConcept concept) { return new GraqlQueryException(INSERT_ABSTRACT_NOT_TYPE.getMessage(concept.label())); } public static GraqlQueryException unexpectedResult(Var var) { return new GraqlQueryException(UNEXPECTED_RESULT.getMessage(var.getValue())); } public static GraqlQueryException invalidComputeQuery_invalidMethod() { return new GraqlQueryException(INVALID_COMPUTE_METHOD.getMessage(METHODS_ACCEPTED)); } public static GraqlQueryException invalidComputeQuery_invalidCondition(Compute.Method method) { return new GraqlQueryException(INVALID_COMPUTE_CONDITION.getMessage(method, CONDITIONS_ACCEPTED.get(method))); } public static GraqlQueryException invalidComputeQuery_missingCondition(Compute.Method method) { return new GraqlQueryException(MISSING_COMPUTE_CONDITION.getMessage(method, CONDITIONS_REQUIRED.get(method))); } public static GraqlQueryException invalidComputeQuery_invalidMethodAlgorithm(Compute.Method method) { return new GraqlQueryException(INVALID_COMPUTE_METHOD_ALGORITHM.getMessage(method, ALGORITHMS_ACCEPTED.get(method))); } public static GraqlQueryException invalidComputeQuery_invalidArgument(Compute.Method method, Compute.Algorithm algorithm) { return new GraqlQueryException(INVALID_COMPUTE_ARGUMENT.getMessage(method, algorithm, ARGUMENTS_ACCEPTED.get(method).get(algorithm))); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/exception/GraqlSyntaxException.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.exception; import java.util.Map; import static ai.grakn.util.ErrorMessage.INVALID_STATEMENT; import static ai.grakn.util.ErrorMessage.TEMPLATE_MISSING_KEY; /** * <p> * Syntax Exception * </p> * * <p> * This is thrown when a parsing error occurs. * It means the user has input an invalid graql query which cannot be parsed. * </p> * * @author fppt */ public class GraqlSyntaxException extends GraknException { private final String NAME = "GraqlSyntaxException"; private GraqlSyntaxException(String error) { super(error); } @Override public String getName() { return NAME; } /** * Thrown when a parsing error occurs during parsing a graql file */ public static GraqlSyntaxException create(String error){ return new GraqlSyntaxException(error); } /** * Thrown when there is a syntactic error in a Graql template */ public static GraqlSyntaxException parsingIncorrectValueType(Object object, Class clazz, Map data){ return new GraqlSyntaxException(INVALID_STATEMENT.getMessage(object, clazz.getName(), data.toString())); } /** * Thrown when a key is missing during parsing a template with matching data */ public static GraqlSyntaxException parsingTemplateMissingKey(String invalidText, Map<String, Object> data){ return new GraqlSyntaxException(TEMPLATE_MISSING_KEY.getMessage(invalidText, data)); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/exception/InvalidKBException.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.exception; import ai.grakn.GraknTx; import ai.grakn.util.ErrorMessage; import java.util.List; /** * <p> * Broken Knowledge Base Exception * </p> * * <p> * This exception is thrown on {@link GraknTx#commit()} when the graph does not comply with the grakn * validation rules. For a complete list of these rules please refer to the documentation * </p> * * @author fppt */ public class InvalidKBException extends GraknException{ private final String NAME = "InvalidKBException"; private InvalidKBException(String message) { super(message); } @Override public String getName() { return NAME; } public static InvalidKBException create(String message) { return new InvalidKBException(message); } /** * Thrown on commit when validation errors are found */ public static InvalidKBException validationErrors(List<String> errors){ StringBuilder message = new StringBuilder(); message.append(ErrorMessage.VALIDATION.getMessage(errors.size())); for (String s : errors) { message.append(s); } return create(message.toString()); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/exception/PropertyNotUniqueException.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.exception; import ai.grakn.concept.Concept; import ai.grakn.concept.Label; import ai.grakn.concept.RelationshipType; import ai.grakn.concept.SchemaConcept; import ai.grakn.util.Schema; import org.apache.tinkerpop.gremlin.structure.Element; import org.apache.tinkerpop.gremlin.structure.Vertex; import static ai.grakn.util.ErrorMessage.INVALID_UNIQUE_PROPERTY_MUTATION; import static ai.grakn.util.ErrorMessage.UNIQUE_PROPERTY_TAKEN; /** * <p> * Unique Concept Property Violation * </p> * * <p> * This occurs when attempting to add a globally unique property to a concept. * For example when creating a {@link ai.grakn.concept.EntityType} and {@link RelationshipType} using * the same {@link Label} * </p> * * @author fppt */ public class PropertyNotUniqueException extends GraknTxOperationException { private PropertyNotUniqueException(String error) { super(error); } public static PropertyNotUniqueException create(String error) { return new PropertyNotUniqueException(error); } /** * Thrown when trying to set the property of concept {@code mutatingConcept} to a {@code value} which is already * taken by concept {@code conceptWithValue} */ public static PropertyNotUniqueException cannotChangeProperty(Element mutatingConcept, Vertex conceptWithValue, Enum property, Object value){ return create(INVALID_UNIQUE_PROPERTY_MUTATION.getMessage(property, mutatingConcept, value, conceptWithValue)); } /** * Thrown when trying to create a {@link SchemaConcept} using a unique property which is already taken. * For example this happens when using an already taken {@link Label} */ public static PropertyNotUniqueException cannotCreateProperty(Concept concept, Schema.VertexProperty property, Object value){ return create(UNIQUE_PROPERTY_TAKEN.getMessage(property.name(), value, concept)); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/exception/TemporaryWriteException.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.exception; import org.apache.tinkerpop.gremlin.structure.Vertex; import static ai.grakn.util.ErrorMessage.LOCKING_EXCEPTION; /** * <p> * Mutation Exception * </p> * * <p> * This exception occurs when we are temporarily unable to write to the graph. * This is typically caused by the persistence layer being overloaded. * When this occurs the transaction should be retried * </p> * * @author fppt */ public class TemporaryWriteException extends GraknBackendException{ private TemporaryWriteException(String error, Exception e) { super(error, e); } /** * Thrown when the persistence layer is locked temporarily. * Retrying the transaction is reccomended. */ public static TemporaryWriteException temporaryLock(Exception e){ return new TemporaryWriteException(LOCKING_EXCEPTION.getMessage(), e); } /** * Thrown when multiple transactions overlap in using an index. This results in incomplete vertices being shared * between transactions. */ public static TemporaryWriteException indexOverlap(Vertex vertex, Exception e){ return new TemporaryWriteException(String.format("Index overlap has led to the accidental sharing of a partially complete vertex {%s}", vertex), e); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/exception/package-info.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ /** * Grakn exception definitions. */ package ai.grakn.exception;
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/Aggregate.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.graql.answer.Answer; import ai.grakn.graql.answer.ConceptMap; import javax.annotation.CheckReturnValue; import java.util.List; import java.util.stream.Stream; /** * An aggregate operation to perform on a query. * @param <T> the type of the result of the aggregate operation * * @author Felix Chapman */ public interface Aggregate<T extends Answer> { /** * The function to apply to the stream of results to produce the aggregate result. * @param stream a stream of query results * @return the result of the aggregate operation */ @CheckReturnValue List<T> apply(Stream<? extends ConceptMap> stream); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/AggregateQuery.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.GraknTx; import ai.grakn.graql.answer.Answer; import javax.annotation.Nullable; /** * An aggregate query produced from a {@link Match}. * * @param <T> the type of the result of the aggregate query * * @author Grakn Warriors */ public interface AggregateQuery<T extends Answer> extends Query<T> { @Override AggregateQuery<T> withTx(GraknTx tx); /** * Get the {@link Match} that this {@link AggregateQuery} will operate on. */ @Nullable Match match(); /** * Get the {@link Aggregate} that will be executed against the results of the {@link #match()}. */ Aggregate<T> aggregate(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/ComputeQuery.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.GraknTx; import ai.grakn.concept.ConceptId; import ai.grakn.concept.Label; import ai.grakn.exception.GraqlQueryException; import ai.grakn.graql.answer.Answer; import javax.annotation.CheckReturnValue; import java.util.Collection; import java.util.Optional; import java.util.Set; import static ai.grakn.util.GraqlSyntax.Compute.Algorithm; import static ai.grakn.util.GraqlSyntax.Compute.Argument; import static ai.grakn.util.GraqlSyntax.Compute.Method; import static ai.grakn.util.GraqlSyntax.Compute.Parameter; /** * Graql Compute Query: to perform distributed analytics OLAP computation on Grakn * @param <T> return type of ComputeQuery */ public interface ComputeQuery<T extends Answer> extends Query<T> { /** * @param tx the graph to execute the compute query on * @return a ComputeQuery with the graph set */ @Override ComputeQuery<T> withTx(GraknTx tx); /** * @param fromID is the Concept ID of in which compute path query will start from * @return A ComputeQuery with the fromID set */ ComputeQuery<T> from(ConceptId fromID); /** * @return a String representing the name of the compute query method */ Method method(); /** * @return a Concept ID in which which compute query will start from */ @CheckReturnValue Optional<ConceptId> from(); /** * @param toID is the Concept ID in which compute query will stop at * @return A ComputeQuery with the toID set */ ComputeQuery<T> to(ConceptId toID); /** * @return a Concept ID in which which compute query will stop at */ @CheckReturnValue Optional<ConceptId> to(); /** * @param types is an array of concept types in which the compute query would apply to * @return a ComputeQuery with the of set */ ComputeQuery<T> of(String type, String... types); /** * @param types is an array of concept types in which the compute query would apply to * @return a ComputeQuery with the of set */ ComputeQuery<T> of(Collection<Label> types); /** * @return the collection of concept types in which the compute query would apply to */ @CheckReturnValue Optional<Set<Label>> of(); /** * @param types is an array of concept types that determines the scope of graph for the compute query * @return a ComputeQuery with the inTypes set */ ComputeQuery<T> in(String type, String... types); /** * @param types is an array of concept types that determines the scope of graph for the compute query * @return a ComputeQuery with the inTypes set */ ComputeQuery<T> in(Collection<Label> types); /** * @return the collection of concept types that determines the scope of graph for the compute query */ @CheckReturnValue Optional<Set<Label>> in(); /** * @param algorithm name as an condition for the compute query * @return a ComputeQuery with algorithm condition set */ ComputeQuery<T> using(Algorithm algorithm); /** * @return the algorithm type for the compute query */ @CheckReturnValue Optional<Algorithm> using(); /** * @param arg is an argument that could provided to modify the compute query parameters * @param args is an array of arguments * @return a ComputeQuery with the arguments set */ ComputeQuery<T> where(Argument arg, Argument... args); /** * @param args is a list of arguments that could be provided to modify the compute query parameters * @return */ ComputeQuery<T> where(Collection<Argument> args); /** * @return an Arguments object containing all the provided individual arguments combined */ @CheckReturnValue Optional<Arguments> where(); /** * Allow analytics query to include attributes and their relationships * * @return a ComputeQuery with the inTypes set */ ComputeQuery<T> includeAttributes(boolean include); /** * Get if this query will include attributes and their relationships */ @CheckReturnValue boolean includesAttributes(); /** * @return a boolean representing whether this query is a valid Graql Compute query given the provided conditions */ @CheckReturnValue boolean isValid(); /** * @return any exception if the query is invalid */ @CheckReturnValue Optional<GraqlQueryException> getException(); /** * Checks Whether this query will modify the graph */ @Override default boolean isReadOnly() { return true; } /** * kill the compute query, terminate the job */ void kill(); /** * Argument inner interface to provide access Compute Query arguments * * @author Grakn Warriors */ interface Arguments { @CheckReturnValue Optional<?> getArgument(Parameter param); @CheckReturnValue Collection<Parameter> getParameters(); @CheckReturnValue Optional<Long> minK(); @CheckReturnValue Optional<Long> k(); @CheckReturnValue Optional<Long> size(); @CheckReturnValue Optional<ConceptId> contains(); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/DefineQuery.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.concept.SchemaConcept; import ai.grakn.graql.answer.ConceptMap; import java.util.Collection; /** * A query for defining {@link SchemaConcept}s. * <p> * The query will define all {@link SchemaConcept}s described in the {@link VarPattern}s provided and return an * {@link ConceptMap} containing bindings for all {@link Var}s in the {@link VarPattern}s. * </p> * * @author Felix Chapman */ public interface DefineQuery extends Query<ConceptMap> { /** * Get the {@link VarPattern}s describing what {@link SchemaConcept}s to define. */ Collection<? extends VarPattern> varPatterns(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/DeleteQuery.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.GraknTx; import ai.grakn.graql.admin.DeleteQueryAdmin; import ai.grakn.graql.answer.ConceptSet; import javax.annotation.CheckReturnValue; /** * A query for deleting concepts from a {@link Match}. * <p> * A {@link DeleteQuery} is built from a {@link Match} and will perform a delete operation for every result of * the {@link Match}. * <p> * The delete operation to perform is based on what {@link VarPattern} objects are provided to it. If only variable names * are provided, then the delete query will delete the concept bound to each given variable name. If property flags * are provided, e.g. {@code var("x").has("name")} then only those properties are deleted. * * @author Felix Chapman */ public interface DeleteQuery extends Query<ConceptSet> { /** * @param tx the graph to execute the query on * @return a new DeleteQuery with the graph set */ @Override DeleteQuery withTx(GraknTx tx); /** * @return admin instance for inspecting and manipulating this query */ @CheckReturnValue DeleteQueryAdmin admin(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/GetQuery.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.GraknTx; import ai.grakn.graql.answer.ConceptMap; import javax.annotation.CheckReturnValue; import java.util.Set; /** * A query used for finding data in a knowledge base that matches the given patterns. The {@link GetQuery} is a * pattern-matching query. The patterns are described in a declarative fashion, then the {@link GetQuery} will traverse * the knowledge base in an efficient fashion to find any matching answers. */ public interface GetQuery extends Query<ConceptMap> { /** * @param tx the transaction to execute the query on * @return a new {@link GetQuery} with the transaction set */ @Override GetQuery withTx(GraknTx tx); /** * Get the {@link Match} this {@link GetQuery} contains */ @CheckReturnValue Match match(); /** * Get the {@link Var}s this {@link GetQuery} will select from the answers */ @CheckReturnValue Set<Var> vars(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/InsertQuery.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.GraknTx; import ai.grakn.graql.admin.InsertQueryAdmin; import ai.grakn.graql.answer.ConceptMap; import javax.annotation.CheckReturnValue; /** * A query for inserting data. * <p> * A {@link InsertQuery} can be built from a {@link QueryBuilder} or a {@link Match}. * <p> * When built from a {@code QueryBuilder}, the insert query will execute once, inserting all the variables provided. * <p> * When built from a {@link Match}, the {@link InsertQuery} will execute for each result of the {@link Match}, * where variable names in the {@link InsertQuery} are bound to the concept in the result of the {@link Match}. * * @author Felix Chapman */ public interface InsertQuery extends Query<ConceptMap> { /** * @param tx the graph to execute the query on * @return a new InsertQuery with the graph set */ @Override InsertQuery withTx(GraknTx tx); /** * @return admin instance for inspecting and manipulating this query */ @CheckReturnValue InsertQueryAdmin admin(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/Match.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.GraknTx; import ai.grakn.graql.admin.MatchAdmin; import ai.grakn.graql.answer.Answer; import ai.grakn.graql.answer.ConceptMap; import javax.annotation.CheckReturnValue; import java.util.Collection; import java.util.Iterator; import java.util.Set; import java.util.stream.Stream; /** * a part of a query used for finding data in a knowledge base that matches the given patterns. * <p> * The {@link Match} is the pattern-matching part of a query. The patterns are described in a declarative fashion, * then the {@link Match} will traverse the knowledge base in an efficient fashion to find any matching answers. * <p> * @see ConceptMap * * @author Felix Chapman */ public interface Match extends Iterable<ConceptMap> { /** * @return iterator over match results */ @Override @CheckReturnValue default Iterator<ConceptMap> iterator() { return stream().iterator(); } /** * @return a stream of match results */ @CheckReturnValue Stream<ConceptMap> stream(); /** * Construct a get query with all all {@link Var}s mentioned in the query */ @CheckReturnValue GetQuery get(); /** * @param vars an array of variables to select * @return a {@link GetQuery} that selects the given variables */ @CheckReturnValue GetQuery get(String var, String... vars); /** * @param vars an array of {@link Var}s to select * @return a {@link GetQuery} that selects the given variables */ @CheckReturnValue GetQuery get(Var var, Var... vars); /** * @param vars a set of {@link Var}s to select * @return a {@link GetQuery} that selects the given variables */ @CheckReturnValue GetQuery get(Set<Var> vars); /** * @param vars an array of variables to insert for each result of this {@link Match} * @return an insert query that will insert the given variables for each result of this {@link Match} */ @CheckReturnValue InsertQuery insert(VarPattern... vars); /** * @param vars a collection of variables to insert for each result of this {@link Match} * @return an insert query that will insert the given variables for each result of this {@link Match} */ @CheckReturnValue InsertQuery insert(Collection<? extends VarPattern> vars); /** * Construct a delete query with all all {@link Var}s mentioned in the query */ @CheckReturnValue DeleteQuery delete(); /** * @param vars an array of variables to delete for each result of this {@link Match} * @return a delete query that will delete the given variables for each result of this {@link Match} */ @CheckReturnValue DeleteQuery delete(String var, String... vars); /** * @param vars an array of variables to delete for each result of this {@link Match} * @return a delete query that will delete the given variables for each result of this {@link Match} */ @CheckReturnValue DeleteQuery delete(Var var, Var... vars); /** * @param vars a collection of variables to delete for each result of this {@link Match} * @return a delete query that will delete the given variables for each result of this {@link Match} */ @CheckReturnValue DeleteQuery delete(Set<Var> vars); /** * Order the results by degree in ascending order * @param varName the variable name to order the results by * @return a new {@link Match} with the given ordering */ @CheckReturnValue Match orderBy(String varName); /** * Order the results by degree in ascending order * @param varName the variable name to order the results by * @return a new {@link Match} with the given ordering */ @CheckReturnValue Match orderBy(Var varName); /** * Order the results by degree * @param varName the variable name to order the results by * @param order the ordering to use * @return a new {@link Match} with the given ordering */ @CheckReturnValue Match orderBy(String varName, Order order); /** * Order the results by degree * @param varName the variable name to order the results by * @param order the ordering to use * @return a new {@link Match} with the given ordering */ @CheckReturnValue Match orderBy(Var varName, Order order); /** * @param tx the graph to execute the query on * @return a new {@link Match} with the graph set */ Match withTx(GraknTx tx); /** * @param limit the maximum number of results the query should return * @return a new {@link Match} with the limit set */ @CheckReturnValue Match limit(long limit); /** * @param offset the number of results to skip * @return a new {@link Match} with the offset set */ @CheckReturnValue Match offset(long offset); /** * Aggregate results of a query. * @param aggregate the aggregate operation to apply * @param <T> the type of the aggregate result * @return a query that will yield the aggregate result */ @CheckReturnValue <T extends Answer> AggregateQuery<T> aggregate(Aggregate<T> aggregate); /** * @return admin instance for inspecting and manipulating this query */ @CheckReturnValue MatchAdmin admin(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/Order.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; /** * Ordering for {@link Match} results * * @author Felix Chapman */ public enum Order { /** * Ascending order */ asc, /** * Descending order */ desc }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/Pattern.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.graql.admin.PatternAdmin; import javax.annotation.CheckReturnValue; /** * A pattern describing a subgraph. * <p> * A {@code Pattern} can describe an entire graph, or just a single concept. * <p> * For example, {@code var("x").isa("movie")} is a pattern representing things that are movies. * <p> * A pattern can also be a conjunction: {@code and(var("x").isa("movie"), var("x").value("Titanic"))}, or a disjunction: * {@code or(var("x").isa("movie"), var("x").isa("tv-show"))}. These can be used to combine other patterns together * into larger patterns. * * @author Felix Chapman */ public interface Pattern { /** * @return an Admin class that allows inspecting or manipulating this pattern */ @CheckReturnValue PatternAdmin admin(); /** * Join patterns in a conjunction */ @CheckReturnValue Pattern and(Pattern pattern); /** * Join patterns in a disjunction */ @CheckReturnValue Pattern or(Pattern pattern); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/Query.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.GraknTx; import ai.grakn.QueryExecutor; import ai.grakn.exception.GraqlQueryException; import ai.grakn.graql.answer.Answer; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; /** * A Graql query of any kind. May read and write to the graph. * * @param <T> The result type after executing the query * * @author Grakn Warriors */ public interface Query<T extends Answer> extends Iterable<T> { /** * @param tx the graph to execute the query on * @return a new query with the graph set */ @CheckReturnValue Query<T> withTx(GraknTx tx); /** * @return a {@link Stream} of T, where T is a special type of {@link Answer} */ @CheckReturnValue Stream<T> stream(); /** * @return a {@link List} of T, where T is a special type of {@link Answer} */ @CheckReturnValue default List<T> execute() { return stream().collect(Collectors.toList()); } /** * @return an {@link Iterator} of T, where T is a special type of {@link Answer} */ @Override @CheckReturnValue default Iterator<T> iterator() { return stream().iterator(); } /** * @return the special type of {@link QueryExecutor}, depending on whether the query is executed on the client or * server side. */ default QueryExecutor executor() { if (tx() == null) throw GraqlQueryException.noTx(); return tx().admin().queryExecutor(); } /** * @return boolean that indicates whether this query will modify the graph */ @CheckReturnValue boolean isReadOnly(); /** * @return the transaction {@link GraknTx} associated with this query */ @Nullable GraknTx tx(); /** * @return boolean that indicates whether this query will perform rule-based inference during execution */ Boolean inferring(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/QueryBuilder.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.concept.SchemaConcept; import ai.grakn.graql.answer.Answer; import javax.annotation.CheckReturnValue; import java.util.Collection; import static ai.grakn.util.GraqlSyntax.Compute.Method; /** * Starting point for creating queries * * @author Felix Chapman */ public interface QueryBuilder { /** * @param patterns an array of patterns to match in the graph * @return a {@link Match} that will find matches of the given patterns */ @CheckReturnValue Match match(Pattern... patterns); /** * @param patterns a collection of patterns to match in the graph * @return a {@link Match} that will find matches of the given patterns */ @CheckReturnValue Match match(Collection<? extends Pattern> 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 */ @CheckReturnValue InsertQuery insert(VarPattern... 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 */ @CheckReturnValue InsertQuery insert(Collection<? extends VarPattern> vars); /** * @param varPatterns an array of {@link VarPattern}s defining {@link SchemaConcept}s * @return a {@link DefineQuery} that will apply the changes described in the {@code patterns} */ @CheckReturnValue DefineQuery define(VarPattern... varPatterns); /** * @param varPatterns a collection of {@link VarPattern}s defining {@link SchemaConcept}s * @return a {@link DefineQuery} that will apply the changes described in the {@code patterns} */ @CheckReturnValue DefineQuery define(Collection<? extends VarPattern> varPatterns); /** * @param varPatterns an array of {@link VarPattern}s defining {@link SchemaConcept}s to undefine * @return an {@link UndefineQuery} that will remove the changes described in the {@code varPatterns} */ @CheckReturnValue UndefineQuery undefine(VarPattern... varPatterns); /** * @param varPatterns a collection of {@link VarPattern}s defining {@link SchemaConcept}s to undefine * @return an {@link UndefineQuery} that will remove the changes described in the {@code varPatterns} */ @CheckReturnValue UndefineQuery undefine(Collection<? extends VarPattern> varPatterns); /** * @return a compute query builder for building analytics query */ @CheckReturnValue <T extends Answer> ComputeQuery<T> compute(Method<T> method); /** * Get a {@link QueryParser} for parsing queries from strings */ QueryParser parser(); /** * @param queryString a string representing a query * @return a query, the type will depend on the type of query. */ @CheckReturnValue <T extends Query<?>> T parse(String queryString); /** * Enable or disable inference */ QueryBuilder infer(boolean infer); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/QueryParser.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import java.io.Reader; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Stream; /** * Class for parsing query strings into valid queries * * @author Felix Chapman */ public interface QueryParser { /** * @param queryString a string representing a query * @return * a query, the type will depend on the type of query. */ @SuppressWarnings("unchecked") <T extends Query<?>> T parseQuery(String queryString); /** * @param reader a reader representing several queries * @return a stream of query objects */ <T extends Query<?>> Stream<T> parseReader(Reader reader); /** * @param queryString a string representing several queries * @return a stream of query objects */ <T extends Query<?>> Stream<T> parseList(String queryString); /** * @param patternsString a string representing a list of patterns * @return a list of patterns */ List<Pattern> parsePatterns(String patternsString); /** * @param patternString a string representing a pattern * @return a pattern */ Pattern parsePattern(String patternString); /** * @param template a string representing a templated graql query * @param data data to use in template * @return a resolved graql query */ <T extends Query<?>> Stream<T> parseTemplate(String template, Map<String, Object> data); /** * Register an aggregate that can be used when parsing a Graql query * @param name the name of the aggregate * @param aggregateMethod a function that will produce an aggregate when passed a list of arguments */ void registerAggregate(String name, Function<List<Object>, Aggregate> aggregateMethod); /** * Set whether the parser should set all {@link Var}s as user-defined. If it does, then every variable will * generate a user-defined name and be returned in results. For example: * <pre> * match ($x, $y); * </pre> * * The previous query would normally return only two concepts per result for {@code $x} and {@code $y}. However, * if the flag is set it will also return a third variable with a random name representing the relation * {@code $123 ($x, $y)}. */ void defineAllVars(boolean defineAllVars); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/UndefineQuery.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.GraknTx; import ai.grakn.concept.SchemaConcept; import ai.grakn.graql.answer.ConceptMap; import java.util.Collection; /** * A query for undefining {@link SchemaConcept}s. * <p> * The query will undefine all {@link SchemaConcept}s described in the {@link VarPattern}s provided. * </p> * * @author Felix Chapman */ public interface UndefineQuery extends Query<ConceptMap> { @Override UndefineQuery withTx(GraknTx tx); /** * Get the {@link VarPattern}s describing what {@link SchemaConcept}s to define. */ Collection<? extends VarPattern> varPatterns(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/ValuePredicate.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.graql.admin.VarPatternAdmin; import org.apache.tinkerpop.gremlin.process.traversal.P; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import javax.annotation.CheckReturnValue; import java.util.Optional; /** * a atom on a value in a query. * <p> * A atom describes a atom (true/false) function that can be tested against some value in the graph. * <p> * Predicates can be combined together using the methods {@code and}, {@code or}, {@code any} and {@code all}. * * @author Felix Chapman */ public interface ValuePredicate { /** * @return whether this predicate is specific (e.g. "eq" is specific, "regex" is not) */ @CheckReturnValue default boolean isSpecific() { return false; } /** * @param predicate to be compared in terms of compatibility * @return true if compatible */ @CheckReturnValue boolean isCompatibleWith(ValuePredicate predicate); /** * @return the value comparing against, if this is an "equality" predicate, otherwise nothing */ @CheckReturnValue default Optional<Object> equalsValue() { return Optional.empty(); } /** * @return the gremlin predicate object this ValuePredicate wraps */ @CheckReturnValue Optional<P<Object>> getPredicate(); /** * Get the inner variable that this predicate refers to, if one is present * @return the inner variable that this predicate refers to, if one is present */ @CheckReturnValue Optional<VarPatternAdmin> getInnerVar(); /** * Apply the predicate to the gremlin traversal, so the traversal will filter things that don't meet the predicate * @param traversal the traversal to apply the predicate to */ <S, E> GraphTraversal<S, E> applyPredicate(GraphTraversal<S, E> traversal); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/Var.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; /** * A variable in a Graql query * * @author Felix Chapman */ public interface Var extends VarPattern { /** * Get the string name of the variable (without prefixed "$") */ String getValue(); /** * The {@link Kind} of the {@link Var}, such as whether it is user-defined. */ Kind kind(); /** * Whether the variable has been manually defined or automatically generated. * @return whether the variable has been manually defined or automatically generated. */ boolean isUserDefinedName(); /** * Transform the variable into a user-defined one, retaining the generated name. * * This is useful for "reifying" an existing variable. * * @return a new variable with the same name as the previous, but set as user-defined. */ Var asUserDefined(); /** * Get a unique name identifying the variable, differentiating user-defined variables from generated ones. */ String name(); /** * Get a shorter representation of the variable (with prefixed "$") */ String shortName(); String toString(); @Override boolean equals(Object o); @Override int hashCode(); /** * The {@link Kind} of a {@link Var}, such as whether it is user-defined. */ enum Kind { UserDefined { @Override public char prefix() { return '§'; } }, Generated { @Override public char prefix() { return '#'; } }, Reserved { @Override public char prefix() { return '!'; } }; public abstract char prefix(); } }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/VarPattern.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql; import ai.grakn.API; import ai.grakn.concept.Attribute; import ai.grakn.concept.AttributeType; import ai.grakn.concept.ConceptId; import ai.grakn.concept.Label; import ai.grakn.concept.Relationship; import ai.grakn.concept.Role; import ai.grakn.graql.admin.VarPatternAdmin; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; /** * A variable together with its properties. * <p> * A {@link VarPattern} may be given a variable, or use an "anonymous" variable. {@code Graql} provides * static methods for constructing {@link VarPattern} objects. * <p> * The methods on {@link VarPattern} are used to set its properties. A {@link VarPattern} behaves differently depending * on the type of query its used in. In a {@link Match}, a {@link VarPattern} describes the properties any matching * concept must have. In an {@link InsertQuery}, it describes the properties that should be set on the inserted concept. * In a {@link DeleteQuery}, it describes the properties that should be deleted. * * @author Felix Chapman */ @SuppressWarnings("UnusedReturnValue") public interface VarPattern extends Pattern { /** * @return an Admin class to allow inspection of this {@link VarPattern} */ @CheckReturnValue VarPatternAdmin admin(); /** * @param id a ConceptId that this variable's ID must match * @return this */ @CheckReturnValue VarPattern id(ConceptId id); /** * @param label a string that this variable's label must match * @return this */ @CheckReturnValue VarPattern label(String label); /** * @param label a type label that this variable's label must match * @return this */ @CheckReturnValue VarPattern label(Label label); /** * @param value a value that this variable's value must exactly match * @return this */ @CheckReturnValue VarPattern val(Object value); /** * @param predicate a atom this variable's value must match * @return this */ @CheckReturnValue VarPattern val(ValuePredicate predicate); /** * the variable must have a resource of the given type with an exact matching value * * @param type a resource type in the schema * @param value a value of a resource * @return this */ @CheckReturnValue VarPattern has(String type, Object value); /** * the variable must have a resource of the given type that matches the given atom * * @param type a resource type in the schema * @param predicate a atom on the value of a resource * @return this */ @CheckReturnValue VarPattern has(String type, ValuePredicate predicate); /** * the variable must have an {@link Attribute} of the given type that matches the given atom * * @param type a resource type in the schema * @param attribute a variable pattern representing an {@link Attribute} * @return this */ @CheckReturnValue VarPattern has(String type, VarPattern attribute); /** * the variable must have an {@link Attribute} of the given type that matches the given atom * * @param type a resource type in the schema * @param attribute a variable pattern representing an {@link Attribute} * @return this */ @CheckReturnValue VarPattern has(Label type, VarPattern attribute); /** * the variable must have an {@link Attribute} of the given type that matches {@code resource}. * The {@link Relationship} associating the two must match {@code relation}. * * @param type a resource type in the ontology * @param attribute a variable pattern representing an {@link Attribute} * @param relationship a variable pattern representing a {@link Relationship} * @return this */ @CheckReturnValue VarPattern has(Label type, VarPattern attribute, VarPattern relationship); /** * @param type a concept type id that the variable must be of this type directly or indirectly * @return this */ @CheckReturnValue VarPattern isa(String type); /** * @param type a concept type that this variable must be an instance of directly or indirectly * @return this */ @CheckReturnValue VarPattern isa(VarPattern type); /** * @param type a concept type id that the variable must be of this type directly * @return this */ @CheckReturnValue VarPattern isaExplicit(String type); /** * @param type a concept type that this variable must be an instance of directly * @return this */ @CheckReturnValue VarPattern isaExplicit(VarPattern type); /** * @param type a concept type id that this variable must be a kind of * @return this */ @CheckReturnValue VarPattern sub(String type); /** * @param type a concept type that this variable must be a kind of * @return this */ @CheckReturnValue VarPattern sub(VarPattern type); /** * @param type a {@link Role} id that this relation type variable must have * @return this */ @CheckReturnValue VarPattern relates(String type); /** * @param type a {@link Role} that this relation type variable must have * @return this */ @CheckReturnValue VarPattern relates(VarPattern type); /** * @param roleType a {@link Role} id that this relation type variable must have * @return this */ @CheckReturnValue VarPattern relates(String roleType, @Nullable String superRoleType); /** * @param roleType a {@link Role} that this relation type variable must have * @return this */ @CheckReturnValue VarPattern relates(VarPattern roleType, @Nullable VarPattern superRoleType); /** * @param type a {@link Role} id that this concept type variable must play * @return this */ @CheckReturnValue VarPattern plays(String type); /** * @param type a {@link Role} that this concept type variable must play * @return this */ @CheckReturnValue VarPattern plays(VarPattern type); /** * @param type a resource type that this type variable can be related to * @return this */ @CheckReturnValue VarPattern has(String type); /** * @param type a resource type that this type variable can be related to * @return this */ @CheckReturnValue VarPattern has(VarPattern type); /** * @param type a resource type that this type variable can be one-to-one related to * @return this */ @CheckReturnValue VarPattern key(String type); /** * @param type a resource type that this type variable can be one-to-one related to * @return this */ @CheckReturnValue VarPattern key(VarPattern type); /** * the variable must be a relation with the given roleplayer * * @param roleplayer a variable representing a roleplayer * @return this */ @CheckReturnValue VarPattern rel(String roleplayer); /** * the variable must be a relation with the given roleplayer * * @param roleplayer a variable pattern representing a roleplayer * @return this */ @CheckReturnValue VarPattern rel(VarPattern roleplayer); /** * the variable must be a relation with the given roleplayer playing the given {@link Role} * * @param role a {@link Role} in the schema * @param roleplayer a variable representing a roleplayer * @return this */ @CheckReturnValue VarPattern rel(String role, String roleplayer); /** * the variable must be a relation with the given roleplayer playing the given {@link Role} * * @param role a variable pattern representing a {@link Role} * @param roleplayer a variable representing a roleplayer * @return this */ @CheckReturnValue VarPattern rel(VarPattern role, String roleplayer); /** * the variable must be a relation with the given roleplayer playing the given {@link Role} * * @param role a {@link Role} in the schema * @param roleplayer a variable pattern representing a roleplayer * @return this */ @CheckReturnValue VarPattern rel(String role, VarPattern roleplayer); /** * the variable must be a relation with the given roleplayer playing the given {@link Role} * * @param role a variable pattern representing a {@link Role} * @param roleplayer a variable pattern representing a roleplayer * @return this */ @CheckReturnValue VarPattern rel(VarPattern role, VarPattern roleplayer); /** * set this concept type variable as abstract, meaning it cannot have direct instances * * @return this */ @CheckReturnValue VarPattern isAbstract(); /** * @param datatype the datatype to set for this resource type variable * @return this */ @CheckReturnValue VarPattern datatype(AttributeType.DataType<?> datatype); /** * Specify the regular expression instances of this resource type must match * * @param regex the regex to set for this resource type variable * @return this */ @CheckReturnValue VarPattern regex(String regex); /** * @param when the left-hand side of this rule * @return this */ @CheckReturnValue VarPattern when(Pattern when); /** * @param then the right-hand side of this rule * @return this */ @CheckReturnValue VarPattern then(Pattern then); /** * Specify that the variable is different to another variable * * @param var the variable that this variable should not be equal to * @return this */ @API @CheckReturnValue VarPattern neq(String var); /** * Specify that the variable is different to another variable * * @param varPattern the variable pattern that this variable should not be equal to * @return this */ @API @CheckReturnValue VarPattern neq(VarPattern varPattern); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/package-info.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ /** * A collection of interfaces and factories for executing Graql queries. */ package ai.grakn.graql;
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/admin/Atomic.java
/* * GRAKN.AI - THE KNOWLEDGE GRAPH * Copyright (C) 2018 Grakn Labs Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package ai.grakn.graql.admin; import ai.grakn.concept.Rule; import ai.grakn.graql.Pattern; import ai.grakn.graql.Var; import ai.grakn.graql.VarPattern; import javax.annotation.CheckReturnValue; import java.util.HashSet; import java.util.Set; /** * * <p> * Basic interface for logical atoms used in reasoning. * </p> * * @author Kasper Piskorski * */ public interface Atomic { @CheckReturnValue Atomic copy(ReasonerQuery parent); /** * @return variable name of this atomic */ @CheckReturnValue Var getVarName(); /** * @return the corresponding base pattern * */ @CheckReturnValue VarPattern getPattern(); /** * @return the {@link ReasonerQuery} this atomic belongs to */ ReasonerQuery getParentQuery(); /** * validate wrt transaction the atomic is defined in */ void checkValid(); /** * @return true if the atomic corresponds to a atom * */ @CheckReturnValue default boolean isAtom(){ return false;} /** * @return true if the atomic corresponds to a type atom * */ @CheckReturnValue default boolean isType(){ return false;} /** * @return true if the atomic corresponds to a relation atom * */ @CheckReturnValue default boolean isRelation(){return false;} /** * @return true if the atomic corresponds to a resource atom * */ default boolean isResource(){ return false;} /** * @return true if obj alpha-equivalent */ @CheckReturnValue boolean isAlphaEquivalent(Object obj); /** * @return true if obj structurally equivalent */ @CheckReturnValue boolean isStructurallyEquivalent(Object obj); /** * @return true if obj compatible */ @CheckReturnValue default boolean isCompatibleWith(Object obj){return isAlphaEquivalent(obj);} /** * @return alpha-equivalence hash code */ @CheckReturnValue int alphaEquivalenceHashCode(); /** * @return structural-equivalence hash code */ @CheckReturnValue int structuralEquivalenceHashCode(); /** * @return true if the atomic can form an atomic query */ @CheckReturnValue default boolean isSelectable(){ return false;} /** * @return true if the atomic can constitute the head of a rule */ @CheckReturnValue Set<String> validateAsRuleHead(Rule rule); /** * @return error messages indicating ontological inconsistencies of this atomic */ @CheckReturnValue default Set<String> validateOntologically(){ return new HashSet<>();} /** * @return the base pattern combined with possible predicate patterns */ @CheckReturnValue Pattern getCombinedPattern(); /** * @return all addressable variable names in this atomic */ @CheckReturnValue Set<Var> getVarNames(); /** * infers types (type, role types) for the atom if applicable/possible * @return either this atom if nothing could be inferred or a fresh atom with inferred types */ @CheckReturnValue Atomic inferTypes(); }
0
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql
java-sources/ai/grakn/grakn-core/1.4.3/ai/grakn/graql/admin/AutoValue_RelationPlayer.java
package ai.grakn.graql.admin; import java.util.Optional; import javax.annotation.CheckReturnValue; import javax.annotation.Generated; @Generated("com.google.auto.value.processor.AutoValueProcessor") final class AutoValue_RelationPlayer extends RelationPlayer { private final Optional<VarPatternAdmin> role; private final VarPatternAdmin rolePlayer; AutoValue_RelationPlayer( Optional<VarPatternAdmin> role, VarPatternAdmin rolePlayer) { if (role == null) { throw new NullPointerException("Null role"); } this.role = role; if (rolePlayer == null) { throw new NullPointerException("Null rolePlayer"); } this.rolePlayer = rolePlayer; } @CheckReturnValue @Override public Optional<VarPatternAdmin> getRole() { return role; } @CheckReturnValue @Override public VarPatternAdmin getRolePlayer() { return rolePlayer; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RelationPlayer) { RelationPlayer that = (RelationPlayer) o; return (this.role.equals(that.getRole())) && (this.rolePlayer.equals(that.getRolePlayer())); } return false; } @Override public int hashCode() { int h = 1; h *= 1000003; h ^= this.role.hashCode(); h *= 1000003; h ^= this.rolePlayer.hashCode(); return h; } }