org.vertexium.Graph.defineProperty()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(19.2k)|赞(0)|评价(0)|浏览(102)

本文整理了Java中org.vertexium.Graph.defineProperty()方法的一些代码示例,展示了Graph.defineProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.defineProperty()方法的具体详情如下:
包路径:org.vertexium.Graph
类名称:Graph
方法名:defineProperty

Graph.defineProperty介绍

[英]Creates a defines property builder. This is typically used by the indexer to give it hints on how it should index a property.
[中]创建定义属性生成器。这通常由索引器用于提示如何对属性进行索引。

代码示例

代码示例来源:origin: org.visallo/visallo-core-test

@Override
protected Graph getGraph() {
  Graph graph = super.getGraph();
  graph.defineProperty(VisalloProperties.TERM_MENTION_CONCEPT_TYPE.getPropertyName()).dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define();
  graph.defineProperty(VisalloProperties.TERM_MENTION_VISIBILITY_JSON.getPropertyName()).dataType(String.class).define();
  graph.defineProperty(VisalloProperties.TERM_MENTION_TITLE.getPropertyName()).dataType(String.class).define();
  graph.defineProperty(VisalloProperties.TERM_MENTION_PROCESS.getPropertyName()).dataType(String.class).define();
  graph.defineProperty(VisalloProperties.TERM_MENTION_PROPERTY_KEY.getPropertyName()).dataType(String.class).define();
  graph.defineProperty(VisalloProperties.TERM_MENTION_PROPERTY_NAME.getPropertyName()).dataType(String.class).define();
  graph.defineProperty(VisalloProperties.TERM_MENTION_START_OFFSET.getPropertyName()).dataType(Integer.class).define();
  graph.defineProperty(VisalloProperties.TERM_MENTION_END_OFFSET.getPropertyName()).dataType(Integer.class).define();
  return graph;
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testLargeFieldValuesThatAreMarkedWithExactMatch() {
  graph.defineProperty("field1").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define();
  StringBuilder largeText = new StringBuilder();
  for (int i = 0; i < 10000; i++) {
    largeText.append("test ");
  }
  graph.prepareVertex("v1", VISIBILITY_EMPTY)
      .addPropertyValue("", "field1", largeText.toString(), VISIBILITY_EMPTY)
      .save(AUTHORIZATIONS_EMPTY);
  graph.flush();
}

代码示例来源:origin: visallo/vertexium

@Test
public void testLargeFieldValuesThatAreMarkedWithExactMatch() {
  graph.defineProperty("field1").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define();
  StringBuilder largeText = new StringBuilder();
  for (int i = 0; i < 10000; i++) {
    largeText.append("test ");
  }
  graph.prepareVertex("v1", VISIBILITY_EMPTY)
      .addPropertyValue("", "field1", largeText.toString(), VISIBILITY_EMPTY)
      .save(AUTHORIZATIONS_EMPTY);
  graph.flush();
}

代码示例来源:origin: org.visallo/visallo-model-vertexium

@Override
protected void importOntologyAnnotationProperty(OWLOntology o, OWLAnnotationProperty annotationProperty, File inDir, Authorizations authorizations) {
  super.importOntologyAnnotationProperty(o, annotationProperty, inDir, authorizations);
  String about = annotationProperty.getIRI().toString();
  LOGGER.debug("disabling index for annotation property: " + about);
  if (!graph.isPropertyDefined(about)) {
    graph.defineProperty(about).dataType(String.class)
        .textIndexHint(TextIndexHint.NONE)
        .define();
  }
}

代码示例来源:origin: visallo/vertexium

@Test
public void testGraphQueryTextVertexDifferentAuths() {
  graph.defineProperty("title").dataType(String.class).textIndexHint(TextIndexHint.ALL).define();
  graph.defineProperty("fullText").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("title", "hello", VISIBILITY_EMPTY)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.prepareVertex("v2", VISIBILITY_B)
      .setProperty("fullText", StreamingPropertyValue.create("this is text with hello"), VISIBILITY_EMPTY)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  Iterable<Vertex> vertices = graph.query("hello", AUTHORIZATIONS_A).vertices();
  assertResultsCount(1, 1, (QueryResultsIterable) vertices);
  vertices = graph.query("hello", AUTHORIZATIONS_A_AND_B).vertices();
  assertResultsCount(2, 2, (QueryResultsIterable) vertices);
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testGraphQueryTextVertexDifferentAuths() {
  graph.defineProperty("title").dataType(String.class).textIndexHint(TextIndexHint.ALL).define();
  graph.defineProperty("fullText").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("title", "hello", VISIBILITY_EMPTY)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.prepareVertex("v2", VISIBILITY_B)
      .setProperty("fullText", StreamingPropertyValue.create("this is text with hello"), VISIBILITY_EMPTY)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  Iterable<Vertex> vertices = graph.query("hello", AUTHORIZATIONS_A).vertices();
  assertResultsCount(1, 1, (QueryResultsIterable) vertices);
  vertices = graph.query("hello", AUTHORIZATIONS_A_AND_B).vertices();
  assertResultsCount(2, 2, (QueryResultsIterable) vertices);
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testFieldBoost() throws Exception {
  assumeTrue("Boost not supported", graph.isFieldBoostSupported());
  graph.defineProperty("a")
      .dataType(String.class)
      .textIndexHint(TextIndexHint.ALL)
      .boost(1)
      .define();
  graph.defineProperty("b")
      .dataType(String.class)
      .textIndexHint(TextIndexHint.ALL)
      .boost(2)
      .define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("a", "Test Value", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.prepareVertex("v2", VISIBILITY_A)
      .setProperty("b", "Test Value", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  assertVertexIds(graph.query("Test", AUTHORIZATIONS_A).vertices(), "v2", "v1");
}

代码示例来源:origin: visallo/vertexium

@Test
public void testFieldBoost() throws Exception {
  assumeTrue("Boost not supported", graph.isFieldBoostSupported());
  graph.defineProperty("a")
      .dataType(String.class)
      .textIndexHint(TextIndexHint.ALL)
      .boost(1)
      .define();
  graph.defineProperty("b")
      .dataType(String.class)
      .textIndexHint(TextIndexHint.ALL)
      .boost(2)
      .define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("a", "Test Value", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.prepareVertex("v2", VISIBILITY_A)
      .setProperty("b", "Test Value", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  assertVertexIds(graph.query("Test", AUTHORIZATIONS_A).vertices(), "v2", "v1");
}

代码示例来源:origin: visallo/vertexium

@Test
public void testTextIndexStreamingPropertyValue() throws Exception {
  graph.defineProperty("none").dataType(String.class).textIndexHint(TextIndexHint.NONE).define();
  graph.defineProperty("both").dataType(String.class).textIndexHint(TextIndexHint.ALL).define();
  graph.defineProperty("fullText").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("none", StreamingPropertyValue.create("Test Value"), VISIBILITY_A)
      .setProperty("both", StreamingPropertyValue.create("Test Value"), VISIBILITY_A)
      .setProperty("fullText", StreamingPropertyValue.create("Test Value"), VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  Assert.assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("both", TextPredicate.CONTAINS, "Test").vertices()));
  Assert.assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("fullText", TextPredicate.CONTAINS, "Test").vertices()));
  Assert.assertEquals("un-indexed property shouldn't match partials", 0, count(graph.query(AUTHORIZATIONS_A).has("none", "Test").vertices()));
  try {
    graph.query(AUTHORIZATIONS_A).has("none", TextPredicate.CONTAINS, "Test");
    fail("Full text queries should not be allowed for properties that are not indexed with FULL_TEXT.");
  } catch (VertexiumException ve) {
    assertEquals("Check your TextIndexHint settings. Property none is not full text indexed.", ve.getMessage());
  }
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testTextIndexStreamingPropertyValue() throws Exception {
  graph.defineProperty("none").dataType(String.class).textIndexHint(TextIndexHint.NONE).define();
  graph.defineProperty("both").dataType(String.class).textIndexHint(TextIndexHint.ALL).define();
  graph.defineProperty("fullText").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("none", StreamingPropertyValue.create("Test Value"), VISIBILITY_A)
      .setProperty("both", StreamingPropertyValue.create("Test Value"), VISIBILITY_A)
      .setProperty("fullText", StreamingPropertyValue.create("Test Value"), VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  Assert.assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("both", TextPredicate.CONTAINS, "Test").vertices()));
  Assert.assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("fullText", TextPredicate.CONTAINS, "Test").vertices()));
  Assert.assertEquals("un-indexed property shouldn't match partials", 0, count(graph.query(AUTHORIZATIONS_A).has("none", "Test").vertices()));
  try {
    graph.query(AUTHORIZATIONS_A).has("none", TextPredicate.CONTAINS, "Test");
    fail("Full text queries should not be allowed for properties that are not indexed with FULL_TEXT.");
  } catch (VertexiumException ve) {
    assertEquals("Check your TextIndexHint settings. Property none is not full text indexed.", ve.getMessage());
  }
}

代码示例来源:origin: visallo/vertexium

@Test
public void testGraphQuerySortOnPropertyThatHasNoValuesInTheIndex() {
  graph.defineProperty("age").dataType(Integer.class).sortable(true).define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("name", "joe", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.prepareVertex("v2", VISIBILITY_A)
      .setProperty("name", "bob", VISIBILITY_B)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  QueryResultsIterable<Vertex> vertices
      = graph.query(AUTHORIZATIONS_A).sort("age", SortDirection.ASCENDING).vertices();
  Assert.assertEquals(2, count(vertices));
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testGraphQuerySortOnPropertyThatHasNoValuesInTheIndex() {
  graph.defineProperty("age").dataType(Integer.class).sortable(true).define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("name", "joe", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.prepareVertex("v2", VISIBILITY_A)
      .setProperty("name", "bob", VISIBILITY_B)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  QueryResultsIterable<Vertex> vertices
      = graph.query(AUTHORIZATIONS_A).sort("age", SortDirection.ASCENDING).vertices();
  Assert.assertEquals(2, count(vertices));
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testGraphQueryWithBoolean() {
  graph.defineProperty("boolean").dataType(Boolean.class).define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .addPropertyValue("k1", "boolean", true, VISIBILITY_A)
      .save(AUTHORIZATIONS_A);
  graph.flush();
  QueryResultsIterable<Vertex> vertices = graph.query("zzzzz", AUTHORIZATIONS_A).vertices();
  assertResultsCount(0, 0, vertices);
  vertices = graph.query(AUTHORIZATIONS_A).has("boolean", true).vertices();
  assertResultsCount(1, 1, vertices);
  vertices = graph.query(AUTHORIZATIONS_A).has("boolean", false).vertices();
  assertResultsCount(0, 0, vertices);
}

代码示例来源:origin: visallo/vertexium

@Test
public void testGraphQueryWithBoolean() {
  graph.defineProperty("boolean").dataType(Boolean.class).define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .addPropertyValue("k1", "boolean", true, VISIBILITY_A)
      .save(AUTHORIZATIONS_A);
  graph.flush();
  QueryResultsIterable<Vertex> vertices = graph.query("zzzzz", AUTHORIZATIONS_A).vertices();
  assertResultsCount(0, 0, vertices);
  vertices = graph.query(AUTHORIZATIONS_A).has("boolean", true).vertices();
  assertResultsCount(1, 1, vertices);
  vertices = graph.query(AUTHORIZATIONS_A).has("boolean", false).vertices();
  assertResultsCount(0, 0, vertices);
}

代码示例来源:origin: visallo/vertexium

@Test
public void testGraphQueryWithANDOperatorAndWithExactMatchFields() {
  graph.defineProperty("firstName").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("firstName", "Joe", VISIBILITY_A)
      .setProperty("lastName", "Ferner", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.prepareVertex("v2", VISIBILITY_A)
      .setProperty("firstName", "Joe", VISIBILITY_A)
      .setProperty("lastName", "Smith", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  assumeTrue("lucene and queries not supported", isLuceneQueriesSupported() && isLuceneAndQueriesSupported());
  Iterable<Vertex> vertices = graph.query("Joe AND ferner", AUTHORIZATIONS_A)
      .vertices();
  Assert.assertEquals(1, count(vertices));
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testGraphQueryWithANDOperatorAndWithExactMatchFields() {
  graph.defineProperty("firstName").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("firstName", "Joe", VISIBILITY_A)
      .setProperty("lastName", "Ferner", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.prepareVertex("v2", VISIBILITY_A)
      .setProperty("firstName", "Joe", VISIBILITY_A)
      .setProperty("lastName", "Smith", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.flush();
  assumeTrue("lucene and queries not supported", isLuceneQueriesSupported() && isLuceneAndQueriesSupported());
  Iterable<Vertex> vertices = graph.query("Joe AND ferner", AUTHORIZATIONS_A)
      .vertices();
  Assert.assertEquals(1, count(vertices));
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testGraphQueryHasWithSpacesAndFieldedQueryString() {
  assumeTrue("fielded query not supported", isFieldNamesInQuerySupported());
  graph.defineProperty("http://vertexium.org#name").dataType(String.class).textIndexHint(TextIndexHint.ALL).define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("http://vertexium.org#name", "Joe Ferner", VISIBILITY_A)
      .setProperty("propWithHyphen", "hyphen-word", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.prepareVertex("v2", VISIBILITY_A)
      .setProperty("http://vertexium.org#name", "Joe Smith", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  assumeTrue("lucene queries", isLuceneQueriesSupported());
  Iterable<Vertex> vertices = graph.query("http\\:\\/\\/vertexium.org#name:Joe", AUTHORIZATIONS_A)
      .vertices();
  Assert.assertEquals(2, count(vertices));
  vertices = graph.query("http\\:\\/\\/vertexium.org#name:\"Joe Ferner\"", AUTHORIZATIONS_A)
      .vertices();
  Assert.assertEquals(1, count(vertices));
}

代码示例来源:origin: visallo/vertexium

@Test
public void testGraphQueryHasWithSpacesAndFieldedQueryString() {
  assumeTrue("fielded query not supported", isFieldNamesInQuerySupported());
  graph.defineProperty("http://vertexium.org#name").dataType(String.class).textIndexHint(TextIndexHint.ALL).define();
  graph.prepareVertex("v1", VISIBILITY_A)
      .setProperty("http://vertexium.org#name", "Joe Ferner", VISIBILITY_A)
      .setProperty("propWithHyphen", "hyphen-word", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  graph.prepareVertex("v2", VISIBILITY_A)
      .setProperty("http://vertexium.org#name", "Joe Smith", VISIBILITY_A)
      .save(AUTHORIZATIONS_A_AND_B);
  assumeTrue("lucene queries", isLuceneQueriesSupported());
  Iterable<Vertex> vertices = graph.query("http\\:\\/\\/vertexium.org#name:Joe", AUTHORIZATIONS_A)
      .vertices();
  Assert.assertEquals(2, count(vertices));
  vertices = graph.query("http\\:\\/\\/vertexium.org#name:\"Joe Ferner\"", AUTHORIZATIONS_A)
      .vertices();
  Assert.assertEquals(1, count(vertices));
}

代码示例来源:origin: org.vertexium/vertexium-test

@Test
public void testAddValuesToExistingProperties() {
  Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL);
  getGraph().flush();
  graph.defineProperty("p1").dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define();
  v1.addPropertyValue("k1", "p1", "val1", VISIBILITY_A, AUTHORIZATIONS_ALL);
  getGraph().flush();
  assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds(), "v1");
  v1.addPropertyValue("k2", "p1", "val2", VISIBILITY_A, AUTHORIZATIONS_ALL);
  getGraph().flush();
  assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds(), "v1");
  assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val2").vertexIds(), "v1");
  assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val3").vertexIds());
  v1.addPropertyValue("k1", "p1", "val3", VISIBILITY_A, AUTHORIZATIONS_ALL);
  getGraph().flush();
  assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val3").vertexIds(), "v1");
  assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val2").vertexIds(), "v1");
  assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds());
}

代码示例来源:origin: visallo/vertexium

@Test
public void testAddValuesToExistingProperties() {
  Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL);
  getGraph().flush();
  graph.defineProperty("p1").dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define();
  v1.addPropertyValue("k1", "p1", "val1", VISIBILITY_A, AUTHORIZATIONS_ALL);
  getGraph().flush();
  assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds(), "v1");
  v1.addPropertyValue("k2", "p1", "val2", VISIBILITY_A, AUTHORIZATIONS_ALL);
  getGraph().flush();
  assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds(), "v1");
  assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val2").vertexIds(), "v1");
  assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val3").vertexIds());
  v1.addPropertyValue("k1", "p1", "val3", VISIBILITY_A, AUTHORIZATIONS_ALL);
  getGraph().flush();
  assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val3").vertexIds(), "v1");
  assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val2").vertexIds(), "v1");
  assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds());
}

相关文章

微信公众号

最新文章

更多