id int32 0 165k | repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 |
|---|---|---|---|---|---|---|---|---|---|---|---|
22,900 | graknlabs/grakn | server/src/graql/executor/ComputeExecutor.java | ComputeExecutor.scopeTypeLabels | private ImmutableSet<Label> scopeTypeLabels(GraqlCompute query) {
return scopeTypes(query).map(SchemaConcept::label).collect(CommonUtil.toImmutableSet());
} | java | private ImmutableSet<Label> scopeTypeLabels(GraqlCompute query) {
return scopeTypes(query).map(SchemaConcept::label).collect(CommonUtil.toImmutableSet());
} | [
"private",
"ImmutableSet",
"<",
"Label",
">",
"scopeTypeLabels",
"(",
"GraqlCompute",
"query",
")",
"{",
"return",
"scopeTypes",
"(",
"query",
")",
".",
"map",
"(",
"SchemaConcept",
"::",
"label",
")",
".",
"collect",
"(",
"CommonUtil",
".",
"toImmutableSet",
"(",
")",
")",
";",
"}"
] | Helper method to get the labels of the type in the query scope
@return a set of Concept Type Labels | [
"Helper",
"method",
"to",
"get",
"the",
"labels",
"of",
"the",
"type",
"in",
"the",
"query",
"scope"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/executor/ComputeExecutor.java#L765-L767 |
22,901 | graknlabs/grakn | server/src/graql/executor/ComputeExecutor.java | ComputeExecutor.scopeContainsInstance | private boolean scopeContainsInstance(GraqlCompute query) {
if (scopeTypeLabels(query).isEmpty()) return false;
List<Pattern> checkSubtypes = scopeTypeLabels(query).stream()
.map(type -> Graql.var("x").isa(Graql.type(type.getValue()))).collect(Collectors.toList());
return tx.stream(Graql.match(Graql.or(checkSubtypes)), false).iterator().hasNext();
} | java | private boolean scopeContainsInstance(GraqlCompute query) {
if (scopeTypeLabels(query).isEmpty()) return false;
List<Pattern> checkSubtypes = scopeTypeLabels(query).stream()
.map(type -> Graql.var("x").isa(Graql.type(type.getValue()))).collect(Collectors.toList());
return tx.stream(Graql.match(Graql.or(checkSubtypes)), false).iterator().hasNext();
} | [
"private",
"boolean",
"scopeContainsInstance",
"(",
"GraqlCompute",
"query",
")",
"{",
"if",
"(",
"scopeTypeLabels",
"(",
"query",
")",
".",
"isEmpty",
"(",
")",
")",
"return",
"false",
";",
"List",
"<",
"Pattern",
">",
"checkSubtypes",
"=",
"scopeTypeLabels",
"(",
"query",
")",
".",
"stream",
"(",
")",
".",
"map",
"(",
"type",
"->",
"Graql",
".",
"var",
"(",
"\"x\"",
")",
".",
"isa",
"(",
"Graql",
".",
"type",
"(",
"type",
".",
"getValue",
"(",
")",
")",
")",
")",
".",
"collect",
"(",
"Collectors",
".",
"toList",
"(",
")",
")",
";",
"return",
"tx",
".",
"stream",
"(",
"Graql",
".",
"match",
"(",
"Graql",
".",
"or",
"(",
"checkSubtypes",
")",
")",
",",
"false",
")",
".",
"iterator",
"(",
")",
".",
"hasNext",
"(",
")",
";",
"}"
] | Helper method to check whether the concept types in the scope have any instances
@return | [
"Helper",
"method",
"to",
"check",
"whether",
"the",
"concept",
"types",
"in",
"the",
"scope",
"have",
"any",
"instances"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/executor/ComputeExecutor.java#L775-L781 |
22,902 | graknlabs/grakn | server/src/graql/executor/ComputeExecutor.java | ComputeExecutor.scopeContainsInstances | private boolean scopeContainsInstances(GraqlCompute query, ConceptId... ids) {
for (ConceptId id : ids) {
Thing thing = tx.getConcept(id);
if (thing == null || !scopeTypeLabels(query).contains(thing.type().label())) return false;
}
return true;
} | java | private boolean scopeContainsInstances(GraqlCompute query, ConceptId... ids) {
for (ConceptId id : ids) {
Thing thing = tx.getConcept(id);
if (thing == null || !scopeTypeLabels(query).contains(thing.type().label())) return false;
}
return true;
} | [
"private",
"boolean",
"scopeContainsInstances",
"(",
"GraqlCompute",
"query",
",",
"ConceptId",
"...",
"ids",
")",
"{",
"for",
"(",
"ConceptId",
"id",
":",
"ids",
")",
"{",
"Thing",
"thing",
"=",
"tx",
".",
"getConcept",
"(",
"id",
")",
";",
"if",
"(",
"thing",
"==",
"null",
"||",
"!",
"scopeTypeLabels",
"(",
"query",
")",
".",
"contains",
"(",
"thing",
".",
"type",
"(",
")",
".",
"label",
"(",
")",
")",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Helper method to check if concept instances exist in the query scope
@param ids
@return true if they exist, false if they don't | [
"Helper",
"method",
"to",
"check",
"if",
"concept",
"instances",
"exist",
"in",
"the",
"query",
"scope"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/executor/ComputeExecutor.java#L789-L795 |
22,903 | graknlabs/grakn | server/src/graql/executor/ComputeExecutor.java | ComputeExecutor.scopeIncludesImplicitOrAttributeTypes | private boolean scopeIncludesImplicitOrAttributeTypes(GraqlCompute query) {
if (query.in().isEmpty()) return false;
return query.in().stream().anyMatch(t -> {
Label label = Label.of(t);
SchemaConcept type = tx.getSchemaConcept(label);
return (type != null && (type.isAttributeType() || type.isImplicit()));
});
} | java | private boolean scopeIncludesImplicitOrAttributeTypes(GraqlCompute query) {
if (query.in().isEmpty()) return false;
return query.in().stream().anyMatch(t -> {
Label label = Label.of(t);
SchemaConcept type = tx.getSchemaConcept(label);
return (type != null && (type.isAttributeType() || type.isImplicit()));
});
} | [
"private",
"boolean",
"scopeIncludesImplicitOrAttributeTypes",
"(",
"GraqlCompute",
"query",
")",
"{",
"if",
"(",
"query",
".",
"in",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"return",
"false",
";",
"return",
"query",
".",
"in",
"(",
")",
".",
"stream",
"(",
")",
".",
"anyMatch",
"(",
"t",
"->",
"{",
"Label",
"label",
"=",
"Label",
".",
"of",
"(",
"t",
")",
";",
"SchemaConcept",
"type",
"=",
"tx",
".",
"getSchemaConcept",
"(",
"label",
")",
";",
"return",
"(",
"type",
"!=",
"null",
"&&",
"(",
"type",
".",
"isAttributeType",
"(",
")",
"||",
"type",
".",
"isImplicit",
"(",
")",
")",
")",
";",
"}",
")",
";",
"}"
] | Helper method to check whether implicit or attribute types are included in the query scope
@return true if they exist, false if they don't | [
"Helper",
"method",
"to",
"check",
"whether",
"implicit",
"or",
"attribute",
"types",
"are",
"included",
"in",
"the",
"query",
"scope"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/executor/ComputeExecutor.java#L811-L818 |
22,904 | graknlabs/grakn | server/src/graql/executor/ComputeExecutor.java | ComputeExecutor.convertLabelsToIds | private Set<LabelId> convertLabelsToIds(Set<Label> labelSet) {
return labelSet.stream()
.map(tx::convertToId)
.filter(LabelId::isValid)
.collect(toSet());
} | java | private Set<LabelId> convertLabelsToIds(Set<Label> labelSet) {
return labelSet.stream()
.map(tx::convertToId)
.filter(LabelId::isValid)
.collect(toSet());
} | [
"private",
"Set",
"<",
"LabelId",
">",
"convertLabelsToIds",
"(",
"Set",
"<",
"Label",
">",
"labelSet",
")",
"{",
"return",
"labelSet",
".",
"stream",
"(",
")",
".",
"map",
"(",
"tx",
"::",
"convertToId",
")",
".",
"filter",
"(",
"LabelId",
"::",
"isValid",
")",
".",
"collect",
"(",
"toSet",
"(",
")",
")",
";",
"}"
] | Helper method to convert type labels to IDs
@param labelSet
@return a set of LabelIds | [
"Helper",
"method",
"to",
"convert",
"type",
"labels",
"to",
"IDs"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/executor/ComputeExecutor.java#L826-L831 |
22,905 | graknlabs/grakn | server/src/graql/analytics/KCoreVertexProgram.java | KCoreVertexProgram.getMessageCountExcludeSelf | private static int getMessageCountExcludeSelf(Messenger<String> messenger, String id) {
Set<String> messageSet = newHashSet(messenger.receiveMessages());
messageSet.remove(id);
return messageSet.size();
} | java | private static int getMessageCountExcludeSelf(Messenger<String> messenger, String id) {
Set<String> messageSet = newHashSet(messenger.receiveMessages());
messageSet.remove(id);
return messageSet.size();
} | [
"private",
"static",
"int",
"getMessageCountExcludeSelf",
"(",
"Messenger",
"<",
"String",
">",
"messenger",
",",
"String",
"id",
")",
"{",
"Set",
"<",
"String",
">",
"messageSet",
"=",
"newHashSet",
"(",
"messenger",
".",
"receiveMessages",
"(",
")",
")",
";",
"messageSet",
".",
"remove",
"(",
"id",
")",
";",
"return",
"messageSet",
".",
"size",
"(",
")",
";",
"}"
] | count the messages from relations, so need to filter its own msg | [
"count",
"the",
"messages",
"from",
"relations",
"so",
"need",
"to",
"filter",
"its",
"own",
"msg"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/analytics/KCoreVertexProgram.java#L215-L219 |
22,906 | graknlabs/grakn | server/src/server/exception/TemporaryWriteException.java | TemporaryWriteException.indexOverlap | 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);
} | java | 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);
} | [
"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",
")",
";",
"}"
] | Thrown when multiple transactions overlap in using an index. This results in incomplete vertices being shared
between transactions. | [
"Thrown",
"when",
"multiple",
"transactions",
"overlap",
"in",
"using",
"an",
"index",
".",
"This",
"results",
"in",
"incomplete",
"vertices",
"being",
"shared",
"between",
"transactions",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/exception/TemporaryWriteException.java#L54-L56 |
22,907 | graknlabs/grakn | server/src/server/exception/TransactionException.java | TransactionException.addingInstancesToAbstractType | public static TransactionException addingInstancesToAbstractType(Type type) {
return create(ErrorMessage.IS_ABSTRACT.getMessage(type.label()));
} | java | public static TransactionException addingInstancesToAbstractType(Type type) {
return create(ErrorMessage.IS_ABSTRACT.getMessage(type.label()));
} | [
"public",
"static",
"TransactionException",
"addingInstancesToAbstractType",
"(",
"Type",
"type",
")",
"{",
"return",
"create",
"(",
"ErrorMessage",
".",
"IS_ABSTRACT",
".",
"getMessage",
"(",
"type",
".",
"label",
"(",
")",
")",
")",
";",
"}"
] | Throw when trying to add instances to an abstract Type | [
"Throw",
"when",
"trying",
"to",
"add",
"instances",
"to",
"an",
"abstract",
"Type"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/exception/TransactionException.java#L86-L88 |
22,908 | graknlabs/grakn | server/src/server/exception/TransactionException.java | TransactionException.hasNotAllowed | public static TransactionException hasNotAllowed(Thing thing, Attribute attribute) {
return create(HAS_INVALID.getMessage(thing.type().label(), attribute.type().label()));
} | java | public static TransactionException hasNotAllowed(Thing thing, Attribute attribute) {
return create(HAS_INVALID.getMessage(thing.type().label(), attribute.type().label()));
} | [
"public",
"static",
"TransactionException",
"hasNotAllowed",
"(",
"Thing",
"thing",
",",
"Attribute",
"attribute",
")",
"{",
"return",
"create",
"(",
"HAS_INVALID",
".",
"getMessage",
"(",
"thing",
".",
"type",
"(",
")",
".",
"label",
"(",
")",
",",
"attribute",
".",
"type",
"(",
")",
".",
"label",
"(",
")",
")",
")",
";",
"}"
] | Thrown when a Thing is not allowed to have Attribute of that AttributeType | [
"Thrown",
"when",
"a",
"Thing",
"is",
"not",
"allowed",
"to",
"have",
"Attribute",
"of",
"that",
"AttributeType"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/exception/TransactionException.java#L93-L95 |
22,909 | graknlabs/grakn | server/src/server/exception/TransactionException.java | TransactionException.cannotBeDeleted | public static TransactionException cannotBeDeleted(SchemaConcept schemaConcept) {
return create(ErrorMessage.CANNOT_DELETE.getMessage(schemaConcept.label()));
} | java | public static TransactionException cannotBeDeleted(SchemaConcept schemaConcept) {
return create(ErrorMessage.CANNOT_DELETE.getMessage(schemaConcept.label()));
} | [
"public",
"static",
"TransactionException",
"cannotBeDeleted",
"(",
"SchemaConcept",
"schemaConcept",
")",
"{",
"return",
"create",
"(",
"ErrorMessage",
".",
"CANNOT_DELETE",
".",
"getMessage",
"(",
"schemaConcept",
".",
"label",
"(",
")",
")",
")",
";",
"}"
] | Thrown when a Type has incoming edges and therefore cannot be deleted | [
"Thrown",
"when",
"a",
"Type",
"has",
"incoming",
"edges",
"and",
"therefore",
"cannot",
"be",
"deleted"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/exception/TransactionException.java#L108-L110 |
22,910 | graknlabs/grakn | server/src/server/exception/TransactionException.java | TransactionException.invalidAttributeValue | public static TransactionException invalidAttributeValue(Object object, AttributeType.DataType dataType) {
return create(ErrorMessage.INVALID_DATATYPE.getMessage(object, object.getClass().getSimpleName(), dataType.name()));
} | java | public static TransactionException invalidAttributeValue(Object object, AttributeType.DataType dataType) {
return create(ErrorMessage.INVALID_DATATYPE.getMessage(object, object.getClass().getSimpleName(), dataType.name()));
} | [
"public",
"static",
"TransactionException",
"invalidAttributeValue",
"(",
"Object",
"object",
",",
"AttributeType",
".",
"DataType",
"dataType",
")",
"{",
"return",
"create",
"(",
"ErrorMessage",
".",
"INVALID_DATATYPE",
".",
"getMessage",
"(",
"object",
",",
"object",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
",",
"dataType",
".",
"name",
"(",
")",
")",
")",
";",
"}"
] | Thrown when creating an Attribute whose value Object does not match attribute data type | [
"Thrown",
"when",
"creating",
"an",
"Attribute",
"whose",
"value",
"Object",
"does",
"not",
"match",
"attribute",
"data",
"type"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/exception/TransactionException.java#L150-L152 |
22,911 | graknlabs/grakn | server/src/server/exception/TransactionException.java | TransactionException.immutableProperty | public static TransactionException immutableProperty(Object oldValue, Object newValue, Enum vertexProperty) {
return create(ErrorMessage.IMMUTABLE_VALUE.getMessage(oldValue, newValue, vertexProperty.name()));
} | java | public static TransactionException immutableProperty(Object oldValue, Object newValue, Enum vertexProperty) {
return create(ErrorMessage.IMMUTABLE_VALUE.getMessage(oldValue, newValue, vertexProperty.name()));
} | [
"public",
"static",
"TransactionException",
"immutableProperty",
"(",
"Object",
"oldValue",
",",
"Object",
"newValue",
",",
"Enum",
"vertexProperty",
")",
"{",
"return",
"create",
"(",
"ErrorMessage",
".",
"IMMUTABLE_VALUE",
".",
"getMessage",
"(",
"oldValue",
",",
"newValue",
",",
"vertexProperty",
".",
"name",
"(",
")",
")",
")",
";",
"}"
] | Thrown when attempting to mutate a property which is immutable | [
"Thrown",
"when",
"attempting",
"to",
"mutate",
"a",
"property",
"which",
"is",
"immutable"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/exception/TransactionException.java#L173-L175 |
22,912 | graknlabs/grakn | server/src/server/exception/TransactionException.java | TransactionException.transactionOpen | public static TransactionException transactionOpen(TransactionOLTP tx) {
return create(ErrorMessage.TRANSACTION_ALREADY_OPEN.getMessage(tx.keyspace()));
} | java | public static TransactionException transactionOpen(TransactionOLTP tx) {
return create(ErrorMessage.TRANSACTION_ALREADY_OPEN.getMessage(tx.keyspace()));
} | [
"public",
"static",
"TransactionException",
"transactionOpen",
"(",
"TransactionOLTP",
"tx",
")",
"{",
"return",
"create",
"(",
"ErrorMessage",
".",
"TRANSACTION_ALREADY_OPEN",
".",
"getMessage",
"(",
"tx",
".",
"keyspace",
"(",
")",
")",
")",
";",
"}"
] | Thrown when attempting to open a transaction which is already open | [
"Thrown",
"when",
"attempting",
"to",
"open",
"a",
"transaction",
"which",
"is",
"already",
"open"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/exception/TransactionException.java#L187-L189 |
22,913 | graknlabs/grakn | server/src/server/exception/TransactionException.java | TransactionException.transactionReadOnly | public static TransactionException transactionReadOnly(TransactionOLTP tx) {
return create(ErrorMessage.TRANSACTION_READ_ONLY.getMessage(tx.keyspace()));
} | java | public static TransactionException transactionReadOnly(TransactionOLTP tx) {
return create(ErrorMessage.TRANSACTION_READ_ONLY.getMessage(tx.keyspace()));
} | [
"public",
"static",
"TransactionException",
"transactionReadOnly",
"(",
"TransactionOLTP",
"tx",
")",
"{",
"return",
"create",
"(",
"ErrorMessage",
".",
"TRANSACTION_READ_ONLY",
".",
"getMessage",
"(",
"tx",
".",
"keyspace",
"(",
")",
")",
")",
";",
"}"
] | Thrown when attempting to mutate a read only transaction | [
"Thrown",
"when",
"attempting",
"to",
"mutate",
"a",
"read",
"only",
"transaction"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/exception/TransactionException.java#L201-L203 |
22,914 | graknlabs/grakn | server/src/server/exception/TransactionException.java | TransactionException.closingFailed | public static TransactionException closingFailed(TransactionOLTP tx, Exception e) {
return new TransactionException(CLOSE_FAILURE.getMessage(tx.keyspace()), e);
} | java | public static TransactionException closingFailed(TransactionOLTP tx, Exception e) {
return new TransactionException(CLOSE_FAILURE.getMessage(tx.keyspace()), e);
} | [
"public",
"static",
"TransactionException",
"closingFailed",
"(",
"TransactionOLTP",
"tx",
",",
"Exception",
"e",
")",
"{",
"return",
"new",
"TransactionException",
"(",
"CLOSE_FAILURE",
".",
"getMessage",
"(",
"tx",
".",
"keyspace",
"(",
")",
")",
",",
"e",
")",
";",
"}"
] | Thrown when the graph can not be closed due to an unknown reason. | [
"Thrown",
"when",
"the",
"graph",
"can",
"not",
"be",
"closed",
"due",
"to",
"an",
"unknown",
"reason",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/exception/TransactionException.java#L227-L229 |
22,915 | graknlabs/grakn | server/src/server/exception/TransactionException.java | TransactionException.invalidPropertyUse | public static TransactionException invalidPropertyUse(Concept concept, Schema.VertexProperty property) {
return create(INVALID_PROPERTY_USE.getMessage(concept, property));
} | java | public static TransactionException invalidPropertyUse(Concept concept, Schema.VertexProperty property) {
return create(INVALID_PROPERTY_USE.getMessage(concept, property));
} | [
"public",
"static",
"TransactionException",
"invalidPropertyUse",
"(",
"Concept",
"concept",
",",
"Schema",
".",
"VertexProperty",
"property",
")",
"{",
"return",
"create",
"(",
"INVALID_PROPERTY_USE",
".",
"getMessage",
"(",
"concept",
",",
"property",
")",
")",
";",
"}"
] | Thrown when trying to add a Schema.VertexProperty to a Concept which does not accept that type
of Schema.VertexProperty | [
"Thrown",
"when",
"trying",
"to",
"add",
"a",
"Schema",
".",
"VertexProperty",
"to",
"a",
"Concept",
"which",
"does",
"not",
"accept",
"that",
"type",
"of",
"Schema",
".",
"VertexProperty"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/exception/TransactionException.java#L256-L258 |
22,916 | graknlabs/grakn | server/src/server/exception/TransactionException.java | TransactionException.changingSuperWillDisconnectRole | public static TransactionException 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()));
} | java | public static TransactionException 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()));
} | [
"public",
"static",
"TransactionException",
"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 changing the super of a Type will result in a Role disconnection which is in use. | [
"Thrown",
"when",
"changing",
"the",
"super",
"of",
"a",
"Type",
"will",
"result",
"in",
"a",
"Role",
"disconnection",
"which",
"is",
"in",
"use",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/exception/TransactionException.java#L284-L287 |
22,917 | graknlabs/grakn | server/src/graql/gremlin/NodesUtil.java | NodesUtil.nodeToPlanFragments | static List<Fragment> nodeToPlanFragments(Node node, Map<NodeId, Node> nodes, boolean visited) {
List<Fragment> subplan = new LinkedList<>();
if (!visited) {
node.getFragmentsWithoutDependency().stream()
.min(Comparator.comparingDouble(Fragment::fragmentCost))
.ifPresent(firstNodeFragment -> {
subplan.add(firstNodeFragment);
node.getFragmentsWithoutDependency().remove(firstNodeFragment);
});
}
node.getFragmentsWithoutDependency().addAll(node.getFragmentsWithDependencyVisited());
subplan.addAll(node.getFragmentsWithoutDependency().stream()
.sorted(Comparator.comparingDouble(Fragment::fragmentCost))
.collect(Collectors.toList()));
node.getFragmentsWithoutDependency().clear();
node.getFragmentsWithDependencyVisited().clear();
// telling their dependants that they have been visited
node.getDependants().forEach(fragment -> {
Node otherNode = nodes.get(NodeId.of(NodeId.NodeType.VAR, fragment.start()));
if (node.equals(otherNode)) {
otherNode = nodes.get(NodeId.of(NodeId.NodeType.VAR, fragment.dependencies().iterator().next()));
}
otherNode.getDependants().remove(fragment.getInverse());
otherNode.getFragmentsWithDependencyVisited().add(fragment);
});
node.getDependants().clear();
return subplan;
} | java | static List<Fragment> nodeToPlanFragments(Node node, Map<NodeId, Node> nodes, boolean visited) {
List<Fragment> subplan = new LinkedList<>();
if (!visited) {
node.getFragmentsWithoutDependency().stream()
.min(Comparator.comparingDouble(Fragment::fragmentCost))
.ifPresent(firstNodeFragment -> {
subplan.add(firstNodeFragment);
node.getFragmentsWithoutDependency().remove(firstNodeFragment);
});
}
node.getFragmentsWithoutDependency().addAll(node.getFragmentsWithDependencyVisited());
subplan.addAll(node.getFragmentsWithoutDependency().stream()
.sorted(Comparator.comparingDouble(Fragment::fragmentCost))
.collect(Collectors.toList()));
node.getFragmentsWithoutDependency().clear();
node.getFragmentsWithDependencyVisited().clear();
// telling their dependants that they have been visited
node.getDependants().forEach(fragment -> {
Node otherNode = nodes.get(NodeId.of(NodeId.NodeType.VAR, fragment.start()));
if (node.equals(otherNode)) {
otherNode = nodes.get(NodeId.of(NodeId.NodeType.VAR, fragment.dependencies().iterator().next()));
}
otherNode.getDependants().remove(fragment.getInverse());
otherNode.getFragmentsWithDependencyVisited().add(fragment);
});
node.getDependants().clear();
return subplan;
} | [
"static",
"List",
"<",
"Fragment",
">",
"nodeToPlanFragments",
"(",
"Node",
"node",
",",
"Map",
"<",
"NodeId",
",",
"Node",
">",
"nodes",
",",
"boolean",
"visited",
")",
"{",
"List",
"<",
"Fragment",
">",
"subplan",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"if",
"(",
"!",
"visited",
")",
"{",
"node",
".",
"getFragmentsWithoutDependency",
"(",
")",
".",
"stream",
"(",
")",
".",
"min",
"(",
"Comparator",
".",
"comparingDouble",
"(",
"Fragment",
"::",
"fragmentCost",
")",
")",
".",
"ifPresent",
"(",
"firstNodeFragment",
"->",
"{",
"subplan",
".",
"add",
"(",
"firstNodeFragment",
")",
";",
"node",
".",
"getFragmentsWithoutDependency",
"(",
")",
".",
"remove",
"(",
"firstNodeFragment",
")",
";",
"}",
")",
";",
"}",
"node",
".",
"getFragmentsWithoutDependency",
"(",
")",
".",
"addAll",
"(",
"node",
".",
"getFragmentsWithDependencyVisited",
"(",
")",
")",
";",
"subplan",
".",
"addAll",
"(",
"node",
".",
"getFragmentsWithoutDependency",
"(",
")",
".",
"stream",
"(",
")",
".",
"sorted",
"(",
"Comparator",
".",
"comparingDouble",
"(",
"Fragment",
"::",
"fragmentCost",
")",
")",
".",
"collect",
"(",
"Collectors",
".",
"toList",
"(",
")",
")",
")",
";",
"node",
".",
"getFragmentsWithoutDependency",
"(",
")",
".",
"clear",
"(",
")",
";",
"node",
".",
"getFragmentsWithDependencyVisited",
"(",
")",
".",
"clear",
"(",
")",
";",
"// telling their dependants that they have been visited",
"node",
".",
"getDependants",
"(",
")",
".",
"forEach",
"(",
"fragment",
"->",
"{",
"Node",
"otherNode",
"=",
"nodes",
".",
"get",
"(",
"NodeId",
".",
"of",
"(",
"NodeId",
".",
"NodeType",
".",
"VAR",
",",
"fragment",
".",
"start",
"(",
")",
")",
")",
";",
"if",
"(",
"node",
".",
"equals",
"(",
"otherNode",
")",
")",
"{",
"otherNode",
"=",
"nodes",
".",
"get",
"(",
"NodeId",
".",
"of",
"(",
"NodeId",
".",
"NodeType",
".",
"VAR",
",",
"fragment",
".",
"dependencies",
"(",
")",
".",
"iterator",
"(",
")",
".",
"next",
"(",
")",
")",
")",
";",
"}",
"otherNode",
".",
"getDependants",
"(",
")",
".",
"remove",
"(",
"fragment",
".",
"getInverse",
"(",
")",
")",
";",
"otherNode",
".",
"getFragmentsWithDependencyVisited",
"(",
")",
".",
"add",
"(",
"fragment",
")",
";",
"}",
")",
";",
"node",
".",
"getDependants",
"(",
")",
".",
"clear",
"(",
")",
";",
"return",
"subplan",
";",
"}"
] | convert a Node to a sub-plan, updating dependants' dependency map | [
"convert",
"a",
"Node",
"to",
"a",
"sub",
"-",
"plan",
"updating",
"dependants",
"dependency",
"map"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/NodesUtil.java#L101-L132 |
22,918 | graknlabs/grakn | concept/printer/Printer.java | Printer.toStream | public Stream<String> toStream(Stream<?> objects) {
if (objects == null) return Stream.empty();
return objects.map(this::toString);
} | java | public Stream<String> toStream(Stream<?> objects) {
if (objects == null) return Stream.empty();
return objects.map(this::toString);
} | [
"public",
"Stream",
"<",
"String",
">",
"toStream",
"(",
"Stream",
"<",
"?",
">",
"objects",
")",
"{",
"if",
"(",
"objects",
"==",
"null",
")",
"return",
"Stream",
".",
"empty",
"(",
")",
";",
"return",
"objects",
".",
"map",
"(",
"this",
"::",
"toString",
")",
";",
"}"
] | Convert a stream of objects into a stream of Strings to be printed
@param objects the objects to be printed
@return the stream of String print output for the object | [
"Convert",
"a",
"stream",
"of",
"objects",
"into",
"a",
"stream",
"of",
"Strings",
"to",
"be",
"printed"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/concept/printer/Printer.java#L64-L67 |
22,919 | graknlabs/grakn | concept/printer/Printer.java | Printer.build | @CheckReturnValue
protected Builder build(Object object) {
if (object instanceof Concept) {
return concept((Concept) object);
}
else if (object instanceof Boolean) {
return bool((boolean) object);
}
else if (object instanceof Collection) {
return collection((Collection<?>) object);
}
else if (object instanceof AnswerGroup<?>) {
return answerGroup((AnswerGroup<?>) object);
}
else if (object instanceof ConceptList) {
return conceptList((ConceptList) object);
}
else if (object instanceof ConceptMap) {
return conceptMap((ConceptMap) object);
}
else if (object instanceof ConceptSet) {
if (object instanceof ConceptSetMeasure) {
return conceptSetMeasure((ConceptSetMeasure) object);
}
else {
return conceptSet((ConceptSet) object);
}
}
else if (object instanceof Numeric) {
return value((Numeric) object);
}
else if (object instanceof Map) {
return map((Map<?, ?>) object);
}
else {
return object(object);
}
} | java | @CheckReturnValue
protected Builder build(Object object) {
if (object instanceof Concept) {
return concept((Concept) object);
}
else if (object instanceof Boolean) {
return bool((boolean) object);
}
else if (object instanceof Collection) {
return collection((Collection<?>) object);
}
else if (object instanceof AnswerGroup<?>) {
return answerGroup((AnswerGroup<?>) object);
}
else if (object instanceof ConceptList) {
return conceptList((ConceptList) object);
}
else if (object instanceof ConceptMap) {
return conceptMap((ConceptMap) object);
}
else if (object instanceof ConceptSet) {
if (object instanceof ConceptSetMeasure) {
return conceptSetMeasure((ConceptSetMeasure) object);
}
else {
return conceptSet((ConceptSet) object);
}
}
else if (object instanceof Numeric) {
return value((Numeric) object);
}
else if (object instanceof Map) {
return map((Map<?, ?>) object);
}
else {
return object(object);
}
} | [
"@",
"CheckReturnValue",
"protected",
"Builder",
"build",
"(",
"Object",
"object",
")",
"{",
"if",
"(",
"object",
"instanceof",
"Concept",
")",
"{",
"return",
"concept",
"(",
"(",
"Concept",
")",
"object",
")",
";",
"}",
"else",
"if",
"(",
"object",
"instanceof",
"Boolean",
")",
"{",
"return",
"bool",
"(",
"(",
"boolean",
")",
"object",
")",
";",
"}",
"else",
"if",
"(",
"object",
"instanceof",
"Collection",
")",
"{",
"return",
"collection",
"(",
"(",
"Collection",
"<",
"?",
">",
")",
"object",
")",
";",
"}",
"else",
"if",
"(",
"object",
"instanceof",
"AnswerGroup",
"<",
"?",
">",
")",
"{",
"return",
"answerGroup",
"(",
"(",
"AnswerGroup",
"<",
"?",
">",
")",
"object",
")",
";",
"}",
"else",
"if",
"(",
"object",
"instanceof",
"ConceptList",
")",
"{",
"return",
"conceptList",
"(",
"(",
"ConceptList",
")",
"object",
")",
";",
"}",
"else",
"if",
"(",
"object",
"instanceof",
"ConceptMap",
")",
"{",
"return",
"conceptMap",
"(",
"(",
"ConceptMap",
")",
"object",
")",
";",
"}",
"else",
"if",
"(",
"object",
"instanceof",
"ConceptSet",
")",
"{",
"if",
"(",
"object",
"instanceof",
"ConceptSetMeasure",
")",
"{",
"return",
"conceptSetMeasure",
"(",
"(",
"ConceptSetMeasure",
")",
"object",
")",
";",
"}",
"else",
"{",
"return",
"conceptSet",
"(",
"(",
"ConceptSet",
")",
"object",
")",
";",
"}",
"}",
"else",
"if",
"(",
"object",
"instanceof",
"Numeric",
")",
"{",
"return",
"value",
"(",
"(",
"Numeric",
")",
"object",
")",
";",
"}",
"else",
"if",
"(",
"object",
"instanceof",
"Map",
")",
"{",
"return",
"map",
"(",
"(",
"Map",
"<",
"?",
",",
"?",
">",
")",
"object",
")",
";",
"}",
"else",
"{",
"return",
"object",
"(",
"object",
")",
";",
"}",
"}"
] | Convert any object into its print builder
@param object the object to convert into its print builder
@return the object as a builder | [
"Convert",
"any",
"object",
"into",
"its",
"print",
"builder"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/concept/printer/Printer.java#L87-L124 |
22,920 | graknlabs/grakn | server/src/graql/gremlin/spanningtree/datastructure/FibonacciHeap.java | FibonacciHeap.create | public static <T, C extends Comparable> FibonacciHeap<T, C> create() {
return FibonacciHeap.create(Ordering.<C>natural());
} | java | public static <T, C extends Comparable> FibonacciHeap<T, C> create() {
return FibonacciHeap.create(Ordering.<C>natural());
} | [
"public",
"static",
"<",
"T",
",",
"C",
"extends",
"Comparable",
">",
"FibonacciHeap",
"<",
"T",
",",
"C",
">",
"create",
"(",
")",
"{",
"return",
"FibonacciHeap",
".",
"create",
"(",
"Ordering",
".",
"<",
"C",
">",
"natural",
"(",
")",
")",
";",
"}"
] | Create a new FibonacciHeap based on the natural ordering on `C` | [
"Create",
"a",
"new",
"FibonacciHeap",
"based",
"on",
"the",
"natural",
"ordering",
"on",
"C"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/spanningtree/datastructure/FibonacciHeap.java#L77-L79 |
22,921 | graknlabs/grakn | server/src/graql/gremlin/spanningtree/datastructure/FibonacciHeap.java | FibonacciHeap.siblingsAndBelow | private List<Entry> siblingsAndBelow(Entry oEntry) {
if (oEntry == null) return Collections.emptyList();
List<Entry> output = new LinkedList<>();
for (Entry entry : getCycle(oEntry)) {
if (entry != null) {
output.add(entry);
output.addAll(siblingsAndBelow(entry.oFirstChild));
}
}
return output;
} | java | private List<Entry> siblingsAndBelow(Entry oEntry) {
if (oEntry == null) return Collections.emptyList();
List<Entry> output = new LinkedList<>();
for (Entry entry : getCycle(oEntry)) {
if (entry != null) {
output.add(entry);
output.addAll(siblingsAndBelow(entry.oFirstChild));
}
}
return output;
} | [
"private",
"List",
"<",
"Entry",
">",
"siblingsAndBelow",
"(",
"Entry",
"oEntry",
")",
"{",
"if",
"(",
"oEntry",
"==",
"null",
")",
"return",
"Collections",
".",
"emptyList",
"(",
")",
";",
"List",
"<",
"Entry",
">",
"output",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"for",
"(",
"Entry",
"entry",
":",
"getCycle",
"(",
"oEntry",
")",
")",
"{",
"if",
"(",
"entry",
"!=",
"null",
")",
"{",
"output",
".",
"add",
"(",
"entry",
")",
";",
"output",
".",
"addAll",
"(",
"siblingsAndBelow",
"(",
"entry",
".",
"oFirstChild",
")",
")",
";",
"}",
"}",
"return",
"output",
";",
"}"
] | Depth-first iteration | [
"Depth",
"-",
"first",
"iteration"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/spanningtree/datastructure/FibonacciHeap.java#L236-L248 |
22,922 | graknlabs/grakn | server/src/graql/gremlin/spanningtree/datastructure/FibonacciHeap.java | FibonacciHeap.mergeLists | private Entry mergeLists(Entry a, Entry b) {
if (a == null) return b;
if (b == null) return a;
// splice the two circular lists together like a Mobius strip
final Entry aOldNext = a.next;
a.next = b.next;
a.next.previous = a;
b.next = aOldNext;
b.next.previous = b;
return comparator.compare(a.priority, b.priority) < 0 ? a : b;
} | java | private Entry mergeLists(Entry a, Entry b) {
if (a == null) return b;
if (b == null) return a;
// splice the two circular lists together like a Mobius strip
final Entry aOldNext = a.next;
a.next = b.next;
a.next.previous = a;
b.next = aOldNext;
b.next.previous = b;
return comparator.compare(a.priority, b.priority) < 0 ? a : b;
} | [
"private",
"Entry",
"mergeLists",
"(",
"Entry",
"a",
",",
"Entry",
"b",
")",
"{",
"if",
"(",
"a",
"==",
"null",
")",
"return",
"b",
";",
"if",
"(",
"b",
"==",
"null",
")",
"return",
"a",
";",
"// splice the two circular lists together like a Mobius strip",
"final",
"Entry",
"aOldNext",
"=",
"a",
".",
"next",
";",
"a",
".",
"next",
"=",
"b",
".",
"next",
";",
"a",
".",
"next",
".",
"previous",
"=",
"a",
";",
"b",
".",
"next",
"=",
"aOldNext",
";",
"b",
".",
"next",
".",
"previous",
"=",
"b",
";",
"return",
"comparator",
".",
"compare",
"(",
"a",
".",
"priority",
",",
"b",
".",
"priority",
")",
"<",
"0",
"?",
"a",
":",
"b",
";",
"}"
] | Merge two doubly-linked circular lists, given a pointer into each.
Return the smaller of the two arguments. | [
"Merge",
"two",
"doubly",
"-",
"linked",
"circular",
"lists",
"given",
"a",
"pointer",
"into",
"each",
".",
"Return",
"the",
"smaller",
"of",
"the",
"two",
"arguments",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/spanningtree/datastructure/FibonacciHeap.java#L266-L278 |
22,923 | graknlabs/grakn | server/src/graql/gremlin/spanningtree/datastructure/FibonacciHeap.java | FibonacciHeap.setParent | private Entry setParent(Entry entry, Entry parent) {
unlinkFromNeighbors(entry);
entry.oParent = parent;
parent.oFirstChild = mergeLists(entry, parent.oFirstChild);
parent.degree++;
entry.isMarked = false;
return parent;
} | java | private Entry setParent(Entry entry, Entry parent) {
unlinkFromNeighbors(entry);
entry.oParent = parent;
parent.oFirstChild = mergeLists(entry, parent.oFirstChild);
parent.degree++;
entry.isMarked = false;
return parent;
} | [
"private",
"Entry",
"setParent",
"(",
"Entry",
"entry",
",",
"Entry",
"parent",
")",
"{",
"unlinkFromNeighbors",
"(",
"entry",
")",
";",
"entry",
".",
"oParent",
"=",
"parent",
";",
"parent",
".",
"oFirstChild",
"=",
"mergeLists",
"(",
"entry",
",",
"parent",
".",
"oFirstChild",
")",
";",
"parent",
".",
"degree",
"++",
";",
"entry",
".",
"isMarked",
"=",
"false",
";",
"return",
"parent",
";",
"}"
] | Attaches `entry` as a child of `parent`. Returns `parent`. | [
"Attaches",
"entry",
"as",
"a",
"child",
"of",
"parent",
".",
"Returns",
"parent",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/spanningtree/datastructure/FibonacciHeap.java#L323-L331 |
22,924 | graknlabs/grakn | daemon/GraknDaemon.java | GraknDaemon.assertEnvironment | private static void assertEnvironment(Path graknHome, Path graknProperties) {
String javaVersion = System.getProperty("java.specification.version");
if (!javaVersion.equals("1.8")) {
throw new RuntimeException(ErrorMessage.UNSUPPORTED_JAVA_VERSION.getMessage(javaVersion));
}
if (!graknHome.resolve("conf").toFile().exists()) {
throw new RuntimeException(ErrorMessage.UNABLE_TO_GET_GRAKN_HOME_FOLDER.getMessage());
}
if (!graknProperties.toFile().exists()) {
throw new RuntimeException(ErrorMessage.UNABLE_TO_GET_GRAKN_CONFIG_FOLDER.getMessage());
}
} | java | private static void assertEnvironment(Path graknHome, Path graknProperties) {
String javaVersion = System.getProperty("java.specification.version");
if (!javaVersion.equals("1.8")) {
throw new RuntimeException(ErrorMessage.UNSUPPORTED_JAVA_VERSION.getMessage(javaVersion));
}
if (!graknHome.resolve("conf").toFile().exists()) {
throw new RuntimeException(ErrorMessage.UNABLE_TO_GET_GRAKN_HOME_FOLDER.getMessage());
}
if (!graknProperties.toFile().exists()) {
throw new RuntimeException(ErrorMessage.UNABLE_TO_GET_GRAKN_CONFIG_FOLDER.getMessage());
}
} | [
"private",
"static",
"void",
"assertEnvironment",
"(",
"Path",
"graknHome",
",",
"Path",
"graknProperties",
")",
"{",
"String",
"javaVersion",
"=",
"System",
".",
"getProperty",
"(",
"\"java.specification.version\"",
")",
";",
"if",
"(",
"!",
"javaVersion",
".",
"equals",
"(",
"\"1.8\"",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"ErrorMessage",
".",
"UNSUPPORTED_JAVA_VERSION",
".",
"getMessage",
"(",
"javaVersion",
")",
")",
";",
"}",
"if",
"(",
"!",
"graknHome",
".",
"resolve",
"(",
"\"conf\"",
")",
".",
"toFile",
"(",
")",
".",
"exists",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"ErrorMessage",
".",
"UNABLE_TO_GET_GRAKN_HOME_FOLDER",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"graknProperties",
".",
"toFile",
"(",
")",
".",
"exists",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"ErrorMessage",
".",
"UNABLE_TO_GET_GRAKN_CONFIG_FOLDER",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Basic environment checks. Grakn should only be ran if users are running Java 8,
home folder can be detected, and the configuration file 'grakn.properties' exists.
@param graknHome path to $GRAKN_HOME
@param graknProperties path to the 'grakn.properties' file | [
"Basic",
"environment",
"checks",
".",
"Grakn",
"should",
"only",
"be",
"ran",
"if",
"users",
"are",
"running",
"Java",
"8",
"home",
"folder",
"can",
"be",
"detected",
"and",
"the",
"configuration",
"file",
"grakn",
".",
"properties",
"exists",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/daemon/GraknDaemon.java#L94-L105 |
22,925 | graknlabs/grakn | common/config/ConfigKey.java | ConfigKey.parse | public final T parse(String value, Path configFilePath) {
if (value == null) {
throw new RuntimeException(ErrorMessage.UNAVAILABLE_PROPERTY.getMessage(name(), configFilePath));
}
return parser().read(value);
} | java | public final T parse(String value, Path configFilePath) {
if (value == null) {
throw new RuntimeException(ErrorMessage.UNAVAILABLE_PROPERTY.getMessage(name(), configFilePath));
}
return parser().read(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",
")",
";",
"}"
] | 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 | [
"Parse",
"the",
"value",
"of",
"a",
"property",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/common/config/ConfigKey.java#L94-L100 |
22,926 | graknlabs/grakn | common/config/ConfigKey.java | ConfigKey.key | public static <T> ConfigKey<T> key(String value, KeyParser<T> parser) {
return new AutoValue_ConfigKey<>(value, parser);
} | java | public static <T> ConfigKey<T> key(String value, KeyParser<T> parser) {
return new AutoValue_ConfigKey<>(value, parser);
} | [
"public",
"static",
"<",
"T",
">",
"ConfigKey",
"<",
"T",
">",
"key",
"(",
"String",
"value",
",",
"KeyParser",
"<",
"T",
">",
"parser",
")",
"{",
"return",
"new",
"AutoValue_ConfigKey",
"<>",
"(",
"value",
",",
"parser",
")",
";",
"}"
] | Create a key with the given parser | [
"Create",
"a",
"key",
"with",
"the",
"given",
"parser"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/common/config/ConfigKey.java#L119-L121 |
22,927 | graknlabs/grakn | server/src/graql/reasoner/query/ReasonerAtomicQuery.java | ReasonerAtomicQuery.materialise | public Stream<ConceptMap> materialise(ConceptMap answer) {
return this.withSubstitution(answer)
.getAtom()
.materialise()
.map(ans -> ans.explain(answer.explanation()));
} | java | public Stream<ConceptMap> materialise(ConceptMap answer) {
return this.withSubstitution(answer)
.getAtom()
.materialise()
.map(ans -> ans.explain(answer.explanation()));
} | [
"public",
"Stream",
"<",
"ConceptMap",
">",
"materialise",
"(",
"ConceptMap",
"answer",
")",
"{",
"return",
"this",
".",
"withSubstitution",
"(",
"answer",
")",
".",
"getAtom",
"(",
")",
".",
"materialise",
"(",
")",
".",
"map",
"(",
"ans",
"->",
"ans",
".",
"explain",
"(",
"answer",
".",
"explanation",
"(",
")",
")",
")",
";",
"}"
] | materialise this query with the accompanying answer - persist to kb
@param answer to be materialised
@return stream of materialised answers | [
"materialise",
"this",
"query",
"with",
"the",
"accompanying",
"answer",
"-",
"persist",
"to",
"kb"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/reasoner/query/ReasonerAtomicQuery.java#L184-L189 |
22,928 | graknlabs/grakn | server/src/server/session/cache/TransactionCache.java | TransactionCache.cacheConcept | public void cacheConcept(Concept concept) {
conceptCache.put(concept.id(), concept);
if (concept.isSchemaConcept()) {
SchemaConcept schemaConcept = concept.asSchemaConcept();
schemaConceptCache.put(schemaConcept.label(), schemaConcept);
labelCache.put(schemaConcept.label(), schemaConcept.labelId());
}
} | java | public void cacheConcept(Concept concept) {
conceptCache.put(concept.id(), concept);
if (concept.isSchemaConcept()) {
SchemaConcept schemaConcept = concept.asSchemaConcept();
schemaConceptCache.put(schemaConcept.label(), schemaConcept);
labelCache.put(schemaConcept.label(), schemaConcept.labelId());
}
} | [
"public",
"void",
"cacheConcept",
"(",
"Concept",
"concept",
")",
"{",
"conceptCache",
".",
"put",
"(",
"concept",
".",
"id",
"(",
")",
",",
"concept",
")",
";",
"if",
"(",
"concept",
".",
"isSchemaConcept",
"(",
")",
")",
"{",
"SchemaConcept",
"schemaConcept",
"=",
"concept",
".",
"asSchemaConcept",
"(",
")",
";",
"schemaConceptCache",
".",
"put",
"(",
"schemaConcept",
".",
"label",
"(",
")",
",",
"schemaConcept",
")",
";",
"labelCache",
".",
"put",
"(",
"schemaConcept",
".",
"label",
"(",
")",
",",
"schemaConcept",
".",
"labelId",
"(",
")",
")",
";",
"}",
"}"
] | Caches a concept so it does not have to be rebuilt later.
@param concept The concept to be cached. | [
"Caches",
"a",
"concept",
"so",
"it",
"does",
"not",
"have",
"to",
"be",
"rebuilt",
"later",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/cache/TransactionCache.java#L173-L180 |
22,929 | graknlabs/grakn | server/src/server/session/cache/TransactionCache.java | TransactionCache.getCachedConcept | public <X extends Concept> X getCachedConcept(ConceptId id) {
//noinspection unchecked
return (X) conceptCache.get(id);
} | java | public <X extends Concept> X getCachedConcept(ConceptId id) {
//noinspection unchecked
return (X) conceptCache.get(id);
} | [
"public",
"<",
"X",
"extends",
"Concept",
">",
"X",
"getCachedConcept",
"(",
"ConceptId",
"id",
")",
"{",
"//noinspection unchecked",
"return",
"(",
"X",
")",
"conceptCache",
".",
"get",
"(",
"id",
")",
";",
"}"
] | Returns a previously built concept
@param id The id of the concept
@param <X> The type of the concept
@return The cached concept | [
"Returns",
"a",
"previously",
"built",
"concept"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/cache/TransactionCache.java#L226-L229 |
22,930 | graknlabs/grakn | server/src/server/session/cache/TransactionCache.java | TransactionCache.getCachedSchemaConcept | public <X extends SchemaConcept> X getCachedSchemaConcept(Label label) {
//noinspection unchecked
return (X) schemaConceptCache.get(label);
} | java | public <X extends SchemaConcept> X getCachedSchemaConcept(Label label) {
//noinspection unchecked
return (X) schemaConceptCache.get(label);
} | [
"public",
"<",
"X",
"extends",
"SchemaConcept",
">",
"X",
"getCachedSchemaConcept",
"(",
"Label",
"label",
")",
"{",
"//noinspection unchecked",
"return",
"(",
"X",
")",
"schemaConceptCache",
".",
"get",
"(",
"label",
")",
";",
"}"
] | Returns a previously built type
@param label The label of the type
@param <X> The type of the type
@return The cached type | [
"Returns",
"a",
"previously",
"built",
"type"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/cache/TransactionCache.java#L248-L251 |
22,931 | graknlabs/grakn | server/src/graql/gremlin/TraversalPlanner.java | TraversalPlanner.createTraversal | public static GraqlTraversal createTraversal(Pattern pattern, TransactionOLTP tx) {
Collection<Conjunction<Statement>> patterns = pattern.getDisjunctiveNormalForm().getPatterns();
Set<? extends List<Fragment>> fragments = patterns.stream()
.map(conjunction -> new ConjunctionQuery(conjunction, tx))
.map((ConjunctionQuery query) -> planForConjunction(query, tx))
.collect(toImmutableSet());
return GraqlTraversal.create(fragments);
} | java | public static GraqlTraversal createTraversal(Pattern pattern, TransactionOLTP tx) {
Collection<Conjunction<Statement>> patterns = pattern.getDisjunctiveNormalForm().getPatterns();
Set<? extends List<Fragment>> fragments = patterns.stream()
.map(conjunction -> new ConjunctionQuery(conjunction, tx))
.map((ConjunctionQuery query) -> planForConjunction(query, tx))
.collect(toImmutableSet());
return GraqlTraversal.create(fragments);
} | [
"public",
"static",
"GraqlTraversal",
"createTraversal",
"(",
"Pattern",
"pattern",
",",
"TransactionOLTP",
"tx",
")",
"{",
"Collection",
"<",
"Conjunction",
"<",
"Statement",
">>",
"patterns",
"=",
"pattern",
".",
"getDisjunctiveNormalForm",
"(",
")",
".",
"getPatterns",
"(",
")",
";",
"Set",
"<",
"?",
"extends",
"List",
"<",
"Fragment",
">",
">",
"fragments",
"=",
"patterns",
".",
"stream",
"(",
")",
".",
"map",
"(",
"conjunction",
"->",
"new",
"ConjunctionQuery",
"(",
"conjunction",
",",
"tx",
")",
")",
".",
"map",
"(",
"(",
"ConjunctionQuery",
"query",
")",
"->",
"planForConjunction",
"(",
"query",
",",
"tx",
")",
")",
".",
"collect",
"(",
"toImmutableSet",
"(",
")",
")",
";",
"return",
"GraqlTraversal",
".",
"create",
"(",
"fragments",
")",
";",
"}"
] | Create a traversal plan.
@param pattern a pattern to find a query plan for
@return a semi-optimal traversal plan | [
"Create",
"a",
"traversal",
"plan",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/TraversalPlanner.java#L77-L86 |
22,932 | graknlabs/grakn | server/src/graql/gremlin/TraversalPlanner.java | TraversalPlanner.planForConjunction | private static List<Fragment> planForConjunction(ConjunctionQuery query, TransactionOLTP tx) {
// a query plan is an ordered list of fragments
final List<Fragment> plan = new ArrayList<>();
// flatten all the possible fragments from the conjunction query (these become edges in the query graph)
final Set<Fragment> allFragments = query.getEquivalentFragmentSets().stream()
.flatMap(EquivalentFragmentSet::stream).collect(Collectors.toSet());
// if role players' types are known, we can infer the types of the relation, adding label & isa fragments
Set<Fragment> inferredFragments = inferRelationTypes(tx, allFragments);
allFragments.addAll(inferredFragments);
// convert fragments into nodes - some fragments create virtual middle nodes to ensure the Janus edge is traversed
ImmutableMap<NodeId, Node> queryGraphNodes = buildNodesWithDependencies(allFragments);
// it's possible that some (or all) fragments are disconnected, e.g. $x isa person; $y isa dog;
Collection<Set<Fragment>> connectedFragmentSets = getConnectedFragmentSets(allFragments);
// build a query plan for each query subgraph separately
for (Set<Fragment> connectedFragments : connectedFragmentSets) {
// one of two cases - either we have a connected graph > 1 node, which is used to compute a MST, OR exactly 1 node
Arborescence<Node> subgraphArborescence = computeArborescence(connectedFragments, queryGraphNodes, tx);
if (subgraphArborescence != null) {
// collect the mapping from directed edge back to fragments -- inverse operation of creating virtual middle nodes
Map<Node, Map<Node, Fragment>> middleNodeFragmentMapping = virtualMiddleNodeToFragmentMapping(connectedFragments, queryGraphNodes);
List<Fragment> subplan = GreedyTreeTraversal.greedyTraversal(subgraphArborescence, queryGraphNodes, middleNodeFragmentMapping);
plan.addAll(subplan);
} else {
// find and include all the nodes not touched in the MST in the plan
Set<Node> unhandledNodes = connectedFragments.stream()
.flatMap(fragment -> fragment.getNodes().stream())
.map(node -> queryGraphNodes.get(node.getNodeId()))
.collect(Collectors.toSet());
if (unhandledNodes.size() != 1) {
throw GraknServerException.create("Query planner exception - expected one unhandled node, found " + unhandledNodes.size());
}
plan.addAll(nodeToPlanFragments(Iterators.getOnlyElement(unhandledNodes.iterator()), queryGraphNodes, false));
}
}
// this shouldn't be necessary, but we keep it just in case of an edge case that we haven't thought of
List<Fragment> remainingFragments = fragmentsForUnvisitedNodes(queryGraphNodes, queryGraphNodes.values());
if (remainingFragments.size() > 0) {
LOG.warn("Expected all fragments to be handled, but found these: " + remainingFragments);
plan.addAll(remainingFragments);
}
LOG.trace("Greedy Plan = {}", plan);
return plan;
} | java | private static List<Fragment> planForConjunction(ConjunctionQuery query, TransactionOLTP tx) {
// a query plan is an ordered list of fragments
final List<Fragment> plan = new ArrayList<>();
// flatten all the possible fragments from the conjunction query (these become edges in the query graph)
final Set<Fragment> allFragments = query.getEquivalentFragmentSets().stream()
.flatMap(EquivalentFragmentSet::stream).collect(Collectors.toSet());
// if role players' types are known, we can infer the types of the relation, adding label & isa fragments
Set<Fragment> inferredFragments = inferRelationTypes(tx, allFragments);
allFragments.addAll(inferredFragments);
// convert fragments into nodes - some fragments create virtual middle nodes to ensure the Janus edge is traversed
ImmutableMap<NodeId, Node> queryGraphNodes = buildNodesWithDependencies(allFragments);
// it's possible that some (or all) fragments are disconnected, e.g. $x isa person; $y isa dog;
Collection<Set<Fragment>> connectedFragmentSets = getConnectedFragmentSets(allFragments);
// build a query plan for each query subgraph separately
for (Set<Fragment> connectedFragments : connectedFragmentSets) {
// one of two cases - either we have a connected graph > 1 node, which is used to compute a MST, OR exactly 1 node
Arborescence<Node> subgraphArborescence = computeArborescence(connectedFragments, queryGraphNodes, tx);
if (subgraphArborescence != null) {
// collect the mapping from directed edge back to fragments -- inverse operation of creating virtual middle nodes
Map<Node, Map<Node, Fragment>> middleNodeFragmentMapping = virtualMiddleNodeToFragmentMapping(connectedFragments, queryGraphNodes);
List<Fragment> subplan = GreedyTreeTraversal.greedyTraversal(subgraphArborescence, queryGraphNodes, middleNodeFragmentMapping);
plan.addAll(subplan);
} else {
// find and include all the nodes not touched in the MST in the plan
Set<Node> unhandledNodes = connectedFragments.stream()
.flatMap(fragment -> fragment.getNodes().stream())
.map(node -> queryGraphNodes.get(node.getNodeId()))
.collect(Collectors.toSet());
if (unhandledNodes.size() != 1) {
throw GraknServerException.create("Query planner exception - expected one unhandled node, found " + unhandledNodes.size());
}
plan.addAll(nodeToPlanFragments(Iterators.getOnlyElement(unhandledNodes.iterator()), queryGraphNodes, false));
}
}
// this shouldn't be necessary, but we keep it just in case of an edge case that we haven't thought of
List<Fragment> remainingFragments = fragmentsForUnvisitedNodes(queryGraphNodes, queryGraphNodes.values());
if (remainingFragments.size() > 0) {
LOG.warn("Expected all fragments to be handled, but found these: " + remainingFragments);
plan.addAll(remainingFragments);
}
LOG.trace("Greedy Plan = {}", plan);
return plan;
} | [
"private",
"static",
"List",
"<",
"Fragment",
">",
"planForConjunction",
"(",
"ConjunctionQuery",
"query",
",",
"TransactionOLTP",
"tx",
")",
"{",
"// a query plan is an ordered list of fragments",
"final",
"List",
"<",
"Fragment",
">",
"plan",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"// flatten all the possible fragments from the conjunction query (these become edges in the query graph)",
"final",
"Set",
"<",
"Fragment",
">",
"allFragments",
"=",
"query",
".",
"getEquivalentFragmentSets",
"(",
")",
".",
"stream",
"(",
")",
".",
"flatMap",
"(",
"EquivalentFragmentSet",
"::",
"stream",
")",
".",
"collect",
"(",
"Collectors",
".",
"toSet",
"(",
")",
")",
";",
"// if role players' types are known, we can infer the types of the relation, adding label & isa fragments",
"Set",
"<",
"Fragment",
">",
"inferredFragments",
"=",
"inferRelationTypes",
"(",
"tx",
",",
"allFragments",
")",
";",
"allFragments",
".",
"addAll",
"(",
"inferredFragments",
")",
";",
"// convert fragments into nodes - some fragments create virtual middle nodes to ensure the Janus edge is traversed",
"ImmutableMap",
"<",
"NodeId",
",",
"Node",
">",
"queryGraphNodes",
"=",
"buildNodesWithDependencies",
"(",
"allFragments",
")",
";",
"// it's possible that some (or all) fragments are disconnected, e.g. $x isa person; $y isa dog;",
"Collection",
"<",
"Set",
"<",
"Fragment",
">",
">",
"connectedFragmentSets",
"=",
"getConnectedFragmentSets",
"(",
"allFragments",
")",
";",
"// build a query plan for each query subgraph separately",
"for",
"(",
"Set",
"<",
"Fragment",
">",
"connectedFragments",
":",
"connectedFragmentSets",
")",
"{",
"// one of two cases - either we have a connected graph > 1 node, which is used to compute a MST, OR exactly 1 node",
"Arborescence",
"<",
"Node",
">",
"subgraphArborescence",
"=",
"computeArborescence",
"(",
"connectedFragments",
",",
"queryGraphNodes",
",",
"tx",
")",
";",
"if",
"(",
"subgraphArborescence",
"!=",
"null",
")",
"{",
"// collect the mapping from directed edge back to fragments -- inverse operation of creating virtual middle nodes",
"Map",
"<",
"Node",
",",
"Map",
"<",
"Node",
",",
"Fragment",
">",
">",
"middleNodeFragmentMapping",
"=",
"virtualMiddleNodeToFragmentMapping",
"(",
"connectedFragments",
",",
"queryGraphNodes",
")",
";",
"List",
"<",
"Fragment",
">",
"subplan",
"=",
"GreedyTreeTraversal",
".",
"greedyTraversal",
"(",
"subgraphArborescence",
",",
"queryGraphNodes",
",",
"middleNodeFragmentMapping",
")",
";",
"plan",
".",
"addAll",
"(",
"subplan",
")",
";",
"}",
"else",
"{",
"// find and include all the nodes not touched in the MST in the plan",
"Set",
"<",
"Node",
">",
"unhandledNodes",
"=",
"connectedFragments",
".",
"stream",
"(",
")",
".",
"flatMap",
"(",
"fragment",
"->",
"fragment",
".",
"getNodes",
"(",
")",
".",
"stream",
"(",
")",
")",
".",
"map",
"(",
"node",
"->",
"queryGraphNodes",
".",
"get",
"(",
"node",
".",
"getNodeId",
"(",
")",
")",
")",
".",
"collect",
"(",
"Collectors",
".",
"toSet",
"(",
")",
")",
";",
"if",
"(",
"unhandledNodes",
".",
"size",
"(",
")",
"!=",
"1",
")",
"{",
"throw",
"GraknServerException",
".",
"create",
"(",
"\"Query planner exception - expected one unhandled node, found \"",
"+",
"unhandledNodes",
".",
"size",
"(",
")",
")",
";",
"}",
"plan",
".",
"addAll",
"(",
"nodeToPlanFragments",
"(",
"Iterators",
".",
"getOnlyElement",
"(",
"unhandledNodes",
".",
"iterator",
"(",
")",
")",
",",
"queryGraphNodes",
",",
"false",
")",
")",
";",
"}",
"}",
"// this shouldn't be necessary, but we keep it just in case of an edge case that we haven't thought of",
"List",
"<",
"Fragment",
">",
"remainingFragments",
"=",
"fragmentsForUnvisitedNodes",
"(",
"queryGraphNodes",
",",
"queryGraphNodes",
".",
"values",
"(",
")",
")",
";",
"if",
"(",
"remainingFragments",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Expected all fragments to be handled, but found these: \"",
"+",
"remainingFragments",
")",
";",
"plan",
".",
"addAll",
"(",
"remainingFragments",
")",
";",
"}",
"LOG",
".",
"trace",
"(",
"\"Greedy Plan = {}\"",
",",
"plan",
")",
";",
"return",
"plan",
";",
"}"
] | Create a plan using Edmonds' algorithm with greedy approach to execute a single conjunction
@param query the conjunction query to find a traversal plan
@return a semi-optimal traversal plan to execute the given conjunction | [
"Create",
"a",
"plan",
"using",
"Edmonds",
"algorithm",
"with",
"greedy",
"approach",
"to",
"execute",
"a",
"single",
"conjunction"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/TraversalPlanner.java#L94-L143 |
22,933 | graknlabs/grakn | server/src/graql/gremlin/TraversalPlanner.java | TraversalPlanner.fragmentsForUnvisitedNodes | private static List<Fragment> fragmentsForUnvisitedNodes(Map<NodeId, Node> allNodes, Collection<Node> connectedNodes) {
List<Fragment> subplan = new LinkedList<>();
Set<Node> nodeWithFragment = connectedNodes.stream()
// make sure the fragment either has no dependency or dependencies have been dealt with
.filter(node -> !node.getFragmentsWithoutDependency().isEmpty() ||
!node.getFragmentsWithDependencyVisited().isEmpty())
.collect(Collectors.toSet());
while (!nodeWithFragment.isEmpty()) {
nodeWithFragment.forEach(node -> subplan.addAll(nodeToPlanFragments(node, allNodes, false)));
nodeWithFragment = connectedNodes.stream()
.filter(node -> !node.getFragmentsWithoutDependency().isEmpty() ||
!node.getFragmentsWithDependencyVisited().isEmpty())
.collect(Collectors.toSet());
}
return subplan;
} | java | private static List<Fragment> fragmentsForUnvisitedNodes(Map<NodeId, Node> allNodes, Collection<Node> connectedNodes) {
List<Fragment> subplan = new LinkedList<>();
Set<Node> nodeWithFragment = connectedNodes.stream()
// make sure the fragment either has no dependency or dependencies have been dealt with
.filter(node -> !node.getFragmentsWithoutDependency().isEmpty() ||
!node.getFragmentsWithDependencyVisited().isEmpty())
.collect(Collectors.toSet());
while (!nodeWithFragment.isEmpty()) {
nodeWithFragment.forEach(node -> subplan.addAll(nodeToPlanFragments(node, allNodes, false)));
nodeWithFragment = connectedNodes.stream()
.filter(node -> !node.getFragmentsWithoutDependency().isEmpty() ||
!node.getFragmentsWithDependencyVisited().isEmpty())
.collect(Collectors.toSet());
}
return subplan;
} | [
"private",
"static",
"List",
"<",
"Fragment",
">",
"fragmentsForUnvisitedNodes",
"(",
"Map",
"<",
"NodeId",
",",
"Node",
">",
"allNodes",
",",
"Collection",
"<",
"Node",
">",
"connectedNodes",
")",
"{",
"List",
"<",
"Fragment",
">",
"subplan",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"Set",
"<",
"Node",
">",
"nodeWithFragment",
"=",
"connectedNodes",
".",
"stream",
"(",
")",
"// make sure the fragment either has no dependency or dependencies have been dealt with",
".",
"filter",
"(",
"node",
"->",
"!",
"node",
".",
"getFragmentsWithoutDependency",
"(",
")",
".",
"isEmpty",
"(",
")",
"||",
"!",
"node",
".",
"getFragmentsWithDependencyVisited",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
".",
"collect",
"(",
"Collectors",
".",
"toSet",
"(",
")",
")",
";",
"while",
"(",
"!",
"nodeWithFragment",
".",
"isEmpty",
"(",
")",
")",
"{",
"nodeWithFragment",
".",
"forEach",
"(",
"node",
"->",
"subplan",
".",
"addAll",
"(",
"nodeToPlanFragments",
"(",
"node",
",",
"allNodes",
",",
"false",
")",
")",
")",
";",
"nodeWithFragment",
"=",
"connectedNodes",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"node",
"->",
"!",
"node",
".",
"getFragmentsWithoutDependency",
"(",
")",
".",
"isEmpty",
"(",
")",
"||",
"!",
"node",
".",
"getFragmentsWithDependencyVisited",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
".",
"collect",
"(",
"Collectors",
".",
"toSet",
"(",
")",
")",
";",
"}",
"return",
"subplan",
";",
"}"
] | add unvisited node fragments to plan | [
"add",
"unvisited",
"node",
"fragments",
"to",
"plan"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/TraversalPlanner.java#L232-L249 |
22,934 | graknlabs/grakn | server/src/graql/gremlin/TraversalPlanner.java | TraversalPlanner.getConnectedFragmentSets | private static Collection<Set<Fragment>> getConnectedFragmentSets(Set<Fragment> allFragments) {
// TODO this could be implemented in a more readable way (eg. using a graph + BFS etc.)
final Map<Integer, Set<Variable>> varSetMap = new HashMap<>();
final Map<Integer, Set<Fragment>> fragmentSetMap = new HashMap<>();
final int[] index = {0};
allFragments.forEach(fragment -> {
Set<Variable> fragmentVarNameSet = Sets.newHashSet(fragment.vars());
List<Integer> setsWithVarInCommon = new ArrayList<>();
varSetMap.forEach((setIndex, varNameSet) -> {
if (!Collections.disjoint(varNameSet, fragmentVarNameSet)) {
setsWithVarInCommon.add(setIndex);
}
});
if (setsWithVarInCommon.isEmpty()) {
index[0] += 1;
varSetMap.put(index[0], fragmentVarNameSet);
fragmentSetMap.put(index[0], Sets.newHashSet(fragment));
} else {
Iterator<Integer> iterator = setsWithVarInCommon.iterator();
Integer firstSet = iterator.next();
varSetMap.get(firstSet).addAll(fragmentVarNameSet);
fragmentSetMap.get(firstSet).add(fragment);
while (iterator.hasNext()) {
Integer nextSet = iterator.next();
varSetMap.get(firstSet).addAll(varSetMap.remove(nextSet));
fragmentSetMap.get(firstSet).addAll(fragmentSetMap.remove(nextSet));
}
}
});
return fragmentSetMap.values();
} | java | private static Collection<Set<Fragment>> getConnectedFragmentSets(Set<Fragment> allFragments) {
// TODO this could be implemented in a more readable way (eg. using a graph + BFS etc.)
final Map<Integer, Set<Variable>> varSetMap = new HashMap<>();
final Map<Integer, Set<Fragment>> fragmentSetMap = new HashMap<>();
final int[] index = {0};
allFragments.forEach(fragment -> {
Set<Variable> fragmentVarNameSet = Sets.newHashSet(fragment.vars());
List<Integer> setsWithVarInCommon = new ArrayList<>();
varSetMap.forEach((setIndex, varNameSet) -> {
if (!Collections.disjoint(varNameSet, fragmentVarNameSet)) {
setsWithVarInCommon.add(setIndex);
}
});
if (setsWithVarInCommon.isEmpty()) {
index[0] += 1;
varSetMap.put(index[0], fragmentVarNameSet);
fragmentSetMap.put(index[0], Sets.newHashSet(fragment));
} else {
Iterator<Integer> iterator = setsWithVarInCommon.iterator();
Integer firstSet = iterator.next();
varSetMap.get(firstSet).addAll(fragmentVarNameSet);
fragmentSetMap.get(firstSet).add(fragment);
while (iterator.hasNext()) {
Integer nextSet = iterator.next();
varSetMap.get(firstSet).addAll(varSetMap.remove(nextSet));
fragmentSetMap.get(firstSet).addAll(fragmentSetMap.remove(nextSet));
}
}
});
return fragmentSetMap.values();
} | [
"private",
"static",
"Collection",
"<",
"Set",
"<",
"Fragment",
">",
">",
"getConnectedFragmentSets",
"(",
"Set",
"<",
"Fragment",
">",
"allFragments",
")",
"{",
"// TODO this could be implemented in a more readable way (eg. using a graph + BFS etc.)",
"final",
"Map",
"<",
"Integer",
",",
"Set",
"<",
"Variable",
">",
">",
"varSetMap",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"final",
"Map",
"<",
"Integer",
",",
"Set",
"<",
"Fragment",
">",
">",
"fragmentSetMap",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"final",
"int",
"[",
"]",
"index",
"=",
"{",
"0",
"}",
";",
"allFragments",
".",
"forEach",
"(",
"fragment",
"->",
"{",
"Set",
"<",
"Variable",
">",
"fragmentVarNameSet",
"=",
"Sets",
".",
"newHashSet",
"(",
"fragment",
".",
"vars",
"(",
")",
")",
";",
"List",
"<",
"Integer",
">",
"setsWithVarInCommon",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"varSetMap",
".",
"forEach",
"(",
"(",
"setIndex",
",",
"varNameSet",
")",
"->",
"{",
"if",
"(",
"!",
"Collections",
".",
"disjoint",
"(",
"varNameSet",
",",
"fragmentVarNameSet",
")",
")",
"{",
"setsWithVarInCommon",
".",
"add",
"(",
"setIndex",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"setsWithVarInCommon",
".",
"isEmpty",
"(",
")",
")",
"{",
"index",
"[",
"0",
"]",
"+=",
"1",
";",
"varSetMap",
".",
"put",
"(",
"index",
"[",
"0",
"]",
",",
"fragmentVarNameSet",
")",
";",
"fragmentSetMap",
".",
"put",
"(",
"index",
"[",
"0",
"]",
",",
"Sets",
".",
"newHashSet",
"(",
"fragment",
")",
")",
";",
"}",
"else",
"{",
"Iterator",
"<",
"Integer",
">",
"iterator",
"=",
"setsWithVarInCommon",
".",
"iterator",
"(",
")",
";",
"Integer",
"firstSet",
"=",
"iterator",
".",
"next",
"(",
")",
";",
"varSetMap",
".",
"get",
"(",
"firstSet",
")",
".",
"addAll",
"(",
"fragmentVarNameSet",
")",
";",
"fragmentSetMap",
".",
"get",
"(",
"firstSet",
")",
".",
"add",
"(",
"fragment",
")",
";",
"while",
"(",
"iterator",
".",
"hasNext",
"(",
")",
")",
"{",
"Integer",
"nextSet",
"=",
"iterator",
".",
"next",
"(",
")",
";",
"varSetMap",
".",
"get",
"(",
"firstSet",
")",
".",
"addAll",
"(",
"varSetMap",
".",
"remove",
"(",
"nextSet",
")",
")",
";",
"fragmentSetMap",
".",
"get",
"(",
"firstSet",
")",
".",
"addAll",
"(",
"fragmentSetMap",
".",
"remove",
"(",
"nextSet",
")",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"fragmentSetMap",
".",
"values",
"(",
")",
";",
"}"
] | return a collection of set, in each set, all the fragments are connected | [
"return",
"a",
"collection",
"of",
"set",
"in",
"each",
"set",
"all",
"the",
"fragments",
"are",
"connected"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/TraversalPlanner.java#L252-L283 |
22,935 | graknlabs/grakn | server/src/graql/gremlin/TraversalPlanner.java | TraversalPlanner.updateFixedCostSubsReachableByIndex | private static void updateFixedCostSubsReachableByIndex(ImmutableMap<NodeId, Node> allNodes,
Map<Node, Double> nodesWithFixedCost,
Set<Fragment> fragments) {
Set<Fragment> validSubFragments = fragments.stream().filter(fragment -> {
if (fragment instanceof InSubFragment) {
Node superType = allNodes.get(NodeId.of(NodeId.NodeType.VAR, fragment.start()));
if (nodesWithFixedCost.containsKey(superType) && nodesWithFixedCost.get(superType) > 0D) {
Node subType = allNodes.get(NodeId.of(NodeId.NodeType.VAR, fragment.end()));
return !nodesWithFixedCost.containsKey(subType);
}
}
return false;
}).collect(Collectors.toSet());
if (!validSubFragments.isEmpty()) {
validSubFragments.forEach(fragment -> {
// TODO: should decrease the weight of sub type after each level
nodesWithFixedCost.put(allNodes.get(NodeId.of(NodeId.NodeType.VAR, fragment.end())),
nodesWithFixedCost.get(allNodes.get(NodeId.of(NodeId.NodeType.VAR, fragment.start()))));
});
// recursively process all the sub fragments
updateFixedCostSubsReachableByIndex(allNodes, nodesWithFixedCost, fragments);
}
} | java | private static void updateFixedCostSubsReachableByIndex(ImmutableMap<NodeId, Node> allNodes,
Map<Node, Double> nodesWithFixedCost,
Set<Fragment> fragments) {
Set<Fragment> validSubFragments = fragments.stream().filter(fragment -> {
if (fragment instanceof InSubFragment) {
Node superType = allNodes.get(NodeId.of(NodeId.NodeType.VAR, fragment.start()));
if (nodesWithFixedCost.containsKey(superType) && nodesWithFixedCost.get(superType) > 0D) {
Node subType = allNodes.get(NodeId.of(NodeId.NodeType.VAR, fragment.end()));
return !nodesWithFixedCost.containsKey(subType);
}
}
return false;
}).collect(Collectors.toSet());
if (!validSubFragments.isEmpty()) {
validSubFragments.forEach(fragment -> {
// TODO: should decrease the weight of sub type after each level
nodesWithFixedCost.put(allNodes.get(NodeId.of(NodeId.NodeType.VAR, fragment.end())),
nodesWithFixedCost.get(allNodes.get(NodeId.of(NodeId.NodeType.VAR, fragment.start()))));
});
// recursively process all the sub fragments
updateFixedCostSubsReachableByIndex(allNodes, nodesWithFixedCost, fragments);
}
} | [
"private",
"static",
"void",
"updateFixedCostSubsReachableByIndex",
"(",
"ImmutableMap",
"<",
"NodeId",
",",
"Node",
">",
"allNodes",
",",
"Map",
"<",
"Node",
",",
"Double",
">",
"nodesWithFixedCost",
",",
"Set",
"<",
"Fragment",
">",
"fragments",
")",
"{",
"Set",
"<",
"Fragment",
">",
"validSubFragments",
"=",
"fragments",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"fragment",
"->",
"{",
"if",
"(",
"fragment",
"instanceof",
"InSubFragment",
")",
"{",
"Node",
"superType",
"=",
"allNodes",
".",
"get",
"(",
"NodeId",
".",
"of",
"(",
"NodeId",
".",
"NodeType",
".",
"VAR",
",",
"fragment",
".",
"start",
"(",
")",
")",
")",
";",
"if",
"(",
"nodesWithFixedCost",
".",
"containsKey",
"(",
"superType",
")",
"&&",
"nodesWithFixedCost",
".",
"get",
"(",
"superType",
")",
">",
"0D",
")",
"{",
"Node",
"subType",
"=",
"allNodes",
".",
"get",
"(",
"NodeId",
".",
"of",
"(",
"NodeId",
".",
"NodeType",
".",
"VAR",
",",
"fragment",
".",
"end",
"(",
")",
")",
")",
";",
"return",
"!",
"nodesWithFixedCost",
".",
"containsKey",
"(",
"subType",
")",
";",
"}",
"}",
"return",
"false",
";",
"}",
")",
".",
"collect",
"(",
"Collectors",
".",
"toSet",
"(",
")",
")",
";",
"if",
"(",
"!",
"validSubFragments",
".",
"isEmpty",
"(",
")",
")",
"{",
"validSubFragments",
".",
"forEach",
"(",
"fragment",
"->",
"{",
"// TODO: should decrease the weight of sub type after each level",
"nodesWithFixedCost",
".",
"put",
"(",
"allNodes",
".",
"get",
"(",
"NodeId",
".",
"of",
"(",
"NodeId",
".",
"NodeType",
".",
"VAR",
",",
"fragment",
".",
"end",
"(",
")",
")",
")",
",",
"nodesWithFixedCost",
".",
"get",
"(",
"allNodes",
".",
"get",
"(",
"NodeId",
".",
"of",
"(",
"NodeId",
".",
"NodeType",
".",
"VAR",
",",
"fragment",
".",
"start",
"(",
")",
")",
")",
")",
")",
";",
"}",
")",
";",
"// recursively process all the sub fragments",
"updateFixedCostSubsReachableByIndex",
"(",
"allNodes",
",",
"nodesWithFixedCost",
",",
"fragments",
")",
";",
"}",
"}"
] | if in-sub starts from an indexed supertype, update the fragment cost of in-isa starting from the subtypes | [
"if",
"in",
"-",
"sub",
"starts",
"from",
"an",
"indexed",
"supertype",
"update",
"the",
"fragment",
"cost",
"of",
"in",
"-",
"isa",
"starting",
"from",
"the",
"subtypes"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/TraversalPlanner.java#L301-L325 |
22,936 | graknlabs/grakn | server/src/graql/gremlin/GraqlTraversal.java | GraqlTraversal.getGraphTraversal | @SuppressWarnings("unchecked")
public GraphTraversal<Vertex, Map<String, Element>> getGraphTraversal(TransactionOLTP tx, Set<Variable> vars) {
if (fragments().size() == 1) {
// If there are no disjunctions, we don't need to union them and get a performance boost
ImmutableList<Fragment> list = Iterables.getOnlyElement(fragments());
return getConjunctionTraversal(tx, tx.getTinkerTraversal().V(), vars, list);
} else {
Traversal[] traversals = fragments().stream()
.map(list -> getConjunctionTraversal(tx, __.V(), vars, list))
.toArray(Traversal[]::new);
// This is a sneaky trick - we want to do a union but tinkerpop requires all traversals to start from
// somewhere, so we start from a single arbitrary vertex.
GraphTraversal traversal = tx.getTinkerTraversal().V().limit(1).union(traversals);
return selectVars(traversal, vars);
}
} | java | @SuppressWarnings("unchecked")
public GraphTraversal<Vertex, Map<String, Element>> getGraphTraversal(TransactionOLTP tx, Set<Variable> vars) {
if (fragments().size() == 1) {
// If there are no disjunctions, we don't need to union them and get a performance boost
ImmutableList<Fragment> list = Iterables.getOnlyElement(fragments());
return getConjunctionTraversal(tx, tx.getTinkerTraversal().V(), vars, list);
} else {
Traversal[] traversals = fragments().stream()
.map(list -> getConjunctionTraversal(tx, __.V(), vars, list))
.toArray(Traversal[]::new);
// This is a sneaky trick - we want to do a union but tinkerpop requires all traversals to start from
// somewhere, so we start from a single arbitrary vertex.
GraphTraversal traversal = tx.getTinkerTraversal().V().limit(1).union(traversals);
return selectVars(traversal, vars);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"GraphTraversal",
"<",
"Vertex",
",",
"Map",
"<",
"String",
",",
"Element",
">",
">",
"getGraphTraversal",
"(",
"TransactionOLTP",
"tx",
",",
"Set",
"<",
"Variable",
">",
"vars",
")",
"{",
"if",
"(",
"fragments",
"(",
")",
".",
"size",
"(",
")",
"==",
"1",
")",
"{",
"// If there are no disjunctions, we don't need to union them and get a performance boost",
"ImmutableList",
"<",
"Fragment",
">",
"list",
"=",
"Iterables",
".",
"getOnlyElement",
"(",
"fragments",
"(",
")",
")",
";",
"return",
"getConjunctionTraversal",
"(",
"tx",
",",
"tx",
".",
"getTinkerTraversal",
"(",
")",
".",
"V",
"(",
")",
",",
"vars",
",",
"list",
")",
";",
"}",
"else",
"{",
"Traversal",
"[",
"]",
"traversals",
"=",
"fragments",
"(",
")",
".",
"stream",
"(",
")",
".",
"map",
"(",
"list",
"->",
"getConjunctionTraversal",
"(",
"tx",
",",
"__",
".",
"V",
"(",
")",
",",
"vars",
",",
"list",
")",
")",
".",
"toArray",
"(",
"Traversal",
"[",
"]",
"::",
"new",
")",
";",
"// This is a sneaky trick - we want to do a union but tinkerpop requires all traversals to start from",
"// somewhere, so we start from a single arbitrary vertex.",
"GraphTraversal",
"traversal",
"=",
"tx",
".",
"getTinkerTraversal",
"(",
")",
".",
"V",
"(",
")",
".",
"limit",
"(",
"1",
")",
".",
"union",
"(",
"traversals",
")",
";",
"return",
"selectVars",
"(",
"traversal",
",",
"vars",
")",
";",
"}",
"}"
] | Because 'union' accepts an array, we can't use generics | [
"Because",
"union",
"accepts",
"an",
"array",
"we",
"can",
"t",
"use",
"generics"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/GraqlTraversal.java#L70-L88 |
22,937 | graknlabs/grakn | server/src/graql/gremlin/GraqlTraversal.java | GraqlTraversal.getComplexity | public double getComplexity() {
double totalCost = 0;
for (List<Fragment> list : fragments()) {
totalCost += fragmentListCost(list);
}
return totalCost;
} | java | public double getComplexity() {
double totalCost = 0;
for (List<Fragment> list : fragments()) {
totalCost += fragmentListCost(list);
}
return totalCost;
} | [
"public",
"double",
"getComplexity",
"(",
")",
"{",
"double",
"totalCost",
"=",
"0",
";",
"for",
"(",
"List",
"<",
"Fragment",
">",
"list",
":",
"fragments",
"(",
")",
")",
"{",
"totalCost",
"+=",
"fragmentListCost",
"(",
"list",
")",
";",
"}",
"return",
"totalCost",
";",
"}"
] | Get the estimated complexity of the traversal. | [
"Get",
"the",
"estimated",
"complexity",
"of",
"the",
"traversal",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/GraqlTraversal.java#L147-L156 |
22,938 | graknlabs/grakn | server/src/server/session/TransactionOLTP.java | TransactionOLTP.addVertexElementWithEdgeIdProperty | public VertexElement addVertexElementWithEdgeIdProperty(Schema.BaseType baseType, ConceptId conceptId) {
return executeLockingMethod(() -> factory().addVertexElementWithEdgeIdProperty(baseType, conceptId));
} | java | public VertexElement addVertexElementWithEdgeIdProperty(Schema.BaseType baseType, ConceptId conceptId) {
return executeLockingMethod(() -> factory().addVertexElementWithEdgeIdProperty(baseType, conceptId));
} | [
"public",
"VertexElement",
"addVertexElementWithEdgeIdProperty",
"(",
"Schema",
".",
"BaseType",
"baseType",
",",
"ConceptId",
"conceptId",
")",
"{",
"return",
"executeLockingMethod",
"(",
"(",
")",
"->",
"factory",
"(",
")",
".",
"addVertexElementWithEdgeIdProperty",
"(",
"baseType",
",",
"conceptId",
")",
")",
";",
"}"
] | This is only used when reifying a Relation
@param baseType Concept BaseType which will become the VertexLabel
@param conceptId ConceptId to be set on the vertex
@return just created Vertex | [
"This",
"is",
"only",
"used",
"when",
"reifying",
"a",
"Relation"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/TransactionOLTP.java#L212-L214 |
22,939 | graknlabs/grakn | server/src/server/session/TransactionOLTP.java | TransactionOLTP.executeLockingMethod | private <X> X executeLockingMethod(Supplier<X> method) {
try {
return method.get();
} catch (JanusGraphException e) {
if (e.isCausedBy(TemporaryLockingException.class) || e.isCausedBy(PermanentLockingException.class)) {
throw TemporaryWriteException.temporaryLock(e);
} else {
throw GraknServerException.unknown(e);
}
}
} | java | private <X> X executeLockingMethod(Supplier<X> method) {
try {
return method.get();
} catch (JanusGraphException e) {
if (e.isCausedBy(TemporaryLockingException.class) || e.isCausedBy(PermanentLockingException.class)) {
throw TemporaryWriteException.temporaryLock(e);
} else {
throw GraknServerException.unknown(e);
}
}
} | [
"private",
"<",
"X",
">",
"X",
"executeLockingMethod",
"(",
"Supplier",
"<",
"X",
">",
"method",
")",
"{",
"try",
"{",
"return",
"method",
".",
"get",
"(",
")",
";",
"}",
"catch",
"(",
"JanusGraphException",
"e",
")",
"{",
"if",
"(",
"e",
".",
"isCausedBy",
"(",
"TemporaryLockingException",
".",
"class",
")",
"||",
"e",
".",
"isCausedBy",
"(",
"PermanentLockingException",
".",
"class",
")",
")",
"{",
"throw",
"TemporaryWriteException",
".",
"temporaryLock",
"(",
"e",
")",
";",
"}",
"else",
"{",
"throw",
"GraknServerException",
".",
"unknown",
"(",
"e",
")",
";",
"}",
"}",
"}"
] | Executes a method which has the potential to throw a TemporaryLockingException or a PermanentLockingException.
If the exception is thrown it is wrapped in a GraknServerException so that the transaction can be retried.
@param method The locking method to execute | [
"Executes",
"a",
"method",
"which",
"has",
"the",
"potential",
"to",
"throw",
"a",
"TemporaryLockingException",
"or",
"a",
"PermanentLockingException",
".",
"If",
"the",
"exception",
"is",
"thrown",
"it",
"is",
"wrapped",
"in",
"a",
"GraknServerException",
"so",
"that",
"the",
"transaction",
"can",
"be",
"retried",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/TransactionOLTP.java#L222-L232 |
22,940 | graknlabs/grakn | server/src/server/session/TransactionOLTP.java | TransactionOLTP.convertToId | public LabelId convertToId(Label label) {
if (transactionCache.isLabelCached(label)) {
return transactionCache.convertLabelToId(label);
}
return LabelId.invalid();
} | java | public LabelId convertToId(Label label) {
if (transactionCache.isLabelCached(label)) {
return transactionCache.convertLabelToId(label);
}
return LabelId.invalid();
} | [
"public",
"LabelId",
"convertToId",
"(",
"Label",
"label",
")",
"{",
"if",
"(",
"transactionCache",
".",
"isLabelCached",
"(",
"label",
")",
")",
"{",
"return",
"transactionCache",
".",
"convertLabelToId",
"(",
"label",
")",
";",
"}",
"return",
"LabelId",
".",
"invalid",
"(",
")",
";",
"}"
] | Converts a Type Label into a type Id for this specific graph. Mapping labels to ids will differ between graphs
so be sure to use the correct graph when performing the mapping.
@param label The label to be converted to the id
@return The matching type id | [
"Converts",
"a",
"Type",
"Label",
"into",
"a",
"type",
"Id",
"for",
"this",
"specific",
"graph",
".",
"Mapping",
"labels",
"to",
"ids",
"will",
"differ",
"between",
"graphs",
"so",
"be",
"sure",
"to",
"use",
"the",
"correct",
"graph",
"when",
"performing",
"the",
"mapping",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/TransactionOLTP.java#L321-L326 |
22,941 | graknlabs/grakn | server/src/server/session/TransactionOLTP.java | TransactionOLTP.getNextId | private LabelId getNextId() {
TypeImpl<?, ?> metaConcept = (TypeImpl<?, ?>) getMetaConcept();
Integer currentValue = metaConcept.vertex().property(Schema.VertexProperty.CURRENT_LABEL_ID);
if (currentValue == null) {
currentValue = Schema.MetaSchema.values().length + 1;
} else {
currentValue = currentValue + 1;
}
//Vertex is used directly here to bypass meta type mutation check
metaConcept.property(Schema.VertexProperty.CURRENT_LABEL_ID, currentValue);
return LabelId.of(currentValue);
} | java | private LabelId getNextId() {
TypeImpl<?, ?> metaConcept = (TypeImpl<?, ?>) getMetaConcept();
Integer currentValue = metaConcept.vertex().property(Schema.VertexProperty.CURRENT_LABEL_ID);
if (currentValue == null) {
currentValue = Schema.MetaSchema.values().length + 1;
} else {
currentValue = currentValue + 1;
}
//Vertex is used directly here to bypass meta type mutation check
metaConcept.property(Schema.VertexProperty.CURRENT_LABEL_ID, currentValue);
return LabelId.of(currentValue);
} | [
"private",
"LabelId",
"getNextId",
"(",
")",
"{",
"TypeImpl",
"<",
"?",
",",
"?",
">",
"metaConcept",
"=",
"(",
"TypeImpl",
"<",
"?",
",",
"?",
">",
")",
"getMetaConcept",
"(",
")",
";",
"Integer",
"currentValue",
"=",
"metaConcept",
".",
"vertex",
"(",
")",
".",
"property",
"(",
"Schema",
".",
"VertexProperty",
".",
"CURRENT_LABEL_ID",
")",
";",
"if",
"(",
"currentValue",
"==",
"null",
")",
"{",
"currentValue",
"=",
"Schema",
".",
"MetaSchema",
".",
"values",
"(",
")",
".",
"length",
"+",
"1",
";",
"}",
"else",
"{",
"currentValue",
"=",
"currentValue",
"+",
"1",
";",
"}",
"//Vertex is used directly here to bypass meta type mutation check",
"metaConcept",
".",
"property",
"(",
"Schema",
".",
"VertexProperty",
".",
"CURRENT_LABEL_ID",
",",
"currentValue",
")",
";",
"return",
"LabelId",
".",
"of",
"(",
"currentValue",
")",
";",
"}"
] | Gets and increments the current available type id.
@return the current available Grakn id which can be used for types | [
"Gets",
"and",
"increments",
"the",
"current",
"available",
"type",
"id",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/TransactionOLTP.java#L333-L344 |
22,942 | graknlabs/grakn | server/src/server/session/TransactionOLTP.java | TransactionOLTP.getTinkerTraversal | public GraphTraversalSource getTinkerTraversal() {
operateOnOpenGraph(() -> null); //This is to check if the graph is open
if (graphTraversalSource == null) {
graphTraversalSource = janusGraph.traversal().withStrategies(ReadOnlyStrategy.instance());
}
return graphTraversalSource;
} | java | public GraphTraversalSource getTinkerTraversal() {
operateOnOpenGraph(() -> null); //This is to check if the graph is open
if (graphTraversalSource == null) {
graphTraversalSource = janusGraph.traversal().withStrategies(ReadOnlyStrategy.instance());
}
return graphTraversalSource;
} | [
"public",
"GraphTraversalSource",
"getTinkerTraversal",
"(",
")",
"{",
"operateOnOpenGraph",
"(",
"(",
")",
"->",
"null",
")",
";",
"//This is to check if the graph is open",
"if",
"(",
"graphTraversalSource",
"==",
"null",
")",
"{",
"graphTraversalSource",
"=",
"janusGraph",
".",
"traversal",
"(",
")",
".",
"withStrategies",
"(",
"ReadOnlyStrategy",
".",
"instance",
"(",
")",
")",
";",
"}",
"return",
"graphTraversalSource",
";",
"}"
] | Utility function to get a read-only Tinkerpop traversal.
@return A read-only Tinkerpop traversal for manually traversing the graph | [
"Utility",
"function",
"to",
"get",
"a",
"read",
"-",
"only",
"Tinkerpop",
"traversal",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/TransactionOLTP.java#L394-L400 |
22,943 | graknlabs/grakn | server/src/server/session/TransactionOLTP.java | TransactionOLTP.addTypeVertex | protected VertexElement addTypeVertex(LabelId id, Label label, Schema.BaseType baseType) {
VertexElement vertexElement = addVertexElement(baseType);
vertexElement.property(Schema.VertexProperty.SCHEMA_LABEL, label.getValue());
vertexElement.property(Schema.VertexProperty.LABEL_ID, id.getValue());
return vertexElement;
} | java | protected VertexElement addTypeVertex(LabelId id, Label label, Schema.BaseType baseType) {
VertexElement vertexElement = addVertexElement(baseType);
vertexElement.property(Schema.VertexProperty.SCHEMA_LABEL, label.getValue());
vertexElement.property(Schema.VertexProperty.LABEL_ID, id.getValue());
return vertexElement;
} | [
"protected",
"VertexElement",
"addTypeVertex",
"(",
"LabelId",
"id",
",",
"Label",
"label",
",",
"Schema",
".",
"BaseType",
"baseType",
")",
"{",
"VertexElement",
"vertexElement",
"=",
"addVertexElement",
"(",
"baseType",
")",
";",
"vertexElement",
".",
"property",
"(",
"Schema",
".",
"VertexProperty",
".",
"SCHEMA_LABEL",
",",
"label",
".",
"getValue",
"(",
")",
")",
";",
"vertexElement",
".",
"property",
"(",
"Schema",
".",
"VertexProperty",
".",
"LABEL_ID",
",",
"id",
".",
"getValue",
"(",
")",
")",
";",
"return",
"vertexElement",
";",
"}"
] | Adds a new type vertex which occupies a grakn id. This result in the grakn id count on the meta concept to be
incremented.
@param label The label of the new type vertex
@param baseType The base type of the new type
@return The new type vertex | [
"Adds",
"a",
"new",
"type",
"vertex",
"which",
"occupies",
"a",
"grakn",
"id",
".",
"This",
"result",
"in",
"the",
"grakn",
"id",
"count",
"on",
"the",
"meta",
"concept",
"to",
"be",
"incremented",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/TransactionOLTP.java#L463-L468 |
22,944 | graknlabs/grakn | server/src/server/session/TransactionOLTP.java | TransactionOLTP.operateOnOpenGraph | private <X> X operateOnOpenGraph(Supplier<X> supplier) {
if (!isLocal() || isClosed()) throw TransactionException.transactionClosed(this, this.closedReason);
return supplier.get();
} | java | private <X> X operateOnOpenGraph(Supplier<X> supplier) {
if (!isLocal() || isClosed()) throw TransactionException.transactionClosed(this, this.closedReason);
return supplier.get();
} | [
"private",
"<",
"X",
">",
"X",
"operateOnOpenGraph",
"(",
"Supplier",
"<",
"X",
">",
"supplier",
")",
"{",
"if",
"(",
"!",
"isLocal",
"(",
")",
"||",
"isClosed",
"(",
")",
")",
"throw",
"TransactionException",
".",
"transactionClosed",
"(",
"this",
",",
"this",
".",
"closedReason",
")",
";",
"return",
"supplier",
".",
"get",
"(",
")",
";",
"}"
] | An operation on the graph which requires it to be open.
@param supplier The operation to be performed on the graph
@return The result of the operation on the graph.
@throws TransactionException if the graph is closed. | [
"An",
"operation",
"on",
"the",
"graph",
"which",
"requires",
"it",
"to",
"be",
"open",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/TransactionOLTP.java#L477-L480 |
22,945 | graknlabs/grakn | server/src/server/session/TransactionOLTP.java | TransactionOLTP.labelTaken | private TransactionException labelTaken(SchemaConcept schemaConcept) {
if (Schema.MetaSchema.isMetaLabel(schemaConcept.label())) {
return TransactionException.reservedLabel(schemaConcept.label());
}
return PropertyNotUniqueException.cannotCreateProperty(schemaConcept, Schema.VertexProperty.SCHEMA_LABEL, schemaConcept.label());
} | java | private TransactionException labelTaken(SchemaConcept schemaConcept) {
if (Schema.MetaSchema.isMetaLabel(schemaConcept.label())) {
return TransactionException.reservedLabel(schemaConcept.label());
}
return PropertyNotUniqueException.cannotCreateProperty(schemaConcept, Schema.VertexProperty.SCHEMA_LABEL, schemaConcept.label());
} | [
"private",
"TransactionException",
"labelTaken",
"(",
"SchemaConcept",
"schemaConcept",
")",
"{",
"if",
"(",
"Schema",
".",
"MetaSchema",
".",
"isMetaLabel",
"(",
"schemaConcept",
".",
"label",
"(",
")",
")",
")",
"{",
"return",
"TransactionException",
".",
"reservedLabel",
"(",
"schemaConcept",
".",
"label",
"(",
")",
")",
";",
"}",
"return",
"PropertyNotUniqueException",
".",
"cannotCreateProperty",
"(",
"schemaConcept",
",",
"Schema",
".",
"VertexProperty",
".",
"SCHEMA_LABEL",
",",
"schemaConcept",
".",
"label",
"(",
")",
")",
";",
"}"
] | Throws an exception when adding a SchemaConcept using a Label which is already taken | [
"Throws",
"an",
"exception",
"when",
"adding",
"a",
"SchemaConcept",
"using",
"a",
"Label",
"which",
"is",
"already",
"taken"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/TransactionOLTP.java#L544-L549 |
22,946 | graknlabs/grakn | server/src/server/session/TransactionOLTP.java | TransactionOLTP.commit | @Override
public void commit() throws InvalidKBException {
if (isClosed()) {
return;
}
try {
checkMutationAllowed();
removeInferredConcepts();
validateGraph();
// lock on the keyspace cache shared between concurrent tx's to the same keyspace
// force serialization & atomic updates, keeping Janus and our KeyspaceCache in sync
synchronized (keyspaceCache) {
commitTransactionInternal();
transactionCache.flushToKeyspaceCache();
}
} finally {
String closeMessage = ErrorMessage.TX_CLOSED_ON_ACTION.getMessage("committed", keyspace());
closeTransaction(closeMessage);
}
} | java | @Override
public void commit() throws InvalidKBException {
if (isClosed()) {
return;
}
try {
checkMutationAllowed();
removeInferredConcepts();
validateGraph();
// lock on the keyspace cache shared between concurrent tx's to the same keyspace
// force serialization & atomic updates, keeping Janus and our KeyspaceCache in sync
synchronized (keyspaceCache) {
commitTransactionInternal();
transactionCache.flushToKeyspaceCache();
}
} finally {
String closeMessage = ErrorMessage.TX_CLOSED_ON_ACTION.getMessage("committed", keyspace());
closeTransaction(closeMessage);
}
} | [
"@",
"Override",
"public",
"void",
"commit",
"(",
")",
"throws",
"InvalidKBException",
"{",
"if",
"(",
"isClosed",
"(",
")",
")",
"{",
"return",
";",
"}",
"try",
"{",
"checkMutationAllowed",
"(",
")",
";",
"removeInferredConcepts",
"(",
")",
";",
"validateGraph",
"(",
")",
";",
"// lock on the keyspace cache shared between concurrent tx's to the same keyspace",
"// force serialization & atomic updates, keeping Janus and our KeyspaceCache in sync",
"synchronized",
"(",
"keyspaceCache",
")",
"{",
"commitTransactionInternal",
"(",
")",
";",
"transactionCache",
".",
"flushToKeyspaceCache",
"(",
")",
";",
"}",
"}",
"finally",
"{",
"String",
"closeMessage",
"=",
"ErrorMessage",
".",
"TX_CLOSED_ON_ACTION",
".",
"getMessage",
"(",
"\"committed\"",
",",
"keyspace",
"(",
")",
")",
";",
"closeTransaction",
"(",
"closeMessage",
")",
";",
"}",
"}"
] | Commits and closes the transaction without returning CommitLog
@throws InvalidKBException | [
"Commits",
"and",
"closes",
"the",
"transaction",
"without",
"returning",
"CommitLog"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/TransactionOLTP.java#L832-L851 |
22,947 | graknlabs/grakn | server/src/server/session/TransactionOLTP.java | TransactionOLTP.commitAndGetLogs | public Optional<CommitLog> commitAndGetLogs() throws InvalidKBException {
if (isClosed()) {
return Optional.empty();
}
try {
return commitWithLogs();
} finally {
String closeMessage = ErrorMessage.TX_CLOSED_ON_ACTION.getMessage("committed", keyspace());
closeTransaction(closeMessage);
}
} | java | public Optional<CommitLog> commitAndGetLogs() throws InvalidKBException {
if (isClosed()) {
return Optional.empty();
}
try {
return commitWithLogs();
} finally {
String closeMessage = ErrorMessage.TX_CLOSED_ON_ACTION.getMessage("committed", keyspace());
closeTransaction(closeMessage);
}
} | [
"public",
"Optional",
"<",
"CommitLog",
">",
"commitAndGetLogs",
"(",
")",
"throws",
"InvalidKBException",
"{",
"if",
"(",
"isClosed",
"(",
")",
")",
"{",
"return",
"Optional",
".",
"empty",
"(",
")",
";",
"}",
"try",
"{",
"return",
"commitWithLogs",
"(",
")",
";",
"}",
"finally",
"{",
"String",
"closeMessage",
"=",
"ErrorMessage",
".",
"TX_CLOSED_ON_ACTION",
".",
"getMessage",
"(",
"\"committed\"",
",",
"keyspace",
"(",
")",
")",
";",
"closeTransaction",
"(",
"closeMessage",
")",
";",
"}",
"}"
] | Commits, closes transaction and returns CommitLog.
@return the commit log that would have been submitted if it is needed.
@throws InvalidKBException when the graph does not conform to the object concept | [
"Commits",
"closes",
"transaction",
"and",
"returns",
"CommitLog",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/TransactionOLTP.java#L859-L869 |
22,948 | graknlabs/grakn | server/src/server/session/TransactionOLTP.java | TransactionOLTP.shard | public void shard(ConceptId conceptId) {
ConceptImpl type = getConcept(conceptId);
if (type == null) {
LOG.warn("Cannot shard concept [" + conceptId + "] due to it not existing in the graph");
} else {
type.createShard();
}
} | java | public void shard(ConceptId conceptId) {
ConceptImpl type = getConcept(conceptId);
if (type == null) {
LOG.warn("Cannot shard concept [" + conceptId + "] due to it not existing in the graph");
} else {
type.createShard();
}
} | [
"public",
"void",
"shard",
"(",
"ConceptId",
"conceptId",
")",
"{",
"ConceptImpl",
"type",
"=",
"getConcept",
"(",
"conceptId",
")",
";",
"if",
"(",
"type",
"==",
"null",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Cannot shard concept [\"",
"+",
"conceptId",
"+",
"\"] due to it not existing in the graph\"",
")",
";",
"}",
"else",
"{",
"type",
".",
"createShard",
"(",
")",
";",
"}",
"}"
] | Creates a new shard for the concept
@param conceptId the id of the concept to shard | [
"Creates",
"a",
"new",
"shard",
"for",
"the",
"concept"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/TransactionOLTP.java#L946-L953 |
22,949 | graknlabs/grakn | server/src/server/session/TransactionOLTP.java | TransactionOLTP.getShardCount | public long getShardCount(grakn.core.concept.type.Type concept) {
return TypeImpl.from(concept).shardCount();
} | java | public long getShardCount(grakn.core.concept.type.Type concept) {
return TypeImpl.from(concept).shardCount();
} | [
"public",
"long",
"getShardCount",
"(",
"grakn",
".",
"core",
".",
"concept",
".",
"type",
".",
"Type",
"concept",
")",
"{",
"return",
"TypeImpl",
".",
"from",
"(",
"concept",
")",
".",
"shardCount",
"(",
")",
";",
"}"
] | Returns the current number of shards the provided grakn.core.concept.type.Type has. This is used in creating more
efficient query plans.
@param concept The grakn.core.concept.type.Type which may contain some shards.
@return the number of Shards the grakn.core.concept.type.Type currently has. | [
"Returns",
"the",
"current",
"number",
"of",
"shards",
"the",
"provided",
"grakn",
".",
"core",
".",
"concept",
".",
"type",
".",
"Type",
"has",
".",
"This",
"is",
"used",
"in",
"creating",
"more",
"efficient",
"query",
"plans",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/TransactionOLTP.java#L962-L964 |
22,950 | graknlabs/grakn | server/src/server/session/SessionFactory.java | SessionFactory.session | public SessionImpl session(KeyspaceImpl keyspace) {
JanusGraph graph;
KeyspaceCache cache;
KeyspaceCacheContainer cacheContainer;
ReadWriteLock graphLock;
Lock lock = lockManager.getLock(getLockingKey(keyspace));
lock.lock();
try {
// If keyspace reference already in cache, retrieve open graph and keyspace cache
if (keyspaceCacheMap.containsKey(keyspace)) {
cacheContainer = keyspaceCacheMap.get(keyspace);
graph = cacheContainer.graph();
cache = cacheContainer.cache();
graphLock = cacheContainer.graphLock();
} else { // If keyspace reference not cached, put keyspace in keyspace manager, open new graph and instantiate new keyspace cache
keyspaceManager.putKeyspace(keyspace);
graph = janusGraphFactory.openGraph(keyspace.name());
cache = new KeyspaceCache();
graphLock = new ReentrantReadWriteLock();
cacheContainer = new KeyspaceCacheContainer(cache, graph, graphLock);
keyspaceCacheMap.put(keyspace, cacheContainer);
}
SessionImpl session = new SessionImpl(keyspace, config, cache, graph, graphLock);
session.setOnClose(this::onSessionClose);
cacheContainer.addSessionReference(session);
return session;
} finally {
lock.unlock();
}
} | java | public SessionImpl session(KeyspaceImpl keyspace) {
JanusGraph graph;
KeyspaceCache cache;
KeyspaceCacheContainer cacheContainer;
ReadWriteLock graphLock;
Lock lock = lockManager.getLock(getLockingKey(keyspace));
lock.lock();
try {
// If keyspace reference already in cache, retrieve open graph and keyspace cache
if (keyspaceCacheMap.containsKey(keyspace)) {
cacheContainer = keyspaceCacheMap.get(keyspace);
graph = cacheContainer.graph();
cache = cacheContainer.cache();
graphLock = cacheContainer.graphLock();
} else { // If keyspace reference not cached, put keyspace in keyspace manager, open new graph and instantiate new keyspace cache
keyspaceManager.putKeyspace(keyspace);
graph = janusGraphFactory.openGraph(keyspace.name());
cache = new KeyspaceCache();
graphLock = new ReentrantReadWriteLock();
cacheContainer = new KeyspaceCacheContainer(cache, graph, graphLock);
keyspaceCacheMap.put(keyspace, cacheContainer);
}
SessionImpl session = new SessionImpl(keyspace, config, cache, graph, graphLock);
session.setOnClose(this::onSessionClose);
cacheContainer.addSessionReference(session);
return session;
} finally {
lock.unlock();
}
} | [
"public",
"SessionImpl",
"session",
"(",
"KeyspaceImpl",
"keyspace",
")",
"{",
"JanusGraph",
"graph",
";",
"KeyspaceCache",
"cache",
";",
"KeyspaceCacheContainer",
"cacheContainer",
";",
"ReadWriteLock",
"graphLock",
";",
"Lock",
"lock",
"=",
"lockManager",
".",
"getLock",
"(",
"getLockingKey",
"(",
"keyspace",
")",
")",
";",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"// If keyspace reference already in cache, retrieve open graph and keyspace cache",
"if",
"(",
"keyspaceCacheMap",
".",
"containsKey",
"(",
"keyspace",
")",
")",
"{",
"cacheContainer",
"=",
"keyspaceCacheMap",
".",
"get",
"(",
"keyspace",
")",
";",
"graph",
"=",
"cacheContainer",
".",
"graph",
"(",
")",
";",
"cache",
"=",
"cacheContainer",
".",
"cache",
"(",
")",
";",
"graphLock",
"=",
"cacheContainer",
".",
"graphLock",
"(",
")",
";",
"}",
"else",
"{",
"// If keyspace reference not cached, put keyspace in keyspace manager, open new graph and instantiate new keyspace cache",
"keyspaceManager",
".",
"putKeyspace",
"(",
"keyspace",
")",
";",
"graph",
"=",
"janusGraphFactory",
".",
"openGraph",
"(",
"keyspace",
".",
"name",
"(",
")",
")",
";",
"cache",
"=",
"new",
"KeyspaceCache",
"(",
")",
";",
"graphLock",
"=",
"new",
"ReentrantReadWriteLock",
"(",
")",
";",
"cacheContainer",
"=",
"new",
"KeyspaceCacheContainer",
"(",
"cache",
",",
"graph",
",",
"graphLock",
")",
";",
"keyspaceCacheMap",
".",
"put",
"(",
"keyspace",
",",
"cacheContainer",
")",
";",
"}",
"SessionImpl",
"session",
"=",
"new",
"SessionImpl",
"(",
"keyspace",
",",
"config",
",",
"cache",
",",
"graph",
",",
"graphLock",
")",
";",
"session",
".",
"setOnClose",
"(",
"this",
"::",
"onSessionClose",
")",
";",
"cacheContainer",
".",
"addSessionReference",
"(",
"session",
")",
";",
"return",
"session",
";",
"}",
"finally",
"{",
"lock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] | Retrieves the Session needed to open the Transaction.
This will open a new one Session if it hasn't been opened before
@param keyspace The keyspace of the Session to retrieve
@return a new Session connecting to the provided keyspace | [
"Retrieves",
"the",
"Session",
"needed",
"to",
"open",
"the",
"Transaction",
".",
"This",
"will",
"open",
"a",
"new",
"one",
"Session",
"if",
"it",
"hasn",
"t",
"been",
"opened",
"before"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/SessionFactory.java#L64-L95 |
22,951 | graknlabs/grakn | server/src/server/session/SessionFactory.java | SessionFactory.deleteKeyspace | public void deleteKeyspace(KeyspaceImpl keyspace) {
Lock lock = lockManager.getLock(getLockingKey(keyspace));
lock.lock();
try {
if (keyspaceCacheMap.containsKey(keyspace)) {
KeyspaceCacheContainer container = keyspaceCacheMap.remove(keyspace);
container.graph().close();
container.invalidateSessions();
}
} finally {
lock.unlock();
}
} | java | public void deleteKeyspace(KeyspaceImpl keyspace) {
Lock lock = lockManager.getLock(getLockingKey(keyspace));
lock.lock();
try {
if (keyspaceCacheMap.containsKey(keyspace)) {
KeyspaceCacheContainer container = keyspaceCacheMap.remove(keyspace);
container.graph().close();
container.invalidateSessions();
}
} finally {
lock.unlock();
}
} | [
"public",
"void",
"deleteKeyspace",
"(",
"KeyspaceImpl",
"keyspace",
")",
"{",
"Lock",
"lock",
"=",
"lockManager",
".",
"getLock",
"(",
"getLockingKey",
"(",
"keyspace",
")",
")",
";",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"keyspaceCacheMap",
".",
"containsKey",
"(",
"keyspace",
")",
")",
"{",
"KeyspaceCacheContainer",
"container",
"=",
"keyspaceCacheMap",
".",
"remove",
"(",
"keyspace",
")",
";",
"container",
".",
"graph",
"(",
")",
".",
"close",
"(",
")",
";",
"container",
".",
"invalidateSessions",
"(",
")",
";",
"}",
"}",
"finally",
"{",
"lock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] | Invoked when user deletes a keyspace.
Remove keyspace reference from internal cache, closes graph associated to it and
invalidates all the open sessions.
@param keyspace keyspace that is being deleted | [
"Invoked",
"when",
"user",
"deletes",
"a",
"keyspace",
".",
"Remove",
"keyspace",
"reference",
"from",
"internal",
"cache",
"closes",
"graph",
"associated",
"to",
"it",
"and",
"invalidates",
"all",
"the",
"open",
"sessions",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/SessionFactory.java#L104-L116 |
22,952 | graknlabs/grakn | server/src/server/session/SessionFactory.java | SessionFactory.onSessionClose | protected void onSessionClose(SessionImpl session) {
Lock lock = lockManager.getLock(getLockingKey(session.keyspace()));
lock.lock();
try {
if (keyspaceCacheMap.containsKey(session.keyspace())) {
KeyspaceCacheContainer cacheContainer = keyspaceCacheMap.get(session.keyspace());
cacheContainer.removeSessionReference(session);
// If there are no more sessions associated to current keyspace,
// close graph and remove reference from cache.
if (cacheContainer.referenceCount() == 0) {
JanusGraph graph = cacheContainer.graph();
graph.close();
keyspaceCacheMap.remove(session.keyspace());
}
}
} finally {
lock.unlock();
}
} | java | protected void onSessionClose(SessionImpl session) {
Lock lock = lockManager.getLock(getLockingKey(session.keyspace()));
lock.lock();
try {
if (keyspaceCacheMap.containsKey(session.keyspace())) {
KeyspaceCacheContainer cacheContainer = keyspaceCacheMap.get(session.keyspace());
cacheContainer.removeSessionReference(session);
// If there are no more sessions associated to current keyspace,
// close graph and remove reference from cache.
if (cacheContainer.referenceCount() == 0) {
JanusGraph graph = cacheContainer.graph();
graph.close();
keyspaceCacheMap.remove(session.keyspace());
}
}
} finally {
lock.unlock();
}
} | [
"protected",
"void",
"onSessionClose",
"(",
"SessionImpl",
"session",
")",
"{",
"Lock",
"lock",
"=",
"lockManager",
".",
"getLock",
"(",
"getLockingKey",
"(",
"session",
".",
"keyspace",
"(",
")",
")",
")",
";",
"lock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"keyspaceCacheMap",
".",
"containsKey",
"(",
"session",
".",
"keyspace",
"(",
")",
")",
")",
"{",
"KeyspaceCacheContainer",
"cacheContainer",
"=",
"keyspaceCacheMap",
".",
"get",
"(",
"session",
".",
"keyspace",
"(",
")",
")",
";",
"cacheContainer",
".",
"removeSessionReference",
"(",
"session",
")",
";",
"// If there are no more sessions associated to current keyspace,",
"// close graph and remove reference from cache.",
"if",
"(",
"cacheContainer",
".",
"referenceCount",
"(",
")",
"==",
"0",
")",
"{",
"JanusGraph",
"graph",
"=",
"cacheContainer",
".",
"graph",
"(",
")",
";",
"graph",
".",
"close",
"(",
")",
";",
"keyspaceCacheMap",
".",
"remove",
"(",
"session",
".",
"keyspace",
"(",
")",
")",
";",
"}",
"}",
"}",
"finally",
"{",
"lock",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] | Callback function invoked by Session when it gets closed.
This access the keyspaceCacheMap to remove the reference of closed session.
@param session SessionImpl that is being closed | [
"Callback",
"function",
"invoked",
"by",
"Session",
"when",
"it",
"gets",
"closed",
".",
"This",
"access",
"the",
"keyspaceCacheMap",
"to",
"remove",
"the",
"reference",
"of",
"closed",
"session",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/SessionFactory.java#L125-L143 |
22,953 | graknlabs/grakn | server/src/server/kb/ValidateGlobalRules.java | ValidateGlobalRules.validatePlaysAndRelatesStructure | static Set<String> validatePlaysAndRelatesStructure(Casting casting) {
Set<String> errors = new HashSet<>();
//Gets here to make sure we traverse/read only once
Thing thing = casting.getRolePlayer();
Role role = casting.getRole();
Relation relation = casting.getRelation();
//Actual checks
roleNotAllowedToBePlayed(role, thing).ifPresent(errors::add);
roleNotLinkedToRelation(role, relation.type(), relation).ifPresent(errors::add);
return errors;
} | java | static Set<String> validatePlaysAndRelatesStructure(Casting casting) {
Set<String> errors = new HashSet<>();
//Gets here to make sure we traverse/read only once
Thing thing = casting.getRolePlayer();
Role role = casting.getRole();
Relation relation = casting.getRelation();
//Actual checks
roleNotAllowedToBePlayed(role, thing).ifPresent(errors::add);
roleNotLinkedToRelation(role, relation.type(), relation).ifPresent(errors::add);
return errors;
} | [
"static",
"Set",
"<",
"String",
">",
"validatePlaysAndRelatesStructure",
"(",
"Casting",
"casting",
")",
"{",
"Set",
"<",
"String",
">",
"errors",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"//Gets here to make sure we traverse/read only once",
"Thing",
"thing",
"=",
"casting",
".",
"getRolePlayer",
"(",
")",
";",
"Role",
"role",
"=",
"casting",
".",
"getRole",
"(",
")",
";",
"Relation",
"relation",
"=",
"casting",
".",
"getRelation",
"(",
")",
";",
"//Actual checks",
"roleNotAllowedToBePlayed",
"(",
"role",
",",
"thing",
")",
".",
"ifPresent",
"(",
"errors",
"::",
"add",
")",
";",
"roleNotLinkedToRelation",
"(",
"role",
",",
"relation",
".",
"type",
"(",
")",
",",
"relation",
")",
".",
"ifPresent",
"(",
"errors",
"::",
"add",
")",
";",
"return",
"errors",
";",
"}"
] | This method checks if the plays edge has been added between the roleplayer's Type and
the Role being played.
It also checks if the Role of the Casting has been linked to the RelationType of the
Relation which the Casting connects to.
@return Specific errors if any are found | [
"This",
"method",
"checks",
"if",
"the",
"plays",
"edge",
"has",
"been",
"added",
"between",
"the",
"roleplayer",
"s",
"Type",
"and",
"the",
"Role",
"being",
"played",
".",
"It",
"also",
"checks",
"if",
"the",
"Role",
"of",
"the",
"Casting",
"has",
"been",
"linked",
"to",
"the",
"RelationType",
"of",
"the",
"Relation",
"which",
"the",
"Casting",
"connects",
"to",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/ValidateGlobalRules.java#L99-L112 |
22,954 | graknlabs/grakn | server/src/server/kb/ValidateGlobalRules.java | ValidateGlobalRules.roleNotLinkedToRelation | private static Optional<String> roleNotLinkedToRelation(Role role, RelationType relationType, Relation relation) {
boolean notFound = role.relations().
noneMatch(innerRelationType -> innerRelationType.label().equals(relationType.label()));
if (notFound) {
return Optional.of(VALIDATION_RELATION_CASTING_LOOP_FAIL.getMessage(relation.id(), role.label(), relationType.label()));
}
return Optional.empty();
} | java | private static Optional<String> roleNotLinkedToRelation(Role role, RelationType relationType, Relation relation) {
boolean notFound = role.relations().
noneMatch(innerRelationType -> innerRelationType.label().equals(relationType.label()));
if (notFound) {
return Optional.of(VALIDATION_RELATION_CASTING_LOOP_FAIL.getMessage(relation.id(), role.label(), relationType.label()));
}
return Optional.empty();
} | [
"private",
"static",
"Optional",
"<",
"String",
">",
"roleNotLinkedToRelation",
"(",
"Role",
"role",
",",
"RelationType",
"relationType",
",",
"Relation",
"relation",
")",
"{",
"boolean",
"notFound",
"=",
"role",
".",
"relations",
"(",
")",
".",
"noneMatch",
"(",
"innerRelationType",
"->",
"innerRelationType",
".",
"label",
"(",
")",
".",
"equals",
"(",
"relationType",
".",
"label",
"(",
")",
")",
")",
";",
"if",
"(",
"notFound",
")",
"{",
"return",
"Optional",
".",
"of",
"(",
"VALIDATION_RELATION_CASTING_LOOP_FAIL",
".",
"getMessage",
"(",
"relation",
".",
"id",
"(",
")",
",",
"role",
".",
"label",
"(",
")",
",",
"relationType",
".",
"label",
"(",
")",
")",
")",
";",
"}",
"return",
"Optional",
".",
"empty",
"(",
")",
";",
"}"
] | Checks if the Role of the Casting has been linked to the RelationType of
the Relation which the Casting connects to.
@param role the Role which the Casting refers to
@param relationType the RelationType which should connect to the role
@param relation the Relation which the Casting refers to
@return an error if one is found | [
"Checks",
"if",
"the",
"Role",
"of",
"the",
"Casting",
"has",
"been",
"linked",
"to",
"the",
"RelationType",
"of",
"the",
"Relation",
"which",
"the",
"Casting",
"connects",
"to",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/ValidateGlobalRules.java#L123-L130 |
22,955 | graknlabs/grakn | server/src/server/kb/ValidateGlobalRules.java | ValidateGlobalRules.roleNotAllowedToBePlayed | private static Optional<String> roleNotAllowedToBePlayed(Role role, Thing thing) {
TypeImpl<?, ?> currentConcept = (TypeImpl<?, ?>) thing.type();
boolean satisfiesPlays = false;
while (currentConcept != null) {
Map<Role, Boolean> plays = currentConcept.directPlays();
for (Map.Entry<Role, Boolean> playsEntry : plays.entrySet()) {
Role rolePlayed = playsEntry.getKey();
Boolean required = playsEntry.getValue();
if (rolePlayed.label().equals(role.label())) {
satisfiesPlays = true;
// Assert unique relation for this role type
if (required && !CommonUtil.containsOnly(thing.relations(role), 1)) {
return Optional.of(VALIDATION_REQUIRED_RELATION.getMessage(thing.id(), thing.type().label(), role.label(), thing.relations(role).count()));
}
}
}
currentConcept = (TypeImpl) currentConcept.sup();
}
if (satisfiesPlays) {
return Optional.empty();
} else {
return Optional.of(VALIDATION_CASTING.getMessage(thing.type().label(), thing.id(), role.label()));
}
} | java | private static Optional<String> roleNotAllowedToBePlayed(Role role, Thing thing) {
TypeImpl<?, ?> currentConcept = (TypeImpl<?, ?>) thing.type();
boolean satisfiesPlays = false;
while (currentConcept != null) {
Map<Role, Boolean> plays = currentConcept.directPlays();
for (Map.Entry<Role, Boolean> playsEntry : plays.entrySet()) {
Role rolePlayed = playsEntry.getKey();
Boolean required = playsEntry.getValue();
if (rolePlayed.label().equals(role.label())) {
satisfiesPlays = true;
// Assert unique relation for this role type
if (required && !CommonUtil.containsOnly(thing.relations(role), 1)) {
return Optional.of(VALIDATION_REQUIRED_RELATION.getMessage(thing.id(), thing.type().label(), role.label(), thing.relations(role).count()));
}
}
}
currentConcept = (TypeImpl) currentConcept.sup();
}
if (satisfiesPlays) {
return Optional.empty();
} else {
return Optional.of(VALIDATION_CASTING.getMessage(thing.type().label(), thing.id(), role.label()));
}
} | [
"private",
"static",
"Optional",
"<",
"String",
">",
"roleNotAllowedToBePlayed",
"(",
"Role",
"role",
",",
"Thing",
"thing",
")",
"{",
"TypeImpl",
"<",
"?",
",",
"?",
">",
"currentConcept",
"=",
"(",
"TypeImpl",
"<",
"?",
",",
"?",
">",
")",
"thing",
".",
"type",
"(",
")",
";",
"boolean",
"satisfiesPlays",
"=",
"false",
";",
"while",
"(",
"currentConcept",
"!=",
"null",
")",
"{",
"Map",
"<",
"Role",
",",
"Boolean",
">",
"plays",
"=",
"currentConcept",
".",
"directPlays",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"Role",
",",
"Boolean",
">",
"playsEntry",
":",
"plays",
".",
"entrySet",
"(",
")",
")",
"{",
"Role",
"rolePlayed",
"=",
"playsEntry",
".",
"getKey",
"(",
")",
";",
"Boolean",
"required",
"=",
"playsEntry",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"rolePlayed",
".",
"label",
"(",
")",
".",
"equals",
"(",
"role",
".",
"label",
"(",
")",
")",
")",
"{",
"satisfiesPlays",
"=",
"true",
";",
"// Assert unique relation for this role type",
"if",
"(",
"required",
"&&",
"!",
"CommonUtil",
".",
"containsOnly",
"(",
"thing",
".",
"relations",
"(",
"role",
")",
",",
"1",
")",
")",
"{",
"return",
"Optional",
".",
"of",
"(",
"VALIDATION_REQUIRED_RELATION",
".",
"getMessage",
"(",
"thing",
".",
"id",
"(",
")",
",",
"thing",
".",
"type",
"(",
")",
".",
"label",
"(",
")",
",",
"role",
".",
"label",
"(",
")",
",",
"thing",
".",
"relations",
"(",
"role",
")",
".",
"count",
"(",
")",
")",
")",
";",
"}",
"}",
"}",
"currentConcept",
"=",
"(",
"TypeImpl",
")",
"currentConcept",
".",
"sup",
"(",
")",
";",
"}",
"if",
"(",
"satisfiesPlays",
")",
"{",
"return",
"Optional",
".",
"empty",
"(",
")",
";",
"}",
"else",
"{",
"return",
"Optional",
".",
"of",
"(",
"VALIDATION_CASTING",
".",
"getMessage",
"(",
"thing",
".",
"type",
"(",
")",
".",
"label",
"(",
")",
",",
"thing",
".",
"id",
"(",
")",
",",
"role",
".",
"label",
"(",
")",
")",
")",
";",
"}",
"}"
] | Checks if the plays edge has been added between the roleplayer's Type and
the Role being played.
Also checks that required Role are satisfied
@param role The Role which the role-player is playing
@param thing the role-player
@return an error if one is found | [
"Checks",
"if",
"the",
"plays",
"edge",
"has",
"been",
"added",
"between",
"the",
"roleplayer",
"s",
"Type",
"and",
"the",
"Role",
"being",
"played",
".",
"Also",
"checks",
"that",
"required",
"Role",
"are",
"satisfied"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/ValidateGlobalRules.java#L141-L168 |
22,956 | graknlabs/grakn | server/src/server/kb/ValidateGlobalRules.java | ValidateGlobalRules.validateRelationHasRolePlayers | static Optional<String> validateRelationHasRolePlayers(Relation relation) {
if (!relation.rolePlayers().findAny().isPresent()) {
return Optional.of(ErrorMessage.VALIDATION_RELATION_WITH_NO_ROLE_PLAYERS.getMessage(relation.id(), relation.type().label()));
}
return Optional.empty();
} | java | static Optional<String> validateRelationHasRolePlayers(Relation relation) {
if (!relation.rolePlayers().findAny().isPresent()) {
return Optional.of(ErrorMessage.VALIDATION_RELATION_WITH_NO_ROLE_PLAYERS.getMessage(relation.id(), relation.type().label()));
}
return Optional.empty();
} | [
"static",
"Optional",
"<",
"String",
">",
"validateRelationHasRolePlayers",
"(",
"Relation",
"relation",
")",
"{",
"if",
"(",
"!",
"relation",
".",
"rolePlayers",
"(",
")",
".",
"findAny",
"(",
")",
".",
"isPresent",
"(",
")",
")",
"{",
"return",
"Optional",
".",
"of",
"(",
"ErrorMessage",
".",
"VALIDATION_RELATION_WITH_NO_ROLE_PLAYERS",
".",
"getMessage",
"(",
"relation",
".",
"id",
"(",
")",
",",
"relation",
".",
"type",
"(",
")",
".",
"label",
"(",
")",
")",
")",
";",
"}",
"return",
"Optional",
".",
"empty",
"(",
")",
";",
"}"
] | Checks if a Relation has at least one role player.
@param relation The Relation to check | [
"Checks",
"if",
"a",
"Relation",
"has",
"at",
"least",
"one",
"role",
"player",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/ValidateGlobalRules.java#L424-L429 |
22,957 | graknlabs/grakn | server/src/graql/reasoner/atom/Atom.java | Atom.rewriteWithTypeVariable | public Atom rewriteWithTypeVariable(Atom parentAtom) {
if (parentAtom.getPredicateVariable().isReturned()
&& !this.getPredicateVariable().isReturned()
&& this.getClass() == parentAtom.getClass()) {
return rewriteWithTypeVariable();
}
return this;
} | java | public Atom rewriteWithTypeVariable(Atom parentAtom) {
if (parentAtom.getPredicateVariable().isReturned()
&& !this.getPredicateVariable().isReturned()
&& this.getClass() == parentAtom.getClass()) {
return rewriteWithTypeVariable();
}
return this;
} | [
"public",
"Atom",
"rewriteWithTypeVariable",
"(",
"Atom",
"parentAtom",
")",
"{",
"if",
"(",
"parentAtom",
".",
"getPredicateVariable",
"(",
")",
".",
"isReturned",
"(",
")",
"&&",
"!",
"this",
".",
"getPredicateVariable",
"(",
")",
".",
"isReturned",
"(",
")",
"&&",
"this",
".",
"getClass",
"(",
")",
"==",
"parentAtom",
".",
"getClass",
"(",
")",
")",
"{",
"return",
"rewriteWithTypeVariable",
"(",
")",
";",
"}",
"return",
"this",
";",
"}"
] | rewrites the atom to user-defined type variable
@param parentAtom parent atom that triggers rewrite
@return rewritten atom | [
"rewrites",
"the",
"atom",
"to",
"user",
"-",
"defined",
"type",
"variable"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/reasoner/atom/Atom.java#L373-L380 |
22,958 | graknlabs/grakn | server/src/server/kb/concept/RelationImpl.java | RelationImpl.reify | private RelationReified reify() {
if (relationStructure.isReified()) return relationStructure.reify();
//Get the role players to transfer
Map<Role, Set<Thing>> rolePlayers = structure().allRolePlayers();
//Now Reify
relationStructure = relationStructure.reify();
//Transfer relations
rolePlayers.forEach((role, things) -> {
Thing thing = Iterables.getOnlyElement(things);
assign(role, thing);
});
return relationStructure.reify();
} | java | private RelationReified reify() {
if (relationStructure.isReified()) return relationStructure.reify();
//Get the role players to transfer
Map<Role, Set<Thing>> rolePlayers = structure().allRolePlayers();
//Now Reify
relationStructure = relationStructure.reify();
//Transfer relations
rolePlayers.forEach((role, things) -> {
Thing thing = Iterables.getOnlyElement(things);
assign(role, thing);
});
return relationStructure.reify();
} | [
"private",
"RelationReified",
"reify",
"(",
")",
"{",
"if",
"(",
"relationStructure",
".",
"isReified",
"(",
")",
")",
"return",
"relationStructure",
".",
"reify",
"(",
")",
";",
"//Get the role players to transfer",
"Map",
"<",
"Role",
",",
"Set",
"<",
"Thing",
">",
">",
"rolePlayers",
"=",
"structure",
"(",
")",
".",
"allRolePlayers",
"(",
")",
";",
"//Now Reify",
"relationStructure",
"=",
"relationStructure",
".",
"reify",
"(",
")",
";",
"//Transfer relations",
"rolePlayers",
".",
"forEach",
"(",
"(",
"role",
",",
"things",
")",
"->",
"{",
"Thing",
"thing",
"=",
"Iterables",
".",
"getOnlyElement",
"(",
"things",
")",
";",
"assign",
"(",
"role",
",",
"thing",
")",
";",
"}",
")",
";",
"return",
"relationStructure",
".",
"reify",
"(",
")",
";",
"}"
] | Reifys and returns the RelationReified | [
"Reifys",
"and",
"returns",
"the",
"RelationReified"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/RelationImpl.java#L74-L90 |
22,959 | graknlabs/grakn | server/src/server/kb/concept/RelationImpl.java | RelationImpl.readFromReified | private <X> Stream<X> readFromReified(Function<RelationReified, Stream<X>> producer) {
return reified().map(producer).orElseGet(Stream::empty);
} | java | private <X> Stream<X> readFromReified(Function<RelationReified, Stream<X>> producer) {
return reified().map(producer).orElseGet(Stream::empty);
} | [
"private",
"<",
"X",
">",
"Stream",
"<",
"X",
">",
"readFromReified",
"(",
"Function",
"<",
"RelationReified",
",",
"Stream",
"<",
"X",
">",
">",
"producer",
")",
"{",
"return",
"reified",
"(",
")",
".",
"map",
"(",
"producer",
")",
".",
"orElseGet",
"(",
"Stream",
"::",
"empty",
")",
";",
"}"
] | Reads some data from a RelationReified. If the Relation has not been reified then an empty
Stream is returned. | [
"Reads",
"some",
"data",
"from",
"a",
"RelationReified",
".",
"If",
"the",
"Relation",
"has",
"not",
"been",
"reified",
"then",
"an",
"empty",
"Stream",
"is",
"returned",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/RelationImpl.java#L136-L138 |
22,960 | graknlabs/grakn | server/src/server/kb/concept/RelationImpl.java | RelationImpl.assign | @Override
public Relation assign(Role role, Thing player) {
reify().addRolePlayer(role, player);
return this;
} | java | @Override
public Relation assign(Role role, Thing player) {
reify().addRolePlayer(role, player);
return this;
} | [
"@",
"Override",
"public",
"Relation",
"assign",
"(",
"Role",
"role",
",",
"Thing",
"player",
")",
"{",
"reify",
"(",
")",
".",
"addRolePlayer",
"(",
"role",
",",
"player",
")",
";",
"return",
"this",
";",
"}"
] | Expands this Relation to include a new role player which is playing a specific Role.
@param role The role of the new role player.
@param player The new role player.
@return The Relation itself | [
"Expands",
"this",
"Relation",
"to",
"include",
"a",
"new",
"role",
"player",
"which",
"is",
"playing",
"a",
"specific",
"Role",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/RelationImpl.java#L163-L167 |
22,961 | graknlabs/grakn | server/src/server/kb/concept/RelationImpl.java | RelationImpl.cleanUp | void cleanUp() {
Stream<Thing> rolePlayers = rolePlayers();
boolean performDeletion = rolePlayers.noneMatch(thing -> thing != null && thing.id() != null);
if (performDeletion) delete();
} | java | void cleanUp() {
Stream<Thing> rolePlayers = rolePlayers();
boolean performDeletion = rolePlayers.noneMatch(thing -> thing != null && thing.id() != null);
if (performDeletion) delete();
} | [
"void",
"cleanUp",
"(",
")",
"{",
"Stream",
"<",
"Thing",
">",
"rolePlayers",
"=",
"rolePlayers",
"(",
")",
";",
"boolean",
"performDeletion",
"=",
"rolePlayers",
".",
"noneMatch",
"(",
"thing",
"->",
"thing",
"!=",
"null",
"&&",
"thing",
".",
"id",
"(",
")",
"!=",
"null",
")",
";",
"if",
"(",
"performDeletion",
")",
"delete",
"(",
")",
";",
"}"
] | When a relation is deleted this cleans up any solitary casting and resources. | [
"When",
"a",
"relation",
"is",
"deleted",
"this",
"cleans",
"up",
"any",
"solitary",
"casting",
"and",
"resources",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/RelationImpl.java#L188-L192 |
22,962 | graknlabs/grakn | server/src/server/kb/concept/SchemaConceptImpl.java | SchemaConceptImpl.delete | @Override
public void delete() {
if (deletionAllowed()) {
//Force load of linked concepts whose caches need to be updated
T superConcept = cachedSuperType.get();
deleteNode();
//Update neighbouring caches
SchemaConceptImpl.from(superConcept).deleteCachedDirectedSubType(getThis());
//clear rule cache
vertex().tx().ruleCache().clear();
} else {
throw TransactionException.cannotBeDeleted(this);
}
} | java | @Override
public void delete() {
if (deletionAllowed()) {
//Force load of linked concepts whose caches need to be updated
T superConcept = cachedSuperType.get();
deleteNode();
//Update neighbouring caches
SchemaConceptImpl.from(superConcept).deleteCachedDirectedSubType(getThis());
//clear rule cache
vertex().tx().ruleCache().clear();
} else {
throw TransactionException.cannotBeDeleted(this);
}
} | [
"@",
"Override",
"public",
"void",
"delete",
"(",
")",
"{",
"if",
"(",
"deletionAllowed",
"(",
")",
")",
"{",
"//Force load of linked concepts whose caches need to be updated",
"T",
"superConcept",
"=",
"cachedSuperType",
".",
"get",
"(",
")",
";",
"deleteNode",
"(",
")",
";",
"//Update neighbouring caches",
"SchemaConceptImpl",
".",
"from",
"(",
"superConcept",
")",
".",
"deleteCachedDirectedSubType",
"(",
"getThis",
"(",
")",
")",
";",
"//clear rule cache",
"vertex",
"(",
")",
".",
"tx",
"(",
")",
".",
"ruleCache",
"(",
")",
".",
"clear",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"TransactionException",
".",
"cannotBeDeleted",
"(",
"this",
")",
";",
"}",
"}"
] | Deletes the concept as a SchemaConcept | [
"Deletes",
"the",
"concept",
"as",
"a",
"SchemaConcept"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/SchemaConceptImpl.java#L131-L147 |
22,963 | graknlabs/grakn | server/src/graql/reasoner/plan/ResolutionQueryPlan.java | ResolutionQueryPlan.queryPlan | private static ImmutableList<ReasonerQueryImpl> queryPlan(ReasonerQueryImpl query){
ResolutionPlan resolutionPlan = query.resolutionPlan();
ImmutableList<Atom> plan = resolutionPlan.plan();
TransactionOLTP tx = query.tx();
LinkedList<Atom> atoms = new LinkedList<>(plan);
List<ReasonerQueryImpl> queries = new LinkedList<>();
List<Atom> nonResolvableAtoms = new ArrayList<>();
while (!atoms.isEmpty()) {
Atom top = atoms.remove();
if (top.isRuleResolvable()) {
if (!nonResolvableAtoms.isEmpty()) {
queries.add(ReasonerQueries.create(nonResolvableAtoms, tx));
nonResolvableAtoms.clear();
}
queries.add(ReasonerQueries.atomic(top));
} else {
nonResolvableAtoms.add(top);
if (atoms.isEmpty()) queries.add(ReasonerQueries.create(nonResolvableAtoms, tx));
}
}
boolean refine = plan.size() != queries.size() && !query.requiresSchema();
return refine? refine(queries) : ImmutableList.copyOf(queries);
} | java | private static ImmutableList<ReasonerQueryImpl> queryPlan(ReasonerQueryImpl query){
ResolutionPlan resolutionPlan = query.resolutionPlan();
ImmutableList<Atom> plan = resolutionPlan.plan();
TransactionOLTP tx = query.tx();
LinkedList<Atom> atoms = new LinkedList<>(plan);
List<ReasonerQueryImpl> queries = new LinkedList<>();
List<Atom> nonResolvableAtoms = new ArrayList<>();
while (!atoms.isEmpty()) {
Atom top = atoms.remove();
if (top.isRuleResolvable()) {
if (!nonResolvableAtoms.isEmpty()) {
queries.add(ReasonerQueries.create(nonResolvableAtoms, tx));
nonResolvableAtoms.clear();
}
queries.add(ReasonerQueries.atomic(top));
} else {
nonResolvableAtoms.add(top);
if (atoms.isEmpty()) queries.add(ReasonerQueries.create(nonResolvableAtoms, tx));
}
}
boolean refine = plan.size() != queries.size() && !query.requiresSchema();
return refine? refine(queries) : ImmutableList.copyOf(queries);
} | [
"private",
"static",
"ImmutableList",
"<",
"ReasonerQueryImpl",
">",
"queryPlan",
"(",
"ReasonerQueryImpl",
"query",
")",
"{",
"ResolutionPlan",
"resolutionPlan",
"=",
"query",
".",
"resolutionPlan",
"(",
")",
";",
"ImmutableList",
"<",
"Atom",
">",
"plan",
"=",
"resolutionPlan",
".",
"plan",
"(",
")",
";",
"TransactionOLTP",
"tx",
"=",
"query",
".",
"tx",
"(",
")",
";",
"LinkedList",
"<",
"Atom",
">",
"atoms",
"=",
"new",
"LinkedList",
"<>",
"(",
"plan",
")",
";",
"List",
"<",
"ReasonerQueryImpl",
">",
"queries",
"=",
"new",
"LinkedList",
"<>",
"(",
")",
";",
"List",
"<",
"Atom",
">",
"nonResolvableAtoms",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"while",
"(",
"!",
"atoms",
".",
"isEmpty",
"(",
")",
")",
"{",
"Atom",
"top",
"=",
"atoms",
".",
"remove",
"(",
")",
";",
"if",
"(",
"top",
".",
"isRuleResolvable",
"(",
")",
")",
"{",
"if",
"(",
"!",
"nonResolvableAtoms",
".",
"isEmpty",
"(",
")",
")",
"{",
"queries",
".",
"add",
"(",
"ReasonerQueries",
".",
"create",
"(",
"nonResolvableAtoms",
",",
"tx",
")",
")",
";",
"nonResolvableAtoms",
".",
"clear",
"(",
")",
";",
"}",
"queries",
".",
"add",
"(",
"ReasonerQueries",
".",
"atomic",
"(",
"top",
")",
")",
";",
"}",
"else",
"{",
"nonResolvableAtoms",
".",
"add",
"(",
"top",
")",
";",
"if",
"(",
"atoms",
".",
"isEmpty",
"(",
")",
")",
"queries",
".",
"add",
"(",
"ReasonerQueries",
".",
"create",
"(",
"nonResolvableAtoms",
",",
"tx",
")",
")",
";",
"}",
"}",
"boolean",
"refine",
"=",
"plan",
".",
"size",
"(",
")",
"!=",
"queries",
".",
"size",
"(",
")",
"&&",
"!",
"query",
".",
"requiresSchema",
"(",
")",
";",
"return",
"refine",
"?",
"refine",
"(",
"queries",
")",
":",
"ImmutableList",
".",
"copyOf",
"(",
"queries",
")",
";",
"}"
] | compute the query resolution plan - list of queries ordered by their cost as computed by the graql traversal planner
@return list of prioritised queries | [
"compute",
"the",
"query",
"resolution",
"plan",
"-",
"list",
"of",
"queries",
"ordered",
"by",
"their",
"cost",
"as",
"computed",
"by",
"the",
"graql",
"traversal",
"planner"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/reasoner/plan/ResolutionQueryPlan.java#L66-L91 |
22,964 | graknlabs/grakn | server/src/server/kb/concept/ConceptUtils.java | ConceptUtils.areDisjointTypes | public static boolean areDisjointTypes(SchemaConcept parent, SchemaConcept child, boolean direct) {
return parent != null && child == null || !typesCompatible(parent, child, direct) && !typesCompatible(child, parent, direct);
} | java | public static boolean areDisjointTypes(SchemaConcept parent, SchemaConcept child, boolean direct) {
return parent != null && child == null || !typesCompatible(parent, child, direct) && !typesCompatible(child, parent, direct);
} | [
"public",
"static",
"boolean",
"areDisjointTypes",
"(",
"SchemaConcept",
"parent",
",",
"SchemaConcept",
"child",
",",
"boolean",
"direct",
")",
"{",
"return",
"parent",
"!=",
"null",
"&&",
"child",
"==",
"null",
"||",
"!",
"typesCompatible",
"(",
"parent",
",",
"child",
",",
"direct",
")",
"&&",
"!",
"typesCompatible",
"(",
"child",
",",
"parent",
",",
"direct",
")",
";",
"}"
] | determines disjointness of parent-child types, parent defines the bound on the child
@param parent {@link SchemaConcept}
@param child {@link SchemaConcept}
@return true if types do not belong to the same type hierarchy, also true if parent is null and false if parent non-null and child null | [
"determines",
"disjointness",
"of",
"parent",
"-",
"child",
"types",
"parent",
"defines",
"the",
"bound",
"on",
"the",
"child"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/ConceptUtils.java#L108-L110 |
22,965 | graknlabs/grakn | server/src/graql/reasoner/utils/TarjanSCC.java | TarjanSCC.getCycles | public List<Set<T>> getCycles() {
return scc.stream().filter(cc ->
cc.size() > 1
|| graph.get(Iterables.getOnlyElement(cc)).contains(Iterables.getOnlyElement(cc))
)
.collect(Collectors.toList());
} | java | public List<Set<T>> getCycles() {
return scc.stream().filter(cc ->
cc.size() > 1
|| graph.get(Iterables.getOnlyElement(cc)).contains(Iterables.getOnlyElement(cc))
)
.collect(Collectors.toList());
} | [
"public",
"List",
"<",
"Set",
"<",
"T",
">",
">",
"getCycles",
"(",
")",
"{",
"return",
"scc",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"cc",
"->",
"cc",
".",
"size",
"(",
")",
">",
"1",
"||",
"graph",
".",
"get",
"(",
"Iterables",
".",
"getOnlyElement",
"(",
"cc",
")",
")",
".",
"contains",
"(",
"Iterables",
".",
"getOnlyElement",
"(",
"cc",
")",
")",
")",
".",
"collect",
"(",
"Collectors",
".",
"toList",
"(",
")",
")",
";",
"}"
] | A cycle isa a connected component that has more than one vertex or a single vertex linked to itself.
@return list of cycles in the graph | [
"A",
"cycle",
"isa",
"a",
"connected",
"component",
"that",
"has",
"more",
"than",
"one",
"vertex",
"or",
"a",
"single",
"vertex",
"linked",
"to",
"itself",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/reasoner/utils/TarjanSCC.java#L64-L70 |
22,966 | graknlabs/grakn | server/src/server/kb/concept/ThingImpl.java | ThingImpl.delete | @Override
public void delete() {
//Remove links to relations and return them
Set<Relation> relations = castingsInstance().map(casting -> {
Relation relation = casting.getRelation();
Role role = casting.getRole();
relation.unassign(role, this);
return relation;
}).collect(toSet());
vertex().tx().cache().removedInstance(type().id());
deleteNode();
relations.forEach(relation -> {
if (relation.type().isImplicit()) {//For now implicit relations die
relation.delete();
} else {
RelationImpl rel = (RelationImpl) relation;
rel.cleanUp();
}
});
} | java | @Override
public void delete() {
//Remove links to relations and return them
Set<Relation> relations = castingsInstance().map(casting -> {
Relation relation = casting.getRelation();
Role role = casting.getRole();
relation.unassign(role, this);
return relation;
}).collect(toSet());
vertex().tx().cache().removedInstance(type().id());
deleteNode();
relations.forEach(relation -> {
if (relation.type().isImplicit()) {//For now implicit relations die
relation.delete();
} else {
RelationImpl rel = (RelationImpl) relation;
rel.cleanUp();
}
});
} | [
"@",
"Override",
"public",
"void",
"delete",
"(",
")",
"{",
"//Remove links to relations and return them",
"Set",
"<",
"Relation",
">",
"relations",
"=",
"castingsInstance",
"(",
")",
".",
"map",
"(",
"casting",
"->",
"{",
"Relation",
"relation",
"=",
"casting",
".",
"getRelation",
"(",
")",
";",
"Role",
"role",
"=",
"casting",
".",
"getRole",
"(",
")",
";",
"relation",
".",
"unassign",
"(",
"role",
",",
"this",
")",
";",
"return",
"relation",
";",
"}",
")",
".",
"collect",
"(",
"toSet",
"(",
")",
")",
";",
"vertex",
"(",
")",
".",
"tx",
"(",
")",
".",
"cache",
"(",
")",
".",
"removedInstance",
"(",
"type",
"(",
")",
".",
"id",
"(",
")",
")",
";",
"deleteNode",
"(",
")",
";",
"relations",
".",
"forEach",
"(",
"relation",
"->",
"{",
"if",
"(",
"relation",
".",
"type",
"(",
")",
".",
"isImplicit",
"(",
")",
")",
"{",
"//For now implicit relations die",
"relation",
".",
"delete",
"(",
")",
";",
"}",
"else",
"{",
"RelationImpl",
"rel",
"=",
"(",
"RelationImpl",
")",
"relation",
";",
"rel",
".",
"cleanUp",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Deletes the concept as an Thing | [
"Deletes",
"the",
"concept",
"as",
"an",
"Thing"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/ThingImpl.java#L106-L127 |
22,967 | graknlabs/grakn | server/src/server/kb/concept/ThingImpl.java | ThingImpl.attributes | private <X extends Concept> Stream<Attribute<?>> attributes(Stream<X> conceptStream, Set<ConceptId> attributeTypesIds) {
Stream<Attribute<?>> attributeStream = conceptStream.
filter(concept -> concept.isAttribute() && !this.equals(concept)).
map(Concept::asAttribute);
if (!attributeTypesIds.isEmpty()) {
attributeStream = attributeStream.filter(attribute -> attributeTypesIds.contains(attribute.type().id()));
}
return attributeStream;
} | java | private <X extends Concept> Stream<Attribute<?>> attributes(Stream<X> conceptStream, Set<ConceptId> attributeTypesIds) {
Stream<Attribute<?>> attributeStream = conceptStream.
filter(concept -> concept.isAttribute() && !this.equals(concept)).
map(Concept::asAttribute);
if (!attributeTypesIds.isEmpty()) {
attributeStream = attributeStream.filter(attribute -> attributeTypesIds.contains(attribute.type().id()));
}
return attributeStream;
} | [
"private",
"<",
"X",
"extends",
"Concept",
">",
"Stream",
"<",
"Attribute",
"<",
"?",
">",
">",
"attributes",
"(",
"Stream",
"<",
"X",
">",
"conceptStream",
",",
"Set",
"<",
"ConceptId",
">",
"attributeTypesIds",
")",
"{",
"Stream",
"<",
"Attribute",
"<",
"?",
">",
">",
"attributeStream",
"=",
"conceptStream",
".",
"filter",
"(",
"concept",
"->",
"concept",
".",
"isAttribute",
"(",
")",
"&&",
"!",
"this",
".",
"equals",
"(",
"concept",
")",
")",
".",
"map",
"(",
"Concept",
"::",
"asAttribute",
")",
";",
"if",
"(",
"!",
"attributeTypesIds",
".",
"isEmpty",
"(",
")",
")",
"{",
"attributeStream",
"=",
"attributeStream",
".",
"filter",
"(",
"attribute",
"->",
"attributeTypesIds",
".",
"contains",
"(",
"attribute",
".",
"type",
"(",
")",
".",
"id",
"(",
")",
")",
")",
";",
"}",
"return",
"attributeStream",
";",
"}"
] | Helper class which filters a Stream of Attribute to those of a specific set of AttributeType.
@param conceptStream The Stream to filter
@param attributeTypesIds The AttributeType ConceptIds to filter to.
@return the filtered stream | [
"Helper",
"class",
"which",
"filters",
"a",
"Stream",
"of",
"Attribute",
"to",
"those",
"of",
"a",
"specific",
"set",
"of",
"AttributeType",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/ThingImpl.java#L165-L175 |
22,968 | graknlabs/grakn | server/src/server/kb/concept/ThingImpl.java | ThingImpl.castingsInstance | Stream<Casting> castingsInstance() {
return vertex().getEdgesOfType(Direction.IN, Schema.EdgeLabel.ROLE_PLAYER).
map(edge -> Casting.withThing(edge, this));
} | java | Stream<Casting> castingsInstance() {
return vertex().getEdgesOfType(Direction.IN, Schema.EdgeLabel.ROLE_PLAYER).
map(edge -> Casting.withThing(edge, this));
} | [
"Stream",
"<",
"Casting",
">",
"castingsInstance",
"(",
")",
"{",
"return",
"vertex",
"(",
")",
".",
"getEdgesOfType",
"(",
"Direction",
".",
"IN",
",",
"Schema",
".",
"EdgeLabel",
".",
"ROLE_PLAYER",
")",
".",
"map",
"(",
"edge",
"->",
"Casting",
".",
"withThing",
"(",
"edge",
",",
"this",
")",
")",
";",
"}"
] | Castings are retrieved from the perspective of the Thing which is a role player in a Relation
@return All the Casting which this instance is cast into the role | [
"Castings",
"are",
"retrieved",
"from",
"the",
"perspective",
"of",
"the",
"Thing",
"which",
"is",
"a",
"role",
"player",
"in",
"a",
"Relation"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/ThingImpl.java#L182-L185 |
22,969 | graknlabs/grakn | server/src/server/kb/concept/ThingImpl.java | ThingImpl.filterNulls | private Role[] filterNulls(Role... roles) {
return Arrays.stream(roles).filter(Objects::nonNull).toArray(Role[]::new);
} | java | private Role[] filterNulls(Role... roles) {
return Arrays.stream(roles).filter(Objects::nonNull).toArray(Role[]::new);
} | [
"private",
"Role",
"[",
"]",
"filterNulls",
"(",
"Role",
"...",
"roles",
")",
"{",
"return",
"Arrays",
".",
"stream",
"(",
"roles",
")",
".",
"filter",
"(",
"Objects",
"::",
"nonNull",
")",
".",
"toArray",
"(",
"Role",
"[",
"]",
"::",
"new",
")",
";",
"}"
] | Returns an array with all the nulls filtered out. | [
"Returns",
"an",
"array",
"with",
"all",
"the",
"nulls",
"filtered",
"out",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/ThingImpl.java#L350-L352 |
22,970 | graknlabs/grakn | server/src/server/rpc/SessionService.java | SessionService.shutdown | public void shutdown(){
transactionListenerSet.forEach(transactionListener -> transactionListener.close(null));
transactionListenerSet.clear();
openSessions.values().forEach(SessionImpl::close);
} | java | public void shutdown(){
transactionListenerSet.forEach(transactionListener -> transactionListener.close(null));
transactionListenerSet.clear();
openSessions.values().forEach(SessionImpl::close);
} | [
"public",
"void",
"shutdown",
"(",
")",
"{",
"transactionListenerSet",
".",
"forEach",
"(",
"transactionListener",
"->",
"transactionListener",
".",
"close",
"(",
"null",
")",
")",
";",
"transactionListenerSet",
".",
"clear",
"(",
")",
";",
"openSessions",
".",
"values",
"(",
")",
".",
"forEach",
"(",
"SessionImpl",
"::",
"close",
")",
";",
"}"
] | Close all open transactions, sessions and connections with clients - this is invoked by JVM shutdown hook | [
"Close",
"all",
"open",
"transactions",
"sessions",
"and",
"connections",
"with",
"clients",
"-",
"this",
"is",
"invoked",
"by",
"JVM",
"shutdown",
"hook"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/rpc/SessionService.java#L89-L93 |
22,971 | graknlabs/grakn | server/src/server/kb/structure/VertexElement.java | VertexElement.deleteEdge | public void deleteEdge(Direction direction, Schema.EdgeLabel label, VertexElement... targets) {
Iterator<Edge> edges = element().edges(direction, label.getLabel());
if (targets.length == 0) {
edges.forEachRemaining(Edge::remove);
} else {
Set<Vertex> verticesToDelete = Arrays.stream(targets).map(AbstractElement::element).collect(Collectors.toSet());
edges.forEachRemaining(edge -> {
boolean delete = false;
switch (direction) {
case BOTH:
delete = verticesToDelete.contains(edge.inVertex()) || verticesToDelete.contains(edge.outVertex());
break;
case IN:
delete = verticesToDelete.contains(edge.outVertex());
break;
case OUT:
delete = verticesToDelete.contains(edge.inVertex());
break;
}
if (delete) edge.remove();
});
}
} | java | public void deleteEdge(Direction direction, Schema.EdgeLabel label, VertexElement... targets) {
Iterator<Edge> edges = element().edges(direction, label.getLabel());
if (targets.length == 0) {
edges.forEachRemaining(Edge::remove);
} else {
Set<Vertex> verticesToDelete = Arrays.stream(targets).map(AbstractElement::element).collect(Collectors.toSet());
edges.forEachRemaining(edge -> {
boolean delete = false;
switch (direction) {
case BOTH:
delete = verticesToDelete.contains(edge.inVertex()) || verticesToDelete.contains(edge.outVertex());
break;
case IN:
delete = verticesToDelete.contains(edge.outVertex());
break;
case OUT:
delete = verticesToDelete.contains(edge.inVertex());
break;
}
if (delete) edge.remove();
});
}
} | [
"public",
"void",
"deleteEdge",
"(",
"Direction",
"direction",
",",
"Schema",
".",
"EdgeLabel",
"label",
",",
"VertexElement",
"...",
"targets",
")",
"{",
"Iterator",
"<",
"Edge",
">",
"edges",
"=",
"element",
"(",
")",
".",
"edges",
"(",
"direction",
",",
"label",
".",
"getLabel",
"(",
")",
")",
";",
"if",
"(",
"targets",
".",
"length",
"==",
"0",
")",
"{",
"edges",
".",
"forEachRemaining",
"(",
"Edge",
"::",
"remove",
")",
";",
"}",
"else",
"{",
"Set",
"<",
"Vertex",
">",
"verticesToDelete",
"=",
"Arrays",
".",
"stream",
"(",
"targets",
")",
".",
"map",
"(",
"AbstractElement",
"::",
"element",
")",
".",
"collect",
"(",
"Collectors",
".",
"toSet",
"(",
")",
")",
";",
"edges",
".",
"forEachRemaining",
"(",
"edge",
"->",
"{",
"boolean",
"delete",
"=",
"false",
";",
"switch",
"(",
"direction",
")",
"{",
"case",
"BOTH",
":",
"delete",
"=",
"verticesToDelete",
".",
"contains",
"(",
"edge",
".",
"inVertex",
"(",
")",
")",
"||",
"verticesToDelete",
".",
"contains",
"(",
"edge",
".",
"outVertex",
"(",
")",
")",
";",
"break",
";",
"case",
"IN",
":",
"delete",
"=",
"verticesToDelete",
".",
"contains",
"(",
"edge",
".",
"outVertex",
"(",
")",
")",
";",
"break",
";",
"case",
"OUT",
":",
"delete",
"=",
"verticesToDelete",
".",
"contains",
"(",
"edge",
".",
"inVertex",
"(",
")",
")",
";",
"break",
";",
"}",
"if",
"(",
"delete",
")",
"edge",
".",
"remove",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
] | Deletes all the edges of a specific Schema.EdgeLabel to or from a specific set of targets.
If no targets are provided then all the edges of the specified type are deleted
@param direction The direction of the edges to delete
@param label The edge label to delete
@param targets An optional set of targets to delete edges from | [
"Deletes",
"all",
"the",
"edges",
"of",
"a",
"specific",
"Schema",
".",
"EdgeLabel",
"to",
"or",
"from",
"a",
"specific",
"set",
"of",
"targets",
".",
"If",
"no",
"targets",
"are",
"provided",
"then",
"all",
"the",
"edges",
"of",
"the",
"specified",
"type",
"are",
"deleted"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/structure/VertexElement.java#L93-L116 |
22,972 | graknlabs/grakn | server/src/graql/gremlin/spanningtree/util/Weighted.java | Weighted.weighted | public static <T> Weighted<T> weighted(T value, double weight) {
return new Weighted<>(value, weight);
} | java | public static <T> Weighted<T> weighted(T value, double weight) {
return new Weighted<>(value, weight);
} | [
"public",
"static",
"<",
"T",
">",
"Weighted",
"<",
"T",
">",
"weighted",
"(",
"T",
"value",
",",
"double",
"weight",
")",
"{",
"return",
"new",
"Weighted",
"<>",
"(",
"value",
",",
"weight",
")",
";",
"}"
] | Convenience static constructor | [
"Convenience",
"static",
"constructor"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/spanningtree/util/Weighted.java#L44-L46 |
22,973 | graknlabs/grakn | server/src/graql/gremlin/spanningtree/util/Weighted.java | Weighted.compareTo | public int compareTo(Weighted<DirectedEdge> other) {
return ComparisonChain.start()
.compare(other.weight, weight)
.compare(Objects.hashCode(other.val), Objects.hashCode(val))
.result();
} | java | public int compareTo(Weighted<DirectedEdge> other) {
return ComparisonChain.start()
.compare(other.weight, weight)
.compare(Objects.hashCode(other.val), Objects.hashCode(val))
.result();
} | [
"public",
"int",
"compareTo",
"(",
"Weighted",
"<",
"DirectedEdge",
">",
"other",
")",
"{",
"return",
"ComparisonChain",
".",
"start",
"(",
")",
".",
"compare",
"(",
"other",
".",
"weight",
",",
"weight",
")",
".",
"compare",
"(",
"Objects",
".",
"hashCode",
"(",
"other",
".",
"val",
")",
",",
"Objects",
".",
"hashCode",
"(",
"val",
")",
")",
".",
"result",
"(",
")",
";",
"}"
] | High weights first, use val.hashCode to break ties | [
"High",
"weights",
"first",
"use",
"val",
".",
"hashCode",
"to",
"break",
"ties"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/spanningtree/util/Weighted.java#L51-L56 |
22,974 | graknlabs/grakn | server/src/server/deduplicator/queue/InMemoryQueue.java | InMemoryQueue.insert | public void insert(Attribute attribute) {
queue.put(attribute.conceptId().getValue(), attribute);
synchronized (this) {
notifyAll();
}
} | java | public void insert(Attribute attribute) {
queue.put(attribute.conceptId().getValue(), attribute);
synchronized (this) {
notifyAll();
}
} | [
"public",
"void",
"insert",
"(",
"Attribute",
"attribute",
")",
"{",
"queue",
".",
"put",
"(",
"attribute",
".",
"conceptId",
"(",
")",
".",
"getValue",
"(",
")",
",",
"attribute",
")",
";",
"synchronized",
"(",
"this",
")",
"{",
"notifyAll",
"(",
")",
";",
"}",
"}"
] | insert a new attribute at the end of the queue.
@param attribute the attribute to be inserted | [
"insert",
"a",
"new",
"attribute",
"at",
"the",
"end",
"of",
"the",
"queue",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/deduplicator/queue/InMemoryQueue.java#L49-L54 |
22,975 | graknlabs/grakn | server/src/server/deduplicator/queue/InMemoryQueue.java | InMemoryQueue.ack | public void ack(List<Attribute> attributes) {
for (Attribute attr : attributes) {
queue.remove(attr.conceptId().getValue());
}
} | java | public void ack(List<Attribute> attributes) {
for (Attribute attr : attributes) {
queue.remove(attr.conceptId().getValue());
}
} | [
"public",
"void",
"ack",
"(",
"List",
"<",
"Attribute",
">",
"attributes",
")",
"{",
"for",
"(",
"Attribute",
"attr",
":",
"attributes",
")",
"{",
"queue",
".",
"remove",
"(",
"attr",
".",
"conceptId",
"(",
")",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}"
] | Remove attributes from the queue.
@param attributes the attributes which will be removed | [
"Remove",
"attributes",
"from",
"the",
"queue",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/deduplicator/queue/InMemoryQueue.java#L82-L86 |
22,976 | graknlabs/grakn | server/src/server/deduplicator/AttributeDeduplicator.java | AttributeDeduplicator.deduplicate | public static void deduplicate(SessionFactory sessionFactory, KeyspaceIndexPair keyspaceIndexPair) {
SessionImpl session = sessionFactory.session(keyspaceIndexPair.keyspace());
try (TransactionOLTP tx = session.transaction().write()) {
GraphTraversalSource tinker = tx.getTinkerTraversal();
GraphTraversal<Vertex, Vertex> duplicates = tinker.V().has(Schema.VertexProperty.INDEX.name(), keyspaceIndexPair.index());
// Duplicates might be empty if the user deleted the attribute right after the insertion or deleted the keyspace.
if (duplicates.hasNext()) {
Vertex mergeTargetV = duplicates.next();
while (duplicates.hasNext()) {
Vertex duplicate = duplicates.next();
try {
duplicate.vertices(Direction.IN).forEachRemaining(connectedVertex -> {
// merge attribute edge connecting 'duplicate' and 'connectedVertex' to 'mergeTargetV', if exists
GraphTraversal<Vertex, Edge> attributeEdge =
tinker.V(duplicate).inE(Schema.EdgeLabel.ATTRIBUTE.getLabel()).filter(__.outV().is(connectedVertex));
if (attributeEdge.hasNext()) {
mergeAttributeEdge(mergeTargetV, connectedVertex, attributeEdge);
}
// merge role-player edge connecting 'duplicate' and 'connectedVertex' to 'mergeTargetV', if exists
GraphTraversal<Vertex, Edge> rolePlayerEdge =
tinker.V(duplicate).inE(Schema.EdgeLabel.ROLE_PLAYER.getLabel()).filter(__.outV().is(connectedVertex));
if (rolePlayerEdge.hasNext()) {
mergeRolePlayerEdge(mergeTargetV, rolePlayerEdge);
}
try {
attributeEdge.close();
rolePlayerEdge.close();
} catch (Exception e) {
LOG.warn("Exception while closing traversals:", e);
}
});
duplicate.remove();
} catch (IllegalStateException vertexAlreadyRemovedException) {
LOG.warn("Trying to call the method vertices(Direction.IN) on vertex {} which is already removed.", duplicate.id());
}
}
tx.commit();
} else {
tx.close();
}
try {
tinker.close();
duplicates.close();
} catch (Exception e) {
LOG.warn("Exception while closing traversals:", e);
}
} finally {
session.close();
}
} | java | public static void deduplicate(SessionFactory sessionFactory, KeyspaceIndexPair keyspaceIndexPair) {
SessionImpl session = sessionFactory.session(keyspaceIndexPair.keyspace());
try (TransactionOLTP tx = session.transaction().write()) {
GraphTraversalSource tinker = tx.getTinkerTraversal();
GraphTraversal<Vertex, Vertex> duplicates = tinker.V().has(Schema.VertexProperty.INDEX.name(), keyspaceIndexPair.index());
// Duplicates might be empty if the user deleted the attribute right after the insertion or deleted the keyspace.
if (duplicates.hasNext()) {
Vertex mergeTargetV = duplicates.next();
while (duplicates.hasNext()) {
Vertex duplicate = duplicates.next();
try {
duplicate.vertices(Direction.IN).forEachRemaining(connectedVertex -> {
// merge attribute edge connecting 'duplicate' and 'connectedVertex' to 'mergeTargetV', if exists
GraphTraversal<Vertex, Edge> attributeEdge =
tinker.V(duplicate).inE(Schema.EdgeLabel.ATTRIBUTE.getLabel()).filter(__.outV().is(connectedVertex));
if (attributeEdge.hasNext()) {
mergeAttributeEdge(mergeTargetV, connectedVertex, attributeEdge);
}
// merge role-player edge connecting 'duplicate' and 'connectedVertex' to 'mergeTargetV', if exists
GraphTraversal<Vertex, Edge> rolePlayerEdge =
tinker.V(duplicate).inE(Schema.EdgeLabel.ROLE_PLAYER.getLabel()).filter(__.outV().is(connectedVertex));
if (rolePlayerEdge.hasNext()) {
mergeRolePlayerEdge(mergeTargetV, rolePlayerEdge);
}
try {
attributeEdge.close();
rolePlayerEdge.close();
} catch (Exception e) {
LOG.warn("Exception while closing traversals:", e);
}
});
duplicate.remove();
} catch (IllegalStateException vertexAlreadyRemovedException) {
LOG.warn("Trying to call the method vertices(Direction.IN) on vertex {} which is already removed.", duplicate.id());
}
}
tx.commit();
} else {
tx.close();
}
try {
tinker.close();
duplicates.close();
} catch (Exception e) {
LOG.warn("Exception while closing traversals:", e);
}
} finally {
session.close();
}
} | [
"public",
"static",
"void",
"deduplicate",
"(",
"SessionFactory",
"sessionFactory",
",",
"KeyspaceIndexPair",
"keyspaceIndexPair",
")",
"{",
"SessionImpl",
"session",
"=",
"sessionFactory",
".",
"session",
"(",
"keyspaceIndexPair",
".",
"keyspace",
"(",
")",
")",
";",
"try",
"(",
"TransactionOLTP",
"tx",
"=",
"session",
".",
"transaction",
"(",
")",
".",
"write",
"(",
")",
")",
"{",
"GraphTraversalSource",
"tinker",
"=",
"tx",
".",
"getTinkerTraversal",
"(",
")",
";",
"GraphTraversal",
"<",
"Vertex",
",",
"Vertex",
">",
"duplicates",
"=",
"tinker",
".",
"V",
"(",
")",
".",
"has",
"(",
"Schema",
".",
"VertexProperty",
".",
"INDEX",
".",
"name",
"(",
")",
",",
"keyspaceIndexPair",
".",
"index",
"(",
")",
")",
";",
"// Duplicates might be empty if the user deleted the attribute right after the insertion or deleted the keyspace.",
"if",
"(",
"duplicates",
".",
"hasNext",
"(",
")",
")",
"{",
"Vertex",
"mergeTargetV",
"=",
"duplicates",
".",
"next",
"(",
")",
";",
"while",
"(",
"duplicates",
".",
"hasNext",
"(",
")",
")",
"{",
"Vertex",
"duplicate",
"=",
"duplicates",
".",
"next",
"(",
")",
";",
"try",
"{",
"duplicate",
".",
"vertices",
"(",
"Direction",
".",
"IN",
")",
".",
"forEachRemaining",
"(",
"connectedVertex",
"->",
"{",
"// merge attribute edge connecting 'duplicate' and 'connectedVertex' to 'mergeTargetV', if exists",
"GraphTraversal",
"<",
"Vertex",
",",
"Edge",
">",
"attributeEdge",
"=",
"tinker",
".",
"V",
"(",
"duplicate",
")",
".",
"inE",
"(",
"Schema",
".",
"EdgeLabel",
".",
"ATTRIBUTE",
".",
"getLabel",
"(",
")",
")",
".",
"filter",
"(",
"__",
".",
"outV",
"(",
")",
".",
"is",
"(",
"connectedVertex",
")",
")",
";",
"if",
"(",
"attributeEdge",
".",
"hasNext",
"(",
")",
")",
"{",
"mergeAttributeEdge",
"(",
"mergeTargetV",
",",
"connectedVertex",
",",
"attributeEdge",
")",
";",
"}",
"// merge role-player edge connecting 'duplicate' and 'connectedVertex' to 'mergeTargetV', if exists",
"GraphTraversal",
"<",
"Vertex",
",",
"Edge",
">",
"rolePlayerEdge",
"=",
"tinker",
".",
"V",
"(",
"duplicate",
")",
".",
"inE",
"(",
"Schema",
".",
"EdgeLabel",
".",
"ROLE_PLAYER",
".",
"getLabel",
"(",
")",
")",
".",
"filter",
"(",
"__",
".",
"outV",
"(",
")",
".",
"is",
"(",
"connectedVertex",
")",
")",
";",
"if",
"(",
"rolePlayerEdge",
".",
"hasNext",
"(",
")",
")",
"{",
"mergeRolePlayerEdge",
"(",
"mergeTargetV",
",",
"rolePlayerEdge",
")",
";",
"}",
"try",
"{",
"attributeEdge",
".",
"close",
"(",
")",
";",
"rolePlayerEdge",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Exception while closing traversals:\"",
",",
"e",
")",
";",
"}",
"}",
")",
";",
"duplicate",
".",
"remove",
"(",
")",
";",
"}",
"catch",
"(",
"IllegalStateException",
"vertexAlreadyRemovedException",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Trying to call the method vertices(Direction.IN) on vertex {} which is already removed.\"",
",",
"duplicate",
".",
"id",
"(",
")",
")",
";",
"}",
"}",
"tx",
".",
"commit",
"(",
")",
";",
"}",
"else",
"{",
"tx",
".",
"close",
"(",
")",
";",
"}",
"try",
"{",
"tinker",
".",
"close",
"(",
")",
";",
"duplicates",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Exception while closing traversals:\"",
",",
"e",
")",
";",
"}",
"}",
"finally",
"{",
"session",
".",
"close",
"(",
")",
";",
"}",
"}"
] | Deduplicate attributes that has the same value. A de-duplication process consists of picking a single attribute
in the duplicates as the "merge target", copying every edges from every "other duplicates" to the merge target, and
finally deleting that other duplicates.
@param sessionFactory the factory object for accessing the database
@param keyspaceIndexPair the pair containing information about the attribute keyspace and index | [
"Deduplicate",
"attributes",
"that",
"has",
"the",
"same",
"value",
".",
"A",
"de",
"-",
"duplication",
"process",
"consists",
"of",
"picking",
"a",
"single",
"attribute",
"in",
"the",
"duplicates",
"as",
"the",
"merge",
"target",
"copying",
"every",
"edges",
"from",
"every",
"other",
"duplicates",
"to",
"the",
"merge",
"target",
"and",
"finally",
"deleting",
"that",
"other",
"duplicates",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/deduplicator/AttributeDeduplicator.java#L52-L105 |
22,977 | graknlabs/grakn | server/src/graql/reasoner/query/QueryAnswers.java | QueryAnswers.unify | public QueryAnswers unify(Unifier unifier){
if (unifier.isEmpty()) return new QueryAnswers(this);
QueryAnswers unifiedAnswers = new QueryAnswers();
this.stream()
.map(unifier::apply)
.filter(a -> !a.isEmpty())
.forEach(unifiedAnswers::add);
return unifiedAnswers;
} | java | public QueryAnswers unify(Unifier unifier){
if (unifier.isEmpty()) return new QueryAnswers(this);
QueryAnswers unifiedAnswers = new QueryAnswers();
this.stream()
.map(unifier::apply)
.filter(a -> !a.isEmpty())
.forEach(unifiedAnswers::add);
return unifiedAnswers;
} | [
"public",
"QueryAnswers",
"unify",
"(",
"Unifier",
"unifier",
")",
"{",
"if",
"(",
"unifier",
".",
"isEmpty",
"(",
")",
")",
"return",
"new",
"QueryAnswers",
"(",
"this",
")",
";",
"QueryAnswers",
"unifiedAnswers",
"=",
"new",
"QueryAnswers",
"(",
")",
";",
"this",
".",
"stream",
"(",
")",
".",
"map",
"(",
"unifier",
"::",
"apply",
")",
".",
"filter",
"(",
"a",
"->",
"!",
"a",
".",
"isEmpty",
"(",
")",
")",
".",
"forEach",
"(",
"unifiedAnswers",
"::",
"add",
")",
";",
"return",
"unifiedAnswers",
";",
"}"
] | unify the answers by applying unifier to variable set
@param unifier map of [key: from/value: to] unifiers
@return unified query answers | [
"unify",
"the",
"answers",
"by",
"applying",
"unifier",
"to",
"variable",
"set"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/reasoner/query/QueryAnswers.java#L77-L85 |
22,978 | graknlabs/grakn | server/src/graql/reasoner/query/QueryAnswers.java | QueryAnswers.unify | public QueryAnswers unify(MultiUnifier multiUnifier){
QueryAnswers unifiedAnswers = new QueryAnswers();
this.stream()
.flatMap(multiUnifier::apply)
.filter(ans -> !ans.isEmpty())
.forEach(unifiedAnswers::add);
return unifiedAnswers;
} | java | public QueryAnswers unify(MultiUnifier multiUnifier){
QueryAnswers unifiedAnswers = new QueryAnswers();
this.stream()
.flatMap(multiUnifier::apply)
.filter(ans -> !ans.isEmpty())
.forEach(unifiedAnswers::add);
return unifiedAnswers;
} | [
"public",
"QueryAnswers",
"unify",
"(",
"MultiUnifier",
"multiUnifier",
")",
"{",
"QueryAnswers",
"unifiedAnswers",
"=",
"new",
"QueryAnswers",
"(",
")",
";",
"this",
".",
"stream",
"(",
")",
".",
"flatMap",
"(",
"multiUnifier",
"::",
"apply",
")",
".",
"filter",
"(",
"ans",
"->",
"!",
"ans",
".",
"isEmpty",
"(",
")",
")",
".",
"forEach",
"(",
"unifiedAnswers",
"::",
"add",
")",
";",
"return",
"unifiedAnswers",
";",
"}"
] | unify the answers by applying multiunifier to variable set
@param multiUnifier multiunifier to be applied to the query answers
@return unified query answers | [
"unify",
"the",
"answers",
"by",
"applying",
"multiunifier",
"to",
"variable",
"set"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/reasoner/query/QueryAnswers.java#L92-L99 |
22,979 | graknlabs/grakn | server/src/server/kb/concept/ElementFactory.java | ElementFactory.buildRelation | RelationImpl buildRelation(EdgeElement edge) {
return getOrBuildConcept(edge, (e) -> RelationImpl.create(RelationEdge.get(edge)));
} | java | RelationImpl buildRelation(EdgeElement edge) {
return getOrBuildConcept(edge, (e) -> RelationImpl.create(RelationEdge.get(edge)));
} | [
"RelationImpl",
"buildRelation",
"(",
"EdgeElement",
"edge",
")",
"{",
"return",
"getOrBuildConcept",
"(",
"edge",
",",
"(",
"e",
")",
"-",
">",
"RelationImpl",
".",
"create",
"(",
"RelationEdge",
".",
"get",
"(",
"edge",
")",
")",
")",
";",
"}"
] | Used by RelationEdge to build a RelationImpl object out of a provided Edge | [
"Used",
"by",
"RelationEdge",
"to",
"build",
"a",
"RelationImpl",
"object",
"out",
"of",
"a",
"provided",
"Edge"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/ElementFactory.java#L113-L115 |
22,980 | graknlabs/grakn | server/src/server/kb/concept/ElementFactory.java | ElementFactory.buildRelationReified | RelationReified buildRelationReified(VertexElement vertex, RelationType type) {
return RelationReified.create(vertex, type);
} | java | RelationReified buildRelationReified(VertexElement vertex, RelationType type) {
return RelationReified.create(vertex, type);
} | [
"RelationReified",
"buildRelationReified",
"(",
"VertexElement",
"vertex",
",",
"RelationType",
"type",
")",
"{",
"return",
"RelationReified",
".",
"create",
"(",
"vertex",
",",
"type",
")",
";",
"}"
] | Used by RelationEdge when it needs to reify a relation.
Used by this factory when need to build an explicit relation
@return ReifiedRelation | [
"Used",
"by",
"RelationEdge",
"when",
"it",
"needs",
"to",
"reify",
"a",
"relation",
".",
"Used",
"by",
"this",
"factory",
"when",
"need",
"to",
"build",
"an",
"explicit",
"relation"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/ElementFactory.java#L122-L124 |
22,981 | graknlabs/grakn | server/src/server/kb/concept/ElementFactory.java | ElementFactory.buildRelation | RelationImpl buildRelation(VertexElement vertex, RelationType type) {
return getOrBuildConcept(vertex, (v) -> RelationImpl.create(buildRelationReified(v, type)));
} | java | RelationImpl buildRelation(VertexElement vertex, RelationType type) {
return getOrBuildConcept(vertex, (v) -> RelationImpl.create(buildRelationReified(v, type)));
} | [
"RelationImpl",
"buildRelation",
"(",
"VertexElement",
"vertex",
",",
"RelationType",
"type",
")",
"{",
"return",
"getOrBuildConcept",
"(",
"vertex",
",",
"(",
"v",
")",
"-",
">",
"RelationImpl",
".",
"create",
"(",
"buildRelationReified",
"(",
"v",
",",
"type",
")",
")",
")",
";",
"}"
] | Used by RelationTypeImpl to create a new instance of RelationImpl
first build a ReifiedRelation and then inject it to RelationImpl
@return | [
"Used",
"by",
"RelationTypeImpl",
"to",
"create",
"a",
"new",
"instance",
"of",
"RelationImpl",
"first",
"build",
"a",
"ReifiedRelation",
"and",
"then",
"inject",
"it",
"to",
"RelationImpl"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/ElementFactory.java#L131-L133 |
22,982 | graknlabs/grakn | server/src/server/kb/concept/ElementFactory.java | ElementFactory.getBaseType | private Schema.BaseType getBaseType(VertexElement vertex) {
try {
return Schema.BaseType.valueOf(vertex.label());
} catch (IllegalArgumentException e) {
//Base type appears to be invalid. Let's try getting the type via the shard edge
Optional<VertexElement> type = vertex.getEdgesOfType(Direction.OUT, Schema.EdgeLabel.SHARD).
map(EdgeElement::target).findAny();
if (type.isPresent()) {
String label = type.get().label();
if (label.equals(Schema.BaseType.ENTITY_TYPE.name())) return Schema.BaseType.ENTITY;
if (label.equals(RELATION_TYPE.name())) return Schema.BaseType.RELATION;
if (label.equals(Schema.BaseType.ATTRIBUTE_TYPE.name())) return Schema.BaseType.ATTRIBUTE;
}
}
throw new IllegalStateException("Could not determine the base type of vertex [" + vertex + "]");
} | java | private Schema.BaseType getBaseType(VertexElement vertex) {
try {
return Schema.BaseType.valueOf(vertex.label());
} catch (IllegalArgumentException e) {
//Base type appears to be invalid. Let's try getting the type via the shard edge
Optional<VertexElement> type = vertex.getEdgesOfType(Direction.OUT, Schema.EdgeLabel.SHARD).
map(EdgeElement::target).findAny();
if (type.isPresent()) {
String label = type.get().label();
if (label.equals(Schema.BaseType.ENTITY_TYPE.name())) return Schema.BaseType.ENTITY;
if (label.equals(RELATION_TYPE.name())) return Schema.BaseType.RELATION;
if (label.equals(Schema.BaseType.ATTRIBUTE_TYPE.name())) return Schema.BaseType.ATTRIBUTE;
}
}
throw new IllegalStateException("Could not determine the base type of vertex [" + vertex + "]");
} | [
"private",
"Schema",
".",
"BaseType",
"getBaseType",
"(",
"VertexElement",
"vertex",
")",
"{",
"try",
"{",
"return",
"Schema",
".",
"BaseType",
".",
"valueOf",
"(",
"vertex",
".",
"label",
"(",
")",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"//Base type appears to be invalid. Let's try getting the type via the shard edge",
"Optional",
"<",
"VertexElement",
">",
"type",
"=",
"vertex",
".",
"getEdgesOfType",
"(",
"Direction",
".",
"OUT",
",",
"Schema",
".",
"EdgeLabel",
".",
"SHARD",
")",
".",
"map",
"(",
"EdgeElement",
"::",
"target",
")",
".",
"findAny",
"(",
")",
";",
"if",
"(",
"type",
".",
"isPresent",
"(",
")",
")",
"{",
"String",
"label",
"=",
"type",
".",
"get",
"(",
")",
".",
"label",
"(",
")",
";",
"if",
"(",
"label",
".",
"equals",
"(",
"Schema",
".",
"BaseType",
".",
"ENTITY_TYPE",
".",
"name",
"(",
")",
")",
")",
"return",
"Schema",
".",
"BaseType",
".",
"ENTITY",
";",
"if",
"(",
"label",
".",
"equals",
"(",
"RELATION_TYPE",
".",
"name",
"(",
")",
")",
")",
"return",
"Schema",
".",
"BaseType",
".",
"RELATION",
";",
"if",
"(",
"label",
".",
"equals",
"(",
"Schema",
".",
"BaseType",
".",
"ATTRIBUTE_TYPE",
".",
"name",
"(",
")",
")",
")",
"return",
"Schema",
".",
"BaseType",
".",
"ATTRIBUTE",
";",
"}",
"}",
"throw",
"new",
"IllegalStateException",
"(",
"\"Could not determine the base type of vertex [\"",
"+",
"vertex",
"+",
"\"]\"",
")",
";",
"}"
] | This is a helper method to get the base type of a vertex.
It first tried to get the base type via the label.
If this is not possible it then tries to get the base type via the Shard Edge.
@param vertex The vertex to build a concept from
@return The base type of the vertex, if it is a valid concept. | [
"This",
"is",
"a",
"helper",
"method",
"to",
"get",
"the",
"base",
"type",
"of",
"a",
"vertex",
".",
"It",
"first",
"tried",
"to",
"get",
"the",
"base",
"type",
"via",
"the",
"label",
".",
"If",
"this",
"is",
"not",
"possible",
"it",
"then",
"tries",
"to",
"get",
"the",
"base",
"type",
"via",
"the",
"Shard",
"Edge",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/ElementFactory.java#L252-L268 |
22,983 | graknlabs/grakn | server/src/server/kb/concept/ElementFactory.java | ElementFactory.addVertexElement | public VertexElement addVertexElement(Schema.BaseType baseType) {
Vertex vertex = graph.addVertex(baseType.name());
return new VertexElement(tx, vertex);
} | java | public VertexElement addVertexElement(Schema.BaseType baseType) {
Vertex vertex = graph.addVertex(baseType.name());
return new VertexElement(tx, vertex);
} | [
"public",
"VertexElement",
"addVertexElement",
"(",
"Schema",
".",
"BaseType",
"baseType",
")",
"{",
"Vertex",
"vertex",
"=",
"graph",
".",
"addVertex",
"(",
"baseType",
".",
"name",
"(",
")",
")",
";",
"return",
"new",
"VertexElement",
"(",
"tx",
",",
"vertex",
")",
";",
"}"
] | Creates a new Vertex in the graph and builds a VertexElement which wraps the newly created vertex
@param baseType The Schema.BaseType
@return a new VertexElement | [
"Creates",
"a",
"new",
"Vertex",
"in",
"the",
"graph",
"and",
"builds",
"a",
"VertexElement",
"which",
"wraps",
"the",
"newly",
"created",
"vertex"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/ElementFactory.java#L308-L311 |
22,984 | graknlabs/grakn | concept/printer/StringPrinter.java | StringPrinter.colorKeyword | private String colorKeyword(String keyword) {
if(colorize) {
return ANSI.color(keyword, ANSI.BLUE);
} else {
return keyword;
}
} | java | private String colorKeyword(String keyword) {
if(colorize) {
return ANSI.color(keyword, ANSI.BLUE);
} else {
return keyword;
}
} | [
"private",
"String",
"colorKeyword",
"(",
"String",
"keyword",
")",
"{",
"if",
"(",
"colorize",
")",
"{",
"return",
"ANSI",
".",
"color",
"(",
"keyword",
",",
"ANSI",
".",
"BLUE",
")",
";",
"}",
"else",
"{",
"return",
"keyword",
";",
"}",
"}"
] | Color-codes the keyword if colorization enabled
@param keyword a keyword to color-code using ANSI colors
@return the keyword, color-coded | [
"Color",
"-",
"codes",
"the",
"keyword",
"if",
"colorization",
"enabled"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/concept/printer/StringPrinter.java#L238-L244 |
22,985 | graknlabs/grakn | concept/printer/StringPrinter.java | StringPrinter.colorType | private String colorType(SchemaConcept schemaConcept) {
if(colorize) {
return ANSI.color(label(schemaConcept.label()), ANSI.PURPLE);
} else {
return label(schemaConcept.label());
}
} | java | private String colorType(SchemaConcept schemaConcept) {
if(colorize) {
return ANSI.color(label(schemaConcept.label()), ANSI.PURPLE);
} else {
return label(schemaConcept.label());
}
} | [
"private",
"String",
"colorType",
"(",
"SchemaConcept",
"schemaConcept",
")",
"{",
"if",
"(",
"colorize",
")",
"{",
"return",
"ANSI",
".",
"color",
"(",
"label",
"(",
"schemaConcept",
".",
"label",
"(",
")",
")",
",",
"ANSI",
".",
"PURPLE",
")",
";",
"}",
"else",
"{",
"return",
"label",
"(",
"schemaConcept",
".",
"label",
"(",
")",
")",
";",
"}",
"}"
] | Color-codes the given type if colorization enabled
@param schemaConcept a type to color-code using ANSI colors
@return the type, color-coded | [
"Color",
"-",
"codes",
"the",
"given",
"type",
"if",
"colorization",
"enabled"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/concept/printer/StringPrinter.java#L251-L257 |
22,986 | graknlabs/grakn | server/src/server/session/cache/KeyspaceCache.java | KeyspaceCache.populateSchemaTxCache | void populateSchemaTxCache(TransactionCache transactionCache) {
try {
lock.writeLock().lock();
Map<Label, LabelId> cachedLabelsSnapshot = getCachedLabels();
cachedLabelsSnapshot.forEach(transactionCache::cacheLabel);
} finally {
lock.writeLock().unlock();
}
} | java | void populateSchemaTxCache(TransactionCache transactionCache) {
try {
lock.writeLock().lock();
Map<Label, LabelId> cachedLabelsSnapshot = getCachedLabels();
cachedLabelsSnapshot.forEach(transactionCache::cacheLabel);
} finally {
lock.writeLock().unlock();
}
} | [
"void",
"populateSchemaTxCache",
"(",
"TransactionCache",
"transactionCache",
")",
"{",
"try",
"{",
"lock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"Map",
"<",
"Label",
",",
"LabelId",
">",
"cachedLabelsSnapshot",
"=",
"getCachedLabels",
"(",
")",
";",
"cachedLabelsSnapshot",
".",
"forEach",
"(",
"transactionCache",
"::",
"cacheLabel",
")",
";",
"}",
"finally",
"{",
"lock",
".",
"writeLock",
"(",
")",
".",
"unlock",
"(",
")",
";",
"}",
"}"
] | Copy the contents of the Keyspace cache into a TransactionOLTP Cache
@param transactionCache | [
"Copy",
"the",
"contents",
"of",
"the",
"Keyspace",
"cache",
"into",
"a",
"TransactionOLTP",
"Cache"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/cache/KeyspaceCache.java#L49-L57 |
22,987 | graknlabs/grakn | server/src/server/session/cache/KeyspaceCache.java | KeyspaceCache.readTxCache | void readTxCache(TransactionCache transactionCache) {
//Check if the schema has been changed and should be flushed into this cache
if (!cachedLabels.equals(transactionCache.getLabelCache())) {
try {
lock.writeLock().lock();
cachedLabels.clear();
cachedLabels.putAll(transactionCache.getLabelCache());
} finally {
lock.writeLock().unlock();
}
}
} | java | void readTxCache(TransactionCache transactionCache) {
//Check if the schema has been changed and should be flushed into this cache
if (!cachedLabels.equals(transactionCache.getLabelCache())) {
try {
lock.writeLock().lock();
cachedLabels.clear();
cachedLabels.putAll(transactionCache.getLabelCache());
} finally {
lock.writeLock().unlock();
}
}
} | [
"void",
"readTxCache",
"(",
"TransactionCache",
"transactionCache",
")",
"{",
"//Check if the schema has been changed and should be flushed into this cache",
"if",
"(",
"!",
"cachedLabels",
".",
"equals",
"(",
"transactionCache",
".",
"getLabelCache",
"(",
")",
")",
")",
"{",
"try",
"{",
"lock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"cachedLabels",
".",
"clear",
"(",
")",
";",
"cachedLabels",
".",
"putAll",
"(",
"transactionCache",
".",
"getLabelCache",
"(",
")",
")",
";",
"}",
"finally",
"{",
"lock",
".",
"writeLock",
"(",
")",
".",
"unlock",
"(",
")",
";",
"}",
"}",
"}"
] | Reads the SchemaConcept labels currently in the transaction cache
into the keyspace cache. This happens when a commit occurs and allows us to track schema
mutations without having to read the graph.
@param transactionCache The transaction cache | [
"Reads",
"the",
"SchemaConcept",
"labels",
"currently",
"in",
"the",
"transaction",
"cache",
"into",
"the",
"keyspace",
"cache",
".",
"This",
"happens",
"when",
"a",
"commit",
"occurs",
"and",
"allows",
"us",
"to",
"track",
"schema",
"mutations",
"without",
"having",
"to",
"read",
"the",
"graph",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/session/cache/KeyspaceCache.java#L77-L88 |
22,988 | graknlabs/grakn | server/src/graql/gremlin/fragment/Fragment.java | Fragment.directedEdges | public Set<Weighted<DirectedEdge>> directedEdges(Map<NodeId, Node> nodes) {
return Collections.emptySet();
} | java | public Set<Weighted<DirectedEdge>> directedEdges(Map<NodeId, Node> nodes) {
return Collections.emptySet();
} | [
"public",
"Set",
"<",
"Weighted",
"<",
"DirectedEdge",
">",
">",
"directedEdges",
"(",
"Map",
"<",
"NodeId",
",",
"Node",
">",
"nodes",
")",
"{",
"return",
"Collections",
".",
"emptySet",
"(",
")",
";",
"}"
] | Convert the fragment to a set of weighted edges for query planning
@param nodes all nodes in the query
@return a set of edges | [
"Convert",
"the",
"fragment",
"to",
"a",
"set",
"of",
"weighted",
"edges",
"for",
"query",
"planning"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/fragment/Fragment.java#L176-L178 |
22,989 | graknlabs/grakn | server/src/server/kb/concept/AttributeTypeImpl.java | AttributeTypeImpl.putInstance | private Attribute<D> putInstance(Schema.BaseType instanceBaseType, Supplier<Attribute<D>> finder, BiFunction<VertexElement, AttributeType<D>, Attribute<D>> producer, boolean isInferred) {
Attribute<D> instance = finder.get();
if (instance == null) {
instance = addInstance(instanceBaseType, producer, isInferred);
} else {
if (isInferred && !instance.isInferred()) {
throw TransactionException.nonInferredThingExists(instance);
}
}
return instance;
} | java | private Attribute<D> putInstance(Schema.BaseType instanceBaseType, Supplier<Attribute<D>> finder, BiFunction<VertexElement, AttributeType<D>, Attribute<D>> producer, boolean isInferred) {
Attribute<D> instance = finder.get();
if (instance == null) {
instance = addInstance(instanceBaseType, producer, isInferred);
} else {
if (isInferred && !instance.isInferred()) {
throw TransactionException.nonInferredThingExists(instance);
}
}
return instance;
} | [
"private",
"Attribute",
"<",
"D",
">",
"putInstance",
"(",
"Schema",
".",
"BaseType",
"instanceBaseType",
",",
"Supplier",
"<",
"Attribute",
"<",
"D",
">",
">",
"finder",
",",
"BiFunction",
"<",
"VertexElement",
",",
"AttributeType",
"<",
"D",
">",
",",
"Attribute",
"<",
"D",
">",
">",
"producer",
",",
"boolean",
"isInferred",
")",
"{",
"Attribute",
"<",
"D",
">",
"instance",
"=",
"finder",
".",
"get",
"(",
")",
";",
"if",
"(",
"instance",
"==",
"null",
")",
"{",
"instance",
"=",
"addInstance",
"(",
"instanceBaseType",
",",
"producer",
",",
"isInferred",
")",
";",
"}",
"else",
"{",
"if",
"(",
"isInferred",
"&&",
"!",
"instance",
".",
"isInferred",
"(",
")",
")",
"{",
"throw",
"TransactionException",
".",
"nonInferredThingExists",
"(",
"instance",
")",
";",
"}",
"}",
"return",
"instance",
";",
"}"
] | Utility method used to create or find an instance of this type
@param instanceBaseType The base type of the instances of this type
@param finder The method to find the instrance if it already exists
@param producer The factory method to produce the instance if it doesn't exist
@return A new or already existing instance | [
"Utility",
"method",
"used",
"to",
"create",
"or",
"find",
"an",
"instance",
"of",
"this",
"type"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/AttributeTypeImpl.java#L139-L149 |
22,990 | graknlabs/grakn | server/src/server/kb/concept/AttributeTypeImpl.java | AttributeTypeImpl.checkConformsToRegexes | private void checkConformsToRegexes(String value) {
//Not checking the datatype because the regex will always be null for non strings.
this.sups().forEach(sup -> {
String regex = sup.regex();
if (regex != null && !Pattern.matches(regex, value)) {
throw TransactionException.regexFailure(this, value, regex);
}
});
} | java | private void checkConformsToRegexes(String value) {
//Not checking the datatype because the regex will always be null for non strings.
this.sups().forEach(sup -> {
String regex = sup.regex();
if (regex != null && !Pattern.matches(regex, value)) {
throw TransactionException.regexFailure(this, value, regex);
}
});
} | [
"private",
"void",
"checkConformsToRegexes",
"(",
"String",
"value",
")",
"{",
"//Not checking the datatype because the regex will always be null for non strings.",
"this",
".",
"sups",
"(",
")",
".",
"forEach",
"(",
"sup",
"->",
"{",
"String",
"regex",
"=",
"sup",
".",
"regex",
"(",
")",
";",
"if",
"(",
"regex",
"!=",
"null",
"&&",
"!",
"Pattern",
".",
"matches",
"(",
"regex",
",",
"value",
")",
")",
"{",
"throw",
"TransactionException",
".",
"regexFailure",
"(",
"this",
",",
"value",
",",
"regex",
")",
";",
"}",
"}",
")",
";",
"}"
] | Checks if all the regex's of the types of this resource conforms to the value provided.
@param value The value to check the regexes against.
@throws TransactionException when the value does not conform to the regex of its types | [
"Checks",
"if",
"all",
"the",
"regex",
"s",
"of",
"the",
"types",
"of",
"this",
"resource",
"conforms",
"to",
"the",
"value",
"provided",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/AttributeTypeImpl.java#L157-L165 |
22,991 | graknlabs/grakn | server/src/server/kb/concept/AttributeTypeImpl.java | AttributeTypeImpl.dataType | @SuppressWarnings({"unchecked"})
@Nullable
@Override
public DataType<D> dataType() {
String className = vertex().property(Schema.VertexProperty.DATA_TYPE);
if (className == null) return null;
try {
return (DataType<D>) DataType.of(Class.forName(className));
} catch (ClassNotFoundException e) {
throw TransactionException.unsupportedDataType(className);
}
} | java | @SuppressWarnings({"unchecked"})
@Nullable
@Override
public DataType<D> dataType() {
String className = vertex().property(Schema.VertexProperty.DATA_TYPE);
if (className == null) return null;
try {
return (DataType<D>) DataType.of(Class.forName(className));
} catch (ClassNotFoundException e) {
throw TransactionException.unsupportedDataType(className);
}
} | [
"@",
"SuppressWarnings",
"(",
"{",
"\"unchecked\"",
"}",
")",
"@",
"Nullable",
"@",
"Override",
"public",
"DataType",
"<",
"D",
">",
"dataType",
"(",
")",
"{",
"String",
"className",
"=",
"vertex",
"(",
")",
".",
"property",
"(",
"Schema",
".",
"VertexProperty",
".",
"DATA_TYPE",
")",
";",
"if",
"(",
"className",
"==",
"null",
")",
"return",
"null",
";",
"try",
"{",
"return",
"(",
"DataType",
"<",
"D",
">",
")",
"DataType",
".",
"of",
"(",
"Class",
".",
"forName",
"(",
"className",
")",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e",
")",
"{",
"throw",
"TransactionException",
".",
"unsupportedDataType",
"(",
"className",
")",
";",
"}",
"}"
] | This unsafe cast is suppressed because at this stage we do not know what the type is when reading from the rootGraph. | [
"This",
"unsafe",
"cast",
"is",
"suppressed",
"because",
"at",
"this",
"stage",
"we",
"do",
"not",
"know",
"what",
"the",
"type",
"is",
"when",
"reading",
"from",
"the",
"rootGraph",
"."
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/server/kb/concept/AttributeTypeImpl.java#L177-L189 |
22,992 | graknlabs/grakn | server/src/graql/gremlin/fragment/Fragments.java | Fragments.outSubs | static <T> GraphTraversal<T, Vertex> outSubs(GraphTraversal<T, Vertex> traversal) {
return outSubs(traversal, TRAVERSE_ALL_SUB_EDGES);
} | java | static <T> GraphTraversal<T, Vertex> outSubs(GraphTraversal<T, Vertex> traversal) {
return outSubs(traversal, TRAVERSE_ALL_SUB_EDGES);
} | [
"static",
"<",
"T",
">",
"GraphTraversal",
"<",
"T",
",",
"Vertex",
">",
"outSubs",
"(",
"GraphTraversal",
"<",
"T",
",",
"Vertex",
">",
"traversal",
")",
"{",
"return",
"outSubs",
"(",
"traversal",
",",
"TRAVERSE_ALL_SUB_EDGES",
")",
";",
"}"
] | Default unlimiteid depth sub-edge traversal
@param traversal
@param <T>
@return | [
"Default",
"unlimiteid",
"depth",
"sub",
"-",
"edge",
"traversal"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/fragment/Fragments.java#L154-L156 |
22,993 | graknlabs/grakn | server/src/graql/gremlin/fragment/Fragments.java | Fragments.inSubs | static <T> GraphTraversal<T, Vertex> inSubs(GraphTraversal<T, Vertex> traversal) {
return inSubs(traversal, TRAVERSE_ALL_SUB_EDGES);
} | java | static <T> GraphTraversal<T, Vertex> inSubs(GraphTraversal<T, Vertex> traversal) {
return inSubs(traversal, TRAVERSE_ALL_SUB_EDGES);
} | [
"static",
"<",
"T",
">",
"GraphTraversal",
"<",
"T",
",",
"Vertex",
">",
"inSubs",
"(",
"GraphTraversal",
"<",
"T",
",",
"Vertex",
">",
"traversal",
")",
"{",
"return",
"inSubs",
"(",
"traversal",
",",
"TRAVERSE_ALL_SUB_EDGES",
")",
";",
"}"
] | Default unlimited-depth sub-edge traversal
@param traversal
@param <T>
@return | [
"Default",
"unlimited",
"-",
"depth",
"sub",
"-",
"edge",
"traversal"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/fragment/Fragments.java#L180-L182 |
22,994 | graknlabs/grakn | server/src/graql/gremlin/fragment/Fragments.java | Fragments.isVertex | static <T> GraphTraversal<T, Vertex> isVertex(GraphTraversal<T, ? extends Element> traversal) {
// This cast is safe because we filter only to vertices
//noinspection unchecked
return (GraphTraversal<T, Vertex>) traversal.filter(e -> e.get() instanceof Vertex);
} | java | static <T> GraphTraversal<T, Vertex> isVertex(GraphTraversal<T, ? extends Element> traversal) {
// This cast is safe because we filter only to vertices
//noinspection unchecked
return (GraphTraversal<T, Vertex>) traversal.filter(e -> e.get() instanceof Vertex);
} | [
"static",
"<",
"T",
">",
"GraphTraversal",
"<",
"T",
",",
"Vertex",
">",
"isVertex",
"(",
"GraphTraversal",
"<",
"T",
",",
"?",
"extends",
"Element",
">",
"traversal",
")",
"{",
"// This cast is safe because we filter only to vertices",
"//noinspection unchecked",
"return",
"(",
"GraphTraversal",
"<",
"T",
",",
"Vertex",
">",
")",
"traversal",
".",
"filter",
"(",
"e",
"->",
"e",
".",
"get",
"(",
")",
"instanceof",
"Vertex",
")",
";",
"}"
] | Create a traversal that filters to only vertices | [
"Create",
"a",
"traversal",
"that",
"filters",
"to",
"only",
"vertices"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/fragment/Fragments.java#L222-L226 |
22,995 | graknlabs/grakn | server/src/graql/gremlin/fragment/Fragments.java | Fragments.isEdge | static <T> GraphTraversal<T, Edge> isEdge(GraphTraversal<T, ? extends Element> traversal) {
// This cast is safe because we filter only to edges
//noinspection unchecked
return (GraphTraversal<T, Edge>) traversal.filter(e -> e.get() instanceof Edge);
} | java | static <T> GraphTraversal<T, Edge> isEdge(GraphTraversal<T, ? extends Element> traversal) {
// This cast is safe because we filter only to edges
//noinspection unchecked
return (GraphTraversal<T, Edge>) traversal.filter(e -> e.get() instanceof Edge);
} | [
"static",
"<",
"T",
">",
"GraphTraversal",
"<",
"T",
",",
"Edge",
">",
"isEdge",
"(",
"GraphTraversal",
"<",
"T",
",",
"?",
"extends",
"Element",
">",
"traversal",
")",
"{",
"// This cast is safe because we filter only to edges",
"//noinspection unchecked",
"return",
"(",
"GraphTraversal",
"<",
"T",
",",
"Edge",
">",
")",
"traversal",
".",
"filter",
"(",
"e",
"->",
"e",
".",
"get",
"(",
")",
"instanceof",
"Edge",
")",
";",
"}"
] | Create a traversal that filters to only edges | [
"Create",
"a",
"traversal",
"that",
"filters",
"to",
"only",
"edges"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/fragment/Fragments.java#L231-L235 |
22,996 | graknlabs/grakn | server/src/graql/gremlin/sets/RolePlayerFragmentSet.java | RolePlayerFragmentSet.removeRoleVar | private RolePlayerFragmentSet removeRoleVar() {
Preconditions.checkNotNull(role());
return new AutoValue_RolePlayerFragmentSet(
varProperty(), relation(), edge(), rolePlayer(), null, roleLabels(), relationTypeLabels()
);
} | java | private RolePlayerFragmentSet removeRoleVar() {
Preconditions.checkNotNull(role());
return new AutoValue_RolePlayerFragmentSet(
varProperty(), relation(), edge(), rolePlayer(), null, roleLabels(), relationTypeLabels()
);
} | [
"private",
"RolePlayerFragmentSet",
"removeRoleVar",
"(",
")",
"{",
"Preconditions",
".",
"checkNotNull",
"(",
"role",
"(",
")",
")",
";",
"return",
"new",
"AutoValue_RolePlayerFragmentSet",
"(",
"varProperty",
"(",
")",
",",
"relation",
"(",
")",
",",
"edge",
"(",
")",
",",
"rolePlayer",
"(",
")",
",",
"null",
",",
"roleLabels",
"(",
")",
",",
"relationTypeLabels",
"(",
")",
")",
";",
"}"
] | Remove any specified role variable | [
"Remove",
"any",
"specified",
"role",
"variable"
] | 6aaee75ea846202474d591f8809d62028262fac5 | https://github.com/graknlabs/grakn/blob/6aaee75ea846202474d591f8809d62028262fac5/server/src/graql/gremlin/sets/RolePlayerFragmentSet.java#L280-L285 |
22,997 | kiegroup/jbpm | jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeImpl.java | NodeImpl.getFrom | public Connection getFrom() {
final List<Connection> list =
getIncomingConnections(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
if (list.size() == 0) {
return null;
}
if (list.size() == 1) {
return list.get(0);
}
if ("true".equals(System.getProperty("jbpm.enable.multi.con"))) {
return list.get(0);
} else {
throw new IllegalArgumentException(
"Trying to retrieve the from connection but multiple connections are present");
}
} | java | public Connection getFrom() {
final List<Connection> list =
getIncomingConnections(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
if (list.size() == 0) {
return null;
}
if (list.size() == 1) {
return list.get(0);
}
if ("true".equals(System.getProperty("jbpm.enable.multi.con"))) {
return list.get(0);
} else {
throw new IllegalArgumentException(
"Trying to retrieve the from connection but multiple connections are present");
}
} | [
"public",
"Connection",
"getFrom",
"(",
")",
"{",
"final",
"List",
"<",
"Connection",
">",
"list",
"=",
"getIncomingConnections",
"(",
"org",
".",
"jbpm",
".",
"workflow",
".",
"core",
".",
"Node",
".",
"CONNECTION_DEFAULT_TYPE",
")",
";",
"if",
"(",
"list",
".",
"size",
"(",
")",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"list",
".",
"size",
"(",
")",
"==",
"1",
")",
"{",
"return",
"list",
".",
"get",
"(",
"0",
")",
";",
"}",
"if",
"(",
"\"true\"",
".",
"equals",
"(",
"System",
".",
"getProperty",
"(",
"\"jbpm.enable.multi.con\"",
")",
")",
")",
"{",
"return",
"list",
".",
"get",
"(",
"0",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Trying to retrieve the from connection but multiple connections are present\"",
")",
";",
"}",
"}"
] | Helper method for nodes that have at most one default incoming connection | [
"Helper",
"method",
"for",
"nodes",
"that",
"have",
"at",
"most",
"one",
"default",
"incoming",
"connection"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeImpl.java#L203-L218 |
22,998 | kiegroup/jbpm | jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeImpl.java | NodeImpl.getDefaultIncomingConnections | public List<Connection> getDefaultIncomingConnections() {
return getIncomingConnections(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
} | java | public List<Connection> getDefaultIncomingConnections() {
return getIncomingConnections(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
} | [
"public",
"List",
"<",
"Connection",
">",
"getDefaultIncomingConnections",
"(",
")",
"{",
"return",
"getIncomingConnections",
"(",
"org",
".",
"jbpm",
".",
"workflow",
".",
"core",
".",
"Node",
".",
"CONNECTION_DEFAULT_TYPE",
")",
";",
"}"
] | Helper method for nodes that have multiple default incoming connections | [
"Helper",
"method",
"for",
"nodes",
"that",
"have",
"multiple",
"default",
"incoming",
"connections"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeImpl.java#L239-L241 |
22,999 | kiegroup/jbpm | jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeImpl.java | NodeImpl.getDefaultOutgoingConnections | public List<Connection> getDefaultOutgoingConnections() {
return getOutgoingConnections(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
} | java | public List<Connection> getDefaultOutgoingConnections() {
return getOutgoingConnections(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
} | [
"public",
"List",
"<",
"Connection",
">",
"getDefaultOutgoingConnections",
"(",
")",
"{",
"return",
"getOutgoingConnections",
"(",
"org",
".",
"jbpm",
".",
"workflow",
".",
"core",
".",
"Node",
".",
"CONNECTION_DEFAULT_TYPE",
")",
";",
"}"
] | Helper method for nodes that have multiple default outgoing connections | [
"Helper",
"method",
"for",
"nodes",
"that",
"have",
"multiple",
"default",
"outgoing",
"connections"
] | c3473c728aa382ebbea01e380c5e754a96647b82 | https://github.com/kiegroup/jbpm/blob/c3473c728aa382ebbea01e380c5e754a96647b82/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeImpl.java#L244-L246 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.