Project

General

Profile

« Previous | Next » 

Revision b0c4a3aa

Added by Andreas Kohlbecker over 8 years ago

gathering classification information implemented with test

View differences:

src/main/java/org/bgbm/biovel/drf/checklist/EEA_BDC_Client.java
12 12
import org.bgbm.biovel.drf.query.TinkerPopClient;
13 13
import org.bgbm.biovel.drf.store.Neo4jStore;
14 14
import org.bgbm.biovel.drf.store.Store;
15
import org.bgbm.biovel.drf.tnr.msg.Classification;
15 16
import org.bgbm.biovel.drf.tnr.msg.NameType;
16 17
import org.bgbm.biovel.drf.tnr.msg.Query;
17 18
import org.bgbm.biovel.drf.tnr.msg.Query.Request;
......
27 28
import org.bgbm.biovel.drf.utils.TnrMsgUtils;
28 29
import org.neo4j.graphdb.Relationship;
29 30

  
30
import com.tinkerpop.blueprints.Direction;
31 31
import com.tinkerpop.blueprints.Graph;
32 32
import com.tinkerpop.blueprints.Vertex;
33 33
import com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Vertex;
......
47 47
    public static final String COPYRIGHT_URL = "http://www.eea.europa.eu/legal/eea-data-policy";
48 48

  
49 49
    private static final String SPECIES_RDF_FILE_URL = "http://localhost/download/species.rdf.gz"; // http://eunis.eea.europa.eu/rdf/species.rdf.gz
50
    private static final String TAXONOMY_RDF_FILE_URL = "http://localhost/download/taxonomy.rdf.gz"; // http://eunis.eea.europa.eu/rdf/taxonomy.rdf.gz
50 51
    private static final String LEGALREFS_RDF_FILE_URL = "http://localhost/download/legalrefs.rdf.gz"; // http://eunis.eea.europa.eu/rdf/legalrefs.rdf.gz
51 52
    private static final String REFERENCES_RDF_FILE_URL = "http://localhost/download/references.rdf.gz"; // http://eunis.eea.europa.eu/rdf/references.rdf.gz
53

  
52 54
    private static final boolean REFRESH_TDB = false;
53 55

  
54 56
    public static final EnumSet<SearchMode> SEARCH_MODES = EnumSet.of(
......
101 103
            return abbreviation;
102 104
        }
103 105

  
104
        public String propertyURI(String name) {
106
        public String property(String name) {
105 107
            return schemaUri + name;
106 108
        }
107 109

  
......
148 150
    private void updateStore(Store neo4jStore) {
149 151
        try {
150 152
            neo4jStore.loadIntoStore(
151
                    SPECIES_RDF_FILE_URL,
152
                    LEGALREFS_RDF_FILE_URL,
153
                    REFERENCES_RDF_FILE_URL
153
//                    SPECIES_RDF_FILE_URL,
154
                    TAXONOMY_RDF_FILE_URL
155
//                    LEGALREFS_RDF_FILE_URL,
156
//                    REFERENCES_RDF_FILE_URL
154 157
                    );
155 158
        } catch (Exception e) {
156 159
            throw new RuntimeException("Loading "
157 160
                    + SPECIES_RDF_FILE_URL + ", "
161
                    + TAXONOMY_RDF_FILE_URL + ", "
158 162
                    + LEGALREFS_RDF_FILE_URL + ", "
159 163
                    + REFERENCES_RDF_FILE_URL +
160 164
                    " into Neo4jStore failed",  e);
......
205 209
        taxon.setTaxonName(taxonName);
206 210
        taxon.setIdentifier(v.getId().toString());
207 211
        taxon.setAccordingTo(queryClient.relatedVertexValue(v, RdfSchema.DWC, "nameAccordingToID"));
208
        URI typeUri = queryClient.relatedVertexURI(v, RdfSchema.RDF, "type");
212
        URI typeUri = queryClient.vertexURI(v, RdfSchema.RDF, "type");
209 213
        taxon.setTaxonomicStatus(typeUri.getFragment());
210 214

  
211 215
        createSources(v, taxon);
212 216

  
213
        /*
214

  
215 217
        // classification
216 218
        Classification c = null;
217
        Resource parentR = queryClient.objectAsResource(taxonR, RdfSchema.EUNIS_SPECIES, "taxonomy");
218
        while (parentR != null) {
219
        Vertex parentV= null;
220
        try {
221
            parentV = queryClient.relatedVertex(v, RdfSchema.EUNIS_SPECIES, "taxonomy");
222
        } catch (Exception e) {
223
            logger.error("No taxonomy information for " + v.toString());
224
        }
219 225

  
220
            String level = queryClient.objectAsString(parentR, RdfSchema.EUNIS_TAXONOMY, "level");
221
            String parentTaxonName = queryClient.objectAsString(parentR, RdfSchema.EUNIS_TAXONOMY, "name");
226
        while (parentV != null) {
227
            logger.debug("parent taxon: " + parentV.toString());
228
            String level = queryClient.relatedVertexValue(parentV, RdfSchema.EUNIS_TAXONOMY, "level");
229
            String parentTaxonName = queryClient.relatedVertexValue(parentV, RdfSchema.EUNIS_TAXONOMY, "name");
222 230

  
223 231
            RankLevel rankLevel = null;
224 232
            try {
......
253 261
                    break;
254 262
                }
255 263
            }
256
            Resource lastParentR = parentR;
257
            parentR = queryClient.objectAsResource(parentR, RdfSchema.EUNIS_TAXONOMY, "parent");
258
            if(lastParentR.equals(parentR)) {
264
            Vertex lastParentV = parentV;
265
            parentV = queryClient.relatedVertex(parentV, RdfSchema.EUNIS_TAXONOMY, "parent");
266
            if(lastParentV.equals(parentV)) {
259 267
                // avoid endless looping when data is not correct
260 268
                break;
261 269
            }
......
263 271
        if(c != null) {
264 272
            taxon.setClassification(c);
265 273
        }
266
        */
267 274
        return taxon;
268 275
    }
269 276

  
......
280 287

  
281 288
        try {
282 289
            List<Vertex> titleVs = taxonPipe
283
                    .outE(RdfSchema.EUNIS_SPECIES.propertyURI("hasLegalReference")).inV()
284
                    .outE(RdfSchema.DCTERMS.propertyURI("source")).inV().dedup()
285
                    .outE(RdfSchema.DCTERMS.propertyURI("title")).inV()
290
                    .outE(RdfSchema.EUNIS_SPECIES.property("hasLegalReference")).inV()
291
                    .outE(RdfSchema.DCTERMS.property("source")).inV().dedup()
292
                    .outE(RdfSchema.DCTERMS.property("title")).inV()
286 293
                    .toList();
287 294
            for(Vertex tv : titleVs) {
288 295
                Source source = new Source();
......
317 324

  
318 325
        try {
319 326
            List<Vertex> synonymVs = taxonPipe
320
                    .inE(RdfSchema.EUNIS_SPECIES.propertyURI("eunisPrimaryName")).outV().dedup()
327
                    .inE(RdfSchema.EUNIS_SPECIES.property("eunisPrimaryName")).outV().dedup()
321 328
                    .toList();
322 329
            for(Vertex synonymV : synonymVs) {
323 330
                String typeUri = queryClient.relatedVertexValue(synonymV, RdfSchema.RDF, "type");
......
379 386
            pipe = new GremlinPipeline<Graph, Vertex>(hitVs);
380 387

  
381 388
            List<Vertex> vertices = new ArrayList<Vertex>();
382
            pipe.in(RdfSchema.EUNIS_SPECIES.propertyURI("binomialName")).fill(vertices);
389
            pipe.in(RdfSchema.EUNIS_SPECIES.property("binomialName")).fill(vertices);
383 390

  
384 391
            updateQueriesWithResponse(vertices, null, null, checklistInfo, query);
385 392
            profiler.end(System.err);
......
434 441
            List<Vertex> vertices = new ArrayList<Vertex>();
435 442
            pipe = new GremlinPipeline<Graph, Vertex>(hitVs);
436 443
            Table table = new Table();
437
            pipe.as("match").in(RdfSchema.DWC.propertyURI("vernacularName")).as("taxon").table(table).iterate();
444
            pipe.as("match").in(RdfSchema.DWC.property("vernacularName")).as("taxon").table(table).iterate();
438 445

  
439 446
            updateQueriesWithResponse(
440 447
                    table.getColumn("taxon"), table.getColumn("match"),
......
540 547
            Vertex synonymV = taxonV;
541 548
            taxonV = null;
542 549
            try {
543
                taxonV = synonymV.getEdges(Direction.OUT, RdfSchema.EUNIS_SPECIES.propertyURI("eunisPrimaryName")).iterator().next().getVertex(Direction.IN);
550
                taxonV = queryClient.relatedVertex(synonymV, RdfSchema.EUNIS_SPECIES, "eunisPrimaryName");
544 551
            } catch(Exception e) {
545 552
                logger.error("No accepted taxon found for " + synonymV.toString() + " (" + synonymV.getProperty(GraphSail.VALUE) + ")");
546 553
            }
src/main/java/org/bgbm/biovel/drf/query/TinkerPopClient.java
86 86
    }
87 87

  
88 88
    /**
89
     * @param subject
89
     * Returns the first Vertex of the edge with the property specified by
90
     * <code>nameSpace</code> and <code>localName</code>. Both, directions
91
     * of edges are taken into account whereas the OUT edge is tested first.
92
     *
93
     * @param v
94
     * @param nameSpace
95
     * @param localName
96
     * @return
97
     */
98
    public Vertex relatedVertex(Vertex v, RdfSchema nameSpace, String localName) {
99
        Vertex relatedV = null;
100
        try {
101
            relatedV = v.getEdges(Direction.OUT, nameSpace.property(localName)).iterator().next().getVertex(Direction.IN);
102
        } catch (NoSuchElementException e) {
103
            try {
104
                relatedV = v.getEdges(Direction.IN, nameSpace.property(localName)).iterator().next().getVertex(Direction.OUT);
105
            } catch (NoSuchElementException e2) {
106
                logger.error("No taxonomy information for " + v.toString());
107
            }
108
        }
109
        return relatedV;
110
    }
111

  
112
    /**
113
     * Returns the <code>value</code> property of the first Vertex of the edge with the property specified by
114
     * <code>nameSpace</code> and <code>localName</code>. Both, directions
115
     * of edges are taken into account whereas the OUT edge is tested first.
116
     *
117
     * @param pipe
90 118
     * @param nameSpace
91 119
     * @param localName
92 120
     * @return
93 121
     */
94 122
    public String relatedVertexValue(GremlinPipeline<Graph, Vertex> pipe, RdfSchema nameSpace, String localName) {
95 123
        String txt = null;
96
        String edgeLabel = nameSpace.propertyURI(localName);
124
        String edgeLabel = nameSpace.property(localName);
97 125
        try {
98 126
            txt = pipe.outE(1, edgeLabel).inV().next().getProperty("value");
99 127
        } catch (FastNoSuchElementException e) {
......
114 142
        return txt;
115 143
    }
116 144

  
145
    /**
146
     * Returns the <code>value</code> property of the first Vertex of the edge with the property specified by
147
     * <code>nameSpace</code> and <code>localName</code>. Both, directions
148
     * of edges are taken into account whereas the OUT edge is tested first.
149
     *
150
     * @param v
151
     * @param nameSpace
152
     * @param localName
153
     * @return
154
     */
117 155
    public String relatedVertexValue(Vertex v, RdfSchema nameSpace, String localName) {
118 156
        String txt = null;
119
        String edgeLabel = nameSpace.propertyURI(localName);
157
        String edgeLabel = nameSpace.property(localName);
120 158
        try {
121 159
            txt = v.getEdges(Direction.OUT, edgeLabel).iterator().next().getVertex(Direction.IN)
122 160
                    .getProperty(GraphSail.VALUE);
......
139 177
     * @param localName
140 178
     * @return
141 179
     */
142
    public URI relatedVertexURI(Vertex v, RdfSchema nameSpace, String localName) {
180
    public URI vertexURI(Vertex v, RdfSchema nameSpace, String localName) {
143 181
        URI uri = null;
144 182
        try {
145 183
            if (v.getProperty(GraphSail.KIND).equals(GraphSail.URI)) {
src/test/java/org/bgbm/biovel/drf/checklist/EEA_BDC_ClientTest.java
3 3
import static org.junit.Assert.assertEquals;
4 4
import static org.junit.Assert.assertTrue;
5 5

  
6
import org.bgbm.biovel.drf.tnr.msg.Classification;
6 7
import org.bgbm.biovel.drf.tnr.msg.NameType;
7 8
import org.bgbm.biovel.drf.tnr.msg.Response;
8 9
import org.bgbm.biovel.drf.tnr.msg.TnrMsg;
......
48 49
        assertEquals("Canis aureus", response.getMatchingNameString());
49 50
        assertEquals("Canis aureus", response.getTaxon().getTaxonName().getCanonicalName());
50 51
        assertTrue(response.getSynonym().size() > 0);
52
        Classification c = response.getTaxon().getClassification();
53
        assertEquals("Canidae", c.getFamily());
54
        assertEquals("Carnivora", c.getOrder());
55
        assertEquals("Chordata", c.getPhylum());
56
        assertEquals("Animalia", c.getKingdom());
51 57
    }
52 58

  
53 59
    @Test

Also available in: Unified diff