2016-02-04 55 views
0

我試圖創建一個Titan圖形示例,但它給出了錯誤。對於TitanGraph類型,未定義makeType()方法

我遇到的pom.xml如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion 
    <groupId>com.titanobwebservices.services</groupId> 
    <artifactId>titanob-services</artifactId> 
    <packaging>war</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>titanob-services Maven Webapp</name> 
    <url>http://maven.apache.org</url> 
    <dependencies> 
     <dependency> 
      <groupId>com.thinkaurelius.titan</groupId> 
      <artifactId>titan-core</artifactId> 
      <version>0.4.4</version> 
     </dependency> 
     <dependency> 
      <groupId>com.thinkaurelius.titan</groupId> 
      <artifactId>titan-berkeleyje</artifactId> 
      <version>0.4.4</version> 
     </dependency> 
     <dependency> 
      <groupId>com.thinkaurelius.titan</groupId> 
      <artifactId>titan-es</artifactId> 
      <version>0.4.4</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <finalName>titanob-services</finalName> 
    </build> 
</project> 

GodOfGraphFactory.java如下:

package com.titanos.webservices; 

import static com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.INDEX_BACKEND_KEY; 
import static com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_DIRECTORY_KEY; 

import java.io.File; 

import org.apache.commons.configuration.BaseConfiguration; 
import org.apache.commons.configuration.Configuration; 

import com.thinkaurelius.titan.core.TitanFactory; 
import com.thinkaurelius.titan.core.TitanGraph; 
import com.thinkaurelius.titan.core.TitanKey; 
import com.thinkaurelius.titan.core.attribute.Geoshape; 
import com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration; 
import com.tinkerpop.blueprints.Direction; 
import com.tinkerpop.blueprints.Edge; 
import com.tinkerpop.blueprints.Vertex; 
import com.tinkerpop.blueprints.util.ElementHelper; 

public class GraphOfTheGodsFactory { 

    public static final String INDEX_NAME = "search"; 


    public static TitanGraph create(final String directory) { 
     BaseConfiguration config = new BaseConfiguration(); 
     Configuration storage = config.subset(GraphDatabaseConfiguration.STORAGE_NAMESPACE); 
     // configuring local backend 
     storage.setProperty(GraphDatabaseConfiguration.STORAGE_BACKEND_KEY, "local"); 
     storage.setProperty(GraphDatabaseConfiguration.STORAGE_DIRECTORY_KEY, directory); 
     // configuring elastic search index 
     Configuration index = storage.subset(GraphDatabaseConfiguration.INDEX_NAMESPACE).subset(INDEX_NAME); 
     index.setProperty(INDEX_BACKEND_KEY, "elasticsearch"); 
     index.setProperty("local-mode", true); 
     index.setProperty("client-only", false); 
     index.setProperty(STORAGE_DIRECTORY_KEY, directory + File.separator + "es"); 

     TitanGraph graph = TitanFactory.open(config); 
     GraphOfTheGodsFactory.load(graph); 
     return graph; 
    } 

    public static void load(final TitanGraph graph) { 

     graph.makeType().name("name").dataType(String.class).indexed(Vertex.class).unique(Direction.BOTH).makePropertyKey(); 
     graph.makeType().name("age").dataType(Integer.class).indexed(INDEX_NAME, Vertex.class).unique(Direction.OUT).makePropertyKey(); 
     graph.makeType().name("type").dataType(String.class).unique(Direction.OUT).makePropertyKey(); 

     final TitanKey time = graph.makeType().name("time").dataType(Integer.class).unique(Direction.OUT).makePropertyKey(); 
     final TitanKey reason = graph.makeType().name("reason").dataType(String.class).indexed(INDEX_NAME, Edge.class).unique(Direction.OUT).makePropertyKey(); 
     graph.makeType().name("place").dataType(Geoshape.class).indexed(INDEX_NAME, Edge.class).unique(Direction.OUT).makePropertyKey(); 

     graph.makeType().name("father").unique(Direction.OUT).makeEdgeLabel(); 
     graph.makeType().name("mother").unique(Direction.OUT).makeEdgeLabel(); 
     graph.makeType().name("battled").primaryKey(time).makeEdgeLabel(); 
     graph.makeType().name("lives").signature(reason).makeEdgeLabel(); 
     graph.makeType().name("pet").makeEdgeLabel(); 
     graph.makeType().name("brother").makeEdgeLabel(); 

     graph.commit(); 

     // vertices 

     Vertex saturn = graph.addVertex(null); 
     saturn.setProperty("name", "saturn"); 
     saturn.setProperty("age", 10000); 
     saturn.setProperty("type", "titan"); 

     Vertex sky = graph.addVertex(null); 
     ElementHelper.setProperties(sky, "name", "sky", "type", "location"); 

     Vertex sea = graph.addVertex(null); 
     ElementHelper.setProperties(sea, "name", "sea", "type", "location"); 

     Vertex jupiter = graph.addVertex(null); 
     ElementHelper.setProperties(jupiter, "name", "jupiter", "age", 5000, "type", "god"); 

     Vertex neptune = graph.addVertex(null); 
     ElementHelper.setProperties(neptune, "name", "neptune", "age", 4500, "type", "god"); 

     Vertex hercules = graph.addVertex(null); 
     ElementHelper.setProperties(hercules, "name", "hercules", "age", 30, "type", "demigod"); 

     Vertex alcmene = graph.addVertex(null); 
     ElementHelper.setProperties(alcmene, "name", "alcmene", "age", 45, "type", "human"); 

     Vertex pluto = graph.addVertex(null); 
     ElementHelper.setProperties(pluto, "name", "pluto", "age", 4000, "type", "god"); 

     Vertex nemean = graph.addVertex(null); 
     ElementHelper.setProperties(nemean, "name", "nemean", "type", "monster"); 

     Vertex hydra = graph.addVertex(null); 
     ElementHelper.setProperties(hydra, "name", "hydra", "type", "monster"); 

     Vertex cerberus = graph.addVertex(null); 
     ElementHelper.setProperties(cerberus, "name", "cerberus", "type", "monster"); 

     Vertex tartarus = graph.addVertex(null); 
     ElementHelper.setProperties(tartarus, "name", "tartarus", "type", "location"); 

     // edges 

     jupiter.addEdge("father", saturn); 
     jupiter.addEdge("lives", sky).setProperty("reason", "loves fresh breezes"); 
     jupiter.addEdge("brother", neptune); 
     jupiter.addEdge("brother", pluto); 

     neptune.addEdge("lives", sea).setProperty("reason", "loves waves"); 
     neptune.addEdge("brother", jupiter); 
     neptune.addEdge("brother", pluto); 

     hercules.addEdge("father", jupiter); 
     hercules.addEdge("mother", alcmene); 
     ElementHelper.setProperties(hercules.addEdge("battled", nemean), "time", 1, "place", Geoshape.point(38.1f, 23.7f)); 
     ElementHelper.setProperties(hercules.addEdge("battled", hydra), "time", 2, "place", Geoshape.point(37.7f, 23.9f)); 
     ElementHelper.setProperties(hercules.addEdge("battled", cerberus), "time", 12, "place", Geoshape.point(39f, 22f)); 

     pluto.addEdge("brother", jupiter); 
     pluto.addEdge("brother", neptune); 
     pluto.addEdge("lives", tartarus).setProperty("reason", "no fear of death"); 
     pluto.addEdge("pet", cerberus); 

     cerberus.addEdge("lives", tartarus); 

     // commit the transaction to disk 
     graph.commit(); 
    } 
} 

但我發現了以下錯誤..

Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method makeType() is undefined for the type TitanGraph 
    at com.titanos.webservices.GraphOfTheGodsFactory.load(GraphOfTheGodsFactory.java:52) 
    at com.titanos.webservices.GraphOfTheGodsFactory.create(GraphOfTheGodsFactory.java:46) 
    at com.titanos.webservices.exampletest.main(exampletest.java:13) 

我附上了截圖。

enter image description here

我無法找到我在這個項目中缺少的依賴關係。

回答

0

由於TitanGraph上沒有方法makeType(),您正在編譯錯誤。如果你看看TitanGraph的Titan 0.4.4 javadoc,你會看到可用的方法。另請參閱Titan 0.3.2至0.4.0中的migration notes,其中指出API的重大變化。 GraphOfTheGodsFactory.java被封裝在Titan中,所以你可以從代碼中看到如何正確定義模式。

泰坦0.4.4於近2年前發佈。 Titan 1.0.0於2015年9月發佈,如果您開始使用Titan,這將是一個更好的起點。有關所有版本的更多詳細信息和文檔,請訪問Titan homepage。確保您將文檔與您正在構建的版本進行匹配。

相關問題