Skip to content

Commit

Permalink
[#191] added all nodes labeler configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jnguyenx committed Feb 13, 2017
1 parent 96e098b commit 02822fc
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@

import static com.google.common.collect.Iterables.size;
import static java.lang.String.format;
import io.scigraph.neo4j.Graph;
import io.scigraph.neo4j.Neo4jModule;
import io.scigraph.owlapi.OwlApiUtils;
import io.scigraph.owlapi.OwlPostprocessor;
import io.scigraph.owlapi.loader.OwlLoadConfiguration.MappedProperty;
import io.scigraph.owlapi.loader.OwlLoadConfiguration.OntologySetup;
import io.scigraph.owlapi.loader.bindings.IndicatesAddEdgeLabel;
import io.scigraph.owlapi.loader.bindings.IndicatesCliqueConfiguration;
import io.scigraph.owlapi.loader.bindings.IndicatesMappedProperties;
import io.scigraph.owlapi.loader.bindings.IndicatesNumberOfConsumerThreads;
import io.scigraph.owlapi.loader.bindings.IndicatesNumberOfProducerThreads;
import io.scigraph.owlapi.postprocessors.Clique;
import io.scigraph.owlapi.postprocessors.CliqueConfiguration;
import io.scigraph.owlapi.postprocessors.EdgeLabeler;

import java.io.File;
import java.util.HashSet;
Expand Down Expand Up @@ -65,6 +51,23 @@
import com.google.inject.Guice;
import com.google.inject.Injector;

import io.scigraph.neo4j.Graph;
import io.scigraph.neo4j.Neo4jModule;
import io.scigraph.owlapi.OwlApiUtils;
import io.scigraph.owlapi.OwlPostprocessor;
import io.scigraph.owlapi.loader.OwlLoadConfiguration.MappedProperty;
import io.scigraph.owlapi.loader.OwlLoadConfiguration.OntologySetup;
import io.scigraph.owlapi.loader.bindings.IndicatesAddEdgeLabel;
import io.scigraph.owlapi.loader.bindings.IndicatesAllNodesLabel;
import io.scigraph.owlapi.loader.bindings.IndicatesCliqueConfiguration;
import io.scigraph.owlapi.loader.bindings.IndicatesMappedProperties;
import io.scigraph.owlapi.loader.bindings.IndicatesNumberOfConsumerThreads;
import io.scigraph.owlapi.loader.bindings.IndicatesNumberOfProducerThreads;
import io.scigraph.owlapi.postprocessors.AllNodesLabeler;
import io.scigraph.owlapi.postprocessors.Clique;
import io.scigraph.owlapi.postprocessors.CliqueConfiguration;
import io.scigraph.owlapi.postprocessors.EdgeLabeler;

public class BatchOwlLoader {

private static final Logger logger = Logger.getLogger(BatchOwlLoader.class.getName());
Expand Down Expand Up @@ -114,6 +117,10 @@ public class BatchOwlLoader {
@Inject
@IndicatesAddEdgeLabel
Optional<Boolean> addEdgeLabel;

@Inject
@IndicatesAllNodesLabel
Optional<String> allNodesLabel;

static {
System.setProperty("entityExpansionLimit", Integer.toString(1_000_000));
Expand Down Expand Up @@ -164,7 +171,11 @@ public void loadOntology() throws InterruptedException, ExecutionException {
if (addEdgeLabel.or(false)) {
postprocessorProvider.runEdgeLabelerPostprocessor();
}


if(allNodesLabel.isPresent()) {
postprocessorProvider.runAllNodesLabeler(allNodesLabel.get());
}

postprocessorProvider.shutdown();

}
Expand Down Expand Up @@ -195,6 +206,11 @@ public void runEdgeLabelerPostprocessor() {
edgeLabeler.run();
}

public void runAllNodesLabeler(String label) {
AllNodesLabeler allNodesLabeler = new AllNodesLabeler(label, graphDb);
allNodesLabeler.run();
}

public void shutdown() {
try (Transaction tx = graphDb.beginTx()) {
logger.info(size(graphDb.getAllNodes()) + " nodes");
Expand All @@ -206,11 +222,10 @@ public void shutdown() {

}

public static void load(OwlLoadConfiguration config) throws InterruptedException,
ExecutionException {
Injector i =
Guice.createInjector(new OwlLoaderModule(config),
new Neo4jModule(config.getGraphConfiguration()));
public static void load(OwlLoadConfiguration config)
throws InterruptedException, ExecutionException {
Injector i = Guice.createInjector(new OwlLoaderModule(config),
new Neo4jModule(config.getGraphConfiguration()));
BatchOwlLoader loader = i.getInstance(BatchOwlLoader.class);
logger.info("Loading ontologies...");
Stopwatch timer = Stopwatch.createStarted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public class OwlLoadConfiguration {
private List<MappedProperty> mappedProperties = new ArrayList<>();
private Optional<CliqueConfiguration> cliqueConfiguration = Optional.absent();
private Optional<Boolean> addEdgeLabel = Optional.absent();
private Optional<String> allNodesLabel = Optional.absent();

public Optional<String> getAllNodesLabel() {
return allNodesLabel;
}

public void setAllNodesLabel(String allNodesLabel) {
this.allNodesLabel = Optional.of(allNodesLabel);
}

public Optional<Boolean> getAddEdgeLabel() {
return addEdgeLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@
*/
package io.scigraph.owlapi.loader;

import io.scigraph.frames.CommonProperties;
import io.scigraph.neo4j.Graph;
import io.scigraph.neo4j.GraphBatchImpl;
import io.scigraph.owlapi.loader.OwlLoadConfiguration.MappedProperty;
import io.scigraph.owlapi.loader.OwlLoadConfiguration.OntologySetup;
import io.scigraph.owlapi.loader.bindings.IndicatesAddEdgeLabel;
import io.scigraph.owlapi.loader.bindings.IndicatesCliqueConfiguration;
import io.scigraph.owlapi.loader.bindings.IndicatesExactIndexedProperties;
import io.scigraph.owlapi.loader.bindings.IndicatesIndexedProperties;
import io.scigraph.owlapi.loader.bindings.IndicatesMappedCategories;
import io.scigraph.owlapi.loader.bindings.IndicatesMappedProperties;
import io.scigraph.owlapi.loader.bindings.IndicatesNumberOfConsumerThreads;
import io.scigraph.owlapi.loader.bindings.IndicatesNumberOfProducerThreads;
import io.scigraph.owlapi.loader.bindings.IndicatesNumberOfShutdownProducers;
import io.scigraph.owlapi.loader.bindings.IndicatesUniqueProperty;
import io.scigraph.owlapi.postprocessors.CliqueConfiguration;

import java.io.File;
import java.io.IOException;
import java.util.List;
Expand All @@ -55,6 +38,24 @@
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;

import io.scigraph.frames.CommonProperties;
import io.scigraph.neo4j.Graph;
import io.scigraph.neo4j.GraphBatchImpl;
import io.scigraph.owlapi.loader.OwlLoadConfiguration.MappedProperty;
import io.scigraph.owlapi.loader.OwlLoadConfiguration.OntologySetup;
import io.scigraph.owlapi.loader.bindings.IndicatesAddEdgeLabel;
import io.scigraph.owlapi.loader.bindings.IndicatesAllNodesLabel;
import io.scigraph.owlapi.loader.bindings.IndicatesCliqueConfiguration;
import io.scigraph.owlapi.loader.bindings.IndicatesExactIndexedProperties;
import io.scigraph.owlapi.loader.bindings.IndicatesIndexedProperties;
import io.scigraph.owlapi.loader.bindings.IndicatesMappedCategories;
import io.scigraph.owlapi.loader.bindings.IndicatesMappedProperties;
import io.scigraph.owlapi.loader.bindings.IndicatesNumberOfConsumerThreads;
import io.scigraph.owlapi.loader.bindings.IndicatesNumberOfProducerThreads;
import io.scigraph.owlapi.loader.bindings.IndicatesNumberOfShutdownProducers;
import io.scigraph.owlapi.loader.bindings.IndicatesUniqueProperty;
import io.scigraph.owlapi.postprocessors.CliqueConfiguration;

public class OwlLoaderModule extends AbstractModule {

private static final Logger logger = Logger.getLogger(OwlLoaderModule.class.getName());
Expand Down Expand Up @@ -97,6 +98,8 @@ protected void configure() {
IndicatesCliqueConfiguration.class).toInstance(config.getCliqueConfiguration());
bind(new TypeLiteral<Optional<Boolean>>() {}).annotatedWith(IndicatesAddEdgeLabel.class)
.toInstance(config.getAddEdgeLabel());
bind(new TypeLiteral<Optional<String>>() {}).annotatedWith(IndicatesAllNodesLabel.class)
.toInstance(config.getAllNodesLabel());
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (C) 2014 The SciGraph authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.scigraph.owlapi.loader.bindings;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import com.google.inject.BindingAnnotation;

@BindingAnnotation @Target({ FIELD, PARAMETER, METHOD }) @Retention(RUNTIME)
public @interface IndicatesAllNodesLabel {}
6 changes: 5 additions & 1 deletion SciGraph-core/src/test/resources/pizzaExample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ graphConfiguration:
- label
- synonym
schemaIndexes:
pizza :
food :
- label
curies:
'pizza' : 'http://www.co-ode.org/ontologies/pizza/pizza.owl#'
Expand Down Expand Up @@ -56,3 +56,7 @@ mappedProperties:
- name: comment
properties:
- rdfs:comment

# To label all the nodes with a specific label.
# Useful for schema indexes.
allNodesLabel: food

0 comments on commit 02822fc

Please sign in to comment.