├── QueryEngine ├── SPARQLToGremlin │ ├── src │ │ ├── test │ │ │ └── resources │ │ │ │ └── log4j.properties │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── ibm │ │ │ └── research │ │ │ └── ergs │ │ │ └── query │ │ │ ├── translation │ │ │ ├── TransformZeroLengthTriple.java │ │ │ └── QueryData.java │ │ │ ├── metadata │ │ │ └── TriplesMetaData.java │ │ │ └── utils │ │ │ └── PropertyMapping.java │ ├── README.md │ └── pom.xml ├── SPARQLQueryEngine │ ├── README.md │ ├── src │ │ ├── test │ │ │ └── resources │ │ │ │ └── log4j.properties │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── ibm │ │ │ └── research │ │ │ └── ergs │ │ │ └── query │ │ │ └── engine │ │ │ ├── SPARQLQueryProcessor.java │ │ │ └── QueryResultSet.java │ └── pom.xml ├── QueryExpansion │ ├── src │ │ ├── com │ │ │ └── ibm │ │ │ │ └── research │ │ │ │ ├── owlql │ │ │ │ ├── ruleref │ │ │ │ │ ├── CreatableTable.java │ │ │ │ │ ├── Table.java │ │ │ │ │ ├── DatatypeFactory.java │ │ │ │ │ ├── IRDFStoreDBSchemaProcessor.java │ │ │ │ │ ├── ExistInverseDataPropertyAnnotatedPredicate.java │ │ │ │ │ ├── TriplePredicate.java │ │ │ │ │ ├── DeleteUnboundVariables.java │ │ │ │ │ └── DLAnnotatedPredicate.java │ │ │ │ ├── rule │ │ │ │ │ ├── Adornment.java │ │ │ │ │ ├── BoundVariablePredicate.java │ │ │ │ │ ├── RuleGoalNode.java │ │ │ │ │ ├── VariableExpr.java │ │ │ │ │ ├── RuleFormatter.java │ │ │ │ │ ├── RuleGoalGraph.java │ │ │ │ │ ├── ConstantExpr.java │ │ │ │ │ ├── Expr.java │ │ │ │ │ ├── PredicateAdornment.java │ │ │ │ │ ├── Predicate.java │ │ │ │ │ ├── MagicSetPredicate.java │ │ │ │ │ ├── RuleAdornment.java │ │ │ │ │ └── UniqueBindingPredicate.java │ │ │ │ ├── NewVariableGenerator.java │ │ │ │ ├── IOWLQLCompiler.java │ │ │ │ ├── ConsistencyCheckResult.java │ │ │ │ ├── SubPropertyComputation.java │ │ │ │ ├── SubClassComputation.java │ │ │ │ └── Taxonomy.java │ │ │ │ ├── utils │ │ │ │ ├── SPARQLFileParser.java │ │ │ │ └── FilterInvalidTriples.java │ │ │ │ └── rdf │ │ │ │ └── store │ │ │ │ └── sparql11 │ │ │ │ └── model │ │ │ │ └── Variable.java │ │ └── log4j.properties │ ├── README.md │ └── pom.xml ├── pom.xml └── README.md ├── .travis.yml ├── Images ├── Architecture.png └── rdf4j-repository-creation.png ├── RDF4J ├── rdf4j-server │ ├── README.md │ └── pom.xml ├── rdf4j-workbench │ ├── README.md │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── org │ │ │ │ └── eclipse │ │ │ │ └── rdf4j │ │ │ │ ├── console │ │ │ │ └── ergs-repository.ttl │ │ │ │ └── repository │ │ │ │ └── config │ │ │ │ └── ergs-repository.ttl │ │ │ └── webapp │ │ │ ├── locale │ │ │ └── ergs-messages.xsl │ │ │ └── transformations │ │ │ ├── create.xsl │ │ │ └── create-ergs-repository.xsl │ └── pom.xml ├── rdf4j-repository │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── META-INF │ │ │ │ │ └── services │ │ │ │ │ │ └── org.eclipse.rdf4j.repository.config.RepositoryFactory │ │ │ │ ├── test.properties │ │ │ │ ├── system.properties │ │ │ │ └── janusgraph-hbase-configurationgraph.properties │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── ibm │ │ │ │ └── research │ │ │ │ └── ergs │ │ │ │ └── rdf4j │ │ │ │ ├── repository │ │ │ │ └── config │ │ │ │ │ └── ExpressiveReasoningGraphStoreRepositoryFactory.java │ │ │ │ ├── query │ │ │ │ ├── ExpressiveReasoningGraphStoreBooleanQuery.java │ │ │ │ ├── ExpressiveReasoningGraphStoreGraphQuery.java │ │ │ │ ├── ExpressiveReasoningGraphStoreTupleQuery.java │ │ │ │ └── AbstractExpressiveReasoningGraphStoreQuery.java │ │ │ │ └── janusgraph │ │ │ │ └── JanusGraphConnection.java │ │ └── test │ │ │ └── resources │ │ │ └── log4j.properties │ ├── README.md │ └── pom.xml ├── pom.xml └── README.md ├── IngestionPipeline ├── GraphIngestion │ ├── README.md │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── ibm │ │ │ └── research │ │ │ └── ergs │ │ │ └── ingestion │ │ │ ├── graphdb │ │ │ ├── ConnectionMode.java │ │ │ ├── JanusGraphConnection.java │ │ │ ├── SchemaCreator.java │ │ │ ├── JanusGraphSchemaConstant.java │ │ │ └── GraphDBLoad.java │ │ │ └── loader │ │ │ ├── ConstantParameters.java │ │ │ ├── BulkLoader.java │ │ │ ├── CreateGraphFoundationSchema.java │ │ │ ├── Main.java │ │ │ └── InputParameters.java │ └── pom.xml ├── pom.xml └── README.md ├── CHANGELOG.md ├── docker ├── bulkloading │ ├── bulkload.properties │ └── load-data.sh ├── rdf4j │ └── Dockerfile └── janusgraph │ ├── gremlin-server.yaml │ └── janusgraph.properties ├── MAINTAINERS.md ├── .gitignore ├── pom.xml ├── docker-compose.yml ├── DCO1.1.txt ├── evaluation └── README.md └── CONTRIBUTING.md /QueryEngine/SPARQLToGremlin/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - openjdk8 5 | 6 | cache: 7 | directories: 8 | - "$HOME/.m2" -------------------------------------------------------------------------------- /Images/Architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/expressive-reasoning-graph-store/HEAD/Images/Architecture.png -------------------------------------------------------------------------------- /RDF4J/rdf4j-server/README.md: -------------------------------------------------------------------------------- 1 | It provides HTTP access to Expressive Reasoning Graph Store(ERGS) RDF4J repositories. 2 | -------------------------------------------------------------------------------- /QueryEngine/SPARQLQueryEngine/README.md: -------------------------------------------------------------------------------- 1 | This project is used for end-to-end execution of SPARQL queries on JanusGraph backend. 2 | -------------------------------------------------------------------------------- /Images/rdf4j-repository-creation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/expressive-reasoning-graph-store/HEAD/Images/rdf4j-repository-creation.png -------------------------------------------------------------------------------- /RDF4J/rdf4j-workbench/README.md: -------------------------------------------------------------------------------- 1 | It provides a web interface for querying, updating and exploring Expressive Reasoning Graph Store(ERGS) repositories. 2 | -------------------------------------------------------------------------------- /IngestionPipeline/GraphIngestion/README.md: -------------------------------------------------------------------------------- 1 | This module ingests RDF data into Tinkerpop complient property graph store. Currently, janusgraph is supported as property graph backend. 2 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/src/main/resources/META-INF/services/org.eclipse.rdf4j.repository.config.RepositoryFactory: -------------------------------------------------------------------------------- 1 | com.ibm.research.ergs.rdf4j.repository.config.ExpressiveReasoningGraphStoreRepositoryFactory -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | ## [Unreleased] 6 | 7 | [unreleased]: https://github.com/IBM/expressive-reasoning-graph-store 8 | -------------------------------------------------------------------------------- /QueryEngine/SPARQLToGremlin/README.md: -------------------------------------------------------------------------------- 1 | This project converts input SPARQL query into an equivalent Gremlin traversal. It also does cost model based query optimization to generate most optimal query plan for the given SPARQL query. 2 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/ruleref/CreatableTable.java: -------------------------------------------------------------------------------- 1 | package com.ibm.research.owlql.ruleref; 2 | 3 | public class CreatableTable { 4 | 5 | public CreatableTable() { 6 | // TODO Auto-generated constructor stub 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/README.md: -------------------------------------------------------------------------------- 1 | It expands the input SPARQL query as a union of multiple conjunctive queries to find some of the implicit solutions to the query. 2 | 3 | The code is extracted from another open-source project [Quetzal](https://github.com/Quetzal-RDF/quetzal). 4 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/README.md: -------------------------------------------------------------------------------- 1 | It exposes Expressive Reasoning Graph Store(ERGS) as RDFJ [Repository](https://rdf4j.org/javadoc/latest/org/eclipse/rdf4j/repository/Repository.html). This repository can be used for performing query and ingestion operations on ERGS using RDF4J standard Java APIs. 2 | -------------------------------------------------------------------------------- /docker/bulkloading/bulkload.properties: -------------------------------------------------------------------------------- 1 | input.commitfrequency=100000 2 | input.numthreads=5 3 | #input.indexprop= 4 | #input.textindexprop=http://www.w3.org/2000/01/rdf-schema#label 5 | #input.textindexprop=all 6 | #input.stringindexprop 7 | #input.textstringindexprop 8 | input.enableforwardchaining = false 9 | 10 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/src/main/resources/test.properties: -------------------------------------------------------------------------------- 1 | input.commitfrequency=100000 2 | input.numthreads=1 3 | #input.indexprop= 4 | #input.textindexprop=http://www.w3.org/2000/01/rdf-schema#label 5 | #input.textindexprop=all 6 | #input.stringindexprop 7 | #input.textstringindexprop 8 | input.enableforwardchaining = false 9 | 10 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Set root logger level to DEBUG and its only appender to A1. 2 | log4j.rootLogger=INFO, A1 3 | # A1 is set to be a ConsoleAppender. 4 | log4j.appender.A1=org.apache.log4j.ConsoleAppender 5 | # A1 uses PatternLayout. 6 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n -------------------------------------------------------------------------------- /QueryEngine/SPARQLQueryEngine/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Set root logger level to DEBUG and its only appender to A1. 2 | log4j.rootLogger=INFO, A1 3 | # A1 is set to be a ConsoleAppender. 4 | log4j.appender.A1=org.apache.log4j.ConsoleAppender 5 | # A1 uses PatternLayout. 6 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/src/main/resources/system.properties: -------------------------------------------------------------------------------- 1 | input.workingDir=src/main/resources 2 | storage.backend=cql 3 | storage.hostname=cass-docker 4 | storage.hbase.table = LUBM-u1 5 | server.hostname=janusgraph-docker 6 | server.port=8182 7 | index.search.backend=lucene 8 | index.search.solr.mode=cloud 9 | index.search.directory=/var/lib/janusgraph/index 10 | #index.search.solr.zookeeper-url=hbase-zookeeper:2181 11 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/ruleref/Table.java: -------------------------------------------------------------------------------- 1 | package com.ibm.research.owlql.ruleref; 2 | 3 | public class Table extends CreatableTable { 4 | 5 | public Table() { 6 | // TODO Auto-generated constructor stub 7 | } 8 | 9 | public Table(String string) { 10 | // TODO Auto-generated constructor stub 11 | } 12 | 13 | public void addColumn(String string, Object createInt, boolean b) { 14 | // TODO Auto-generated method stub 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/ruleref/DatatypeFactory.java: -------------------------------------------------------------------------------- 1 | package com.ibm.research.owlql.ruleref; 2 | 3 | public class DatatypeFactory { 4 | 5 | public DatatypeFactory() { 6 | // TODO Auto-generated constructor stub 7 | } 8 | 9 | public static Object createInt() { 10 | // TODO Auto-generated method stub 11 | return null; 12 | } 13 | 14 | public static Object createBigInt() { 15 | // TODO Auto-generated method stub 16 | return null; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | # MAINTAINERS 2 | 3 | Udit Sharma - udit.sharma@in.ibm.com 4 | 5 | Sumit Neelam - sumit.neelam@in.ibm.com 6 | 7 | Sumit Bhatia - sumitbhatia@in.ibm.com 8 | 9 | Hima Karanam - hkaranam@in.ibm.com 10 | 11 | Ankita Likhyani - anlikhya@in.ibm.com 12 | 13 | Shajith I Mohamed - shajmoha@in.ibm.com 14 | 15 | Santosh Srivastava - sasriva5@in.ibm.com 16 | 17 | Achille Fokoue - achille@us.ibm.com 18 | 19 | Ibrahim Abdelaziz- sasriva5@in.ibm.com 20 | 21 | L V Subramaniam - lvsubram@in.ibm.com 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Java related 2 | target/** 3 | */target/ 4 | *.jar 5 | *.war 6 | *.ear 7 | *.class 8 | 9 | # eclipse specific 10 | *.pydevproject 11 | .project 12 | **/.project 13 | .settings/ 14 | **/.settings 15 | bin 16 | **/bin 17 | .classpath 18 | **/.classpath 19 | .metadata 20 | tmp/** 21 | tmp/**/* 22 | *.tmp 23 | *.bak 24 | *.swp 25 | *~.nib 26 | local.properties 27 | 28 | .loadpath 29 | 30 | # External tool builders 31 | .externalToolBuilders/ 32 | 33 | # Locally stored "Eclipse launch configurations" 34 | *.launch 35 | 36 | *.DS_Store 37 | -------------------------------------------------------------------------------- /IngestionPipeline/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | IngestionPipeline 8 | pom 9 | 10 | com.ibm.research.reasoning 11 | ergs 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | GraphIngestion 16 | 17 | 18 | -------------------------------------------------------------------------------- /RDF4J/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | rdf4j 8 | pom 9 | 10 | com.ibm.research.reasoning 11 | ergs 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | rdf4j-repository 16 | rdf4j-server 17 | rdf4j-workbench 18 | 19 | 20 | -------------------------------------------------------------------------------- /QueryEngine/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | QueryEngine 8 | pom 9 | 10 | com.ibm.research.reasoning 11 | ergs 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | SPARQLQueryEngine 16 | SPARQLToGremlin 17 | QueryExpansion 18 | 19 | 20 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-workbench/src/main/resources/org/eclipse/rdf4j/console/ergs-repository.ttl: -------------------------------------------------------------------------------- 1 | # 2 | # Sesame configuration template for a ERGS repository 3 | # 4 | 5 | @prefix rdfs: . 6 | @prefix rep: . 7 | @prefix ergs: . 8 | @prefix xsd: . 9 | 10 | 11 | [] a rep:Repository ; 12 | rep:repositoryID "{%Repository ID|myRepository%}" ; 13 | rdfs:label "{%Repository title|Expressive Reasoning Graph Store%}" ; 14 | rep:repositoryImpl [ 15 | rep:repositoryType "ergs:ExpressiveReasoningGraphStoreRepository" ; 16 | ergs:tbox "{%tbox%}" ; 17 | ergs:config "{%config%}" ; 18 | ]. 19 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-workbench/src/main/resources/org/eclipse/rdf4j/repository/config/ergs-repository.ttl: -------------------------------------------------------------------------------- 1 | # 2 | # Sesame configuration template for a ERGS repository 3 | # 4 | 5 | @prefix rdfs: . 6 | @prefix rep: . 7 | @prefix ergs: . 8 | @prefix xsd: . 9 | 10 | 11 | [] a rep:Repository ; 12 | rep:repositoryID "{%Repository ID|myRepository%}" ; 13 | rdfs:label "{%Repository title|Expressive Reasoning Graph Store%}" ; 14 | rep:repositoryImpl [ 15 | rep:repositoryType "ergs:ExpressiveReasoningGraphStoreRepository" ; 16 | ergs:tbox "{%tbox%}" ; 17 | ergs:config "{%config%}" ; 18 | ]. 19 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-workbench/src/main/webapp/locale/ergs-messages.xsl: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | Build Summary 8 | True if you want to create ABox summary 9 | This is the name of table/graph in JanusGraph 10 | Configuration file 11 | Upload a file containing configuration properties 12 | Tbox file 13 | Upload a file containing the TBox 14 | 15 | 16 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/Adornment.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | 12 | package com.ibm.research.owlql.rule; 13 | 14 | 15 | public interface Adornment { 16 | boolean isAdornmentOnRule(); 17 | boolean isAdornmentOnPredicate(); 18 | RuleAdornment asRuleAdornment(); 19 | PredicateAdornment asPredicateAdornment(); 20 | } 21 | -------------------------------------------------------------------------------- /RDF4J/README.md: -------------------------------------------------------------------------------- 1 | This project contains submodules for exposing different [RDF4J](https://rdf4j.org) APIs. RDF4J repository interface is implemented on top of an underlying Apache Tinkerpop3 compliant Property Graph database along with all the required interfaces to support ingestion and querying of RDF data. It provides four different types of interfaces to the user. 2 | 1. **RDF4J console**: A command-line application that can be used for accessing and modifying the data. 3 | 2. **RDF4J workbench**: It provides different graphical interfaces for interacting with the underlying store using SPARQL and other endpoints. 4 | 3. **RDF4J server**: Set of REST APIs which allow the user to interact with the RDF store using HTTP protocol. 5 | 4. **HTTP repository**: It provides a proxy for remote RDF4J repository, such that users could use Java APIs to interact with the repository just like a local repository. 6 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | com.ibm.research.reasoning 8 | ergs 9 | 0.0.1-SNAPSHOT 10 | pom 11 | 12 | 0.0.1-SNAPSHOT 13 | 4.1.25.Final 14 | 0.4.0 15 | 3.6.0 16 | 1.7.10 17 | 3.3.0 18 | 4.13 19 | 5.0.3 20 | 5.0.3 21 | UTF-8 22 | 23 | 24 | 25 | IngestionPipeline 26 | QueryEngine 27 | RDF4J 28 | 29 | 30 | -------------------------------------------------------------------------------- /docker/bulkloading/load-data.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SCRIPT_PATH=`dirname "$0"` 4 | 5 | REPO_NAME=$1 6 | DATA_DIR=$2 7 | FORMAT=$3 8 | BASE_URI=$4 9 | 10 | MAPPED_DATA_DIR=$SCRIPT_PATH/data 11 | DOCKER_DATA_DIR=/usr/local/tomcat/bulkloading/data 12 | DOCKER_PROPERTIES_FILE=/usr/local/tomcat/bulkload.properties 13 | 14 | #Move the data to mapped directory 15 | mkdir -p $MAPPED_DATA_DIR 16 | chmod -R 777 $MAPPED_DATA_DIR 17 | 18 | if [[ -d $DATA_DIR ]]; then 19 | cp -pr $DATA_DIR/* $MAPPED_DATA_DIR 20 | elif [[ -f $DATA_DIR ]]; then 21 | cp -pr $DATA_DIR $MAPPED_DATA_DIR 22 | else 23 | echo "$DATA_DIR is not valid" 24 | exit 1 25 | fi 26 | 27 | #Set Heap size 28 | docker exec -it ergo_rdf4j export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m" 29 | 30 | #Ingest the data 31 | docker exec -it -w /usr/local/tomcat/IngestionPipeline/GraphIngestion ergo_rdf4j mvn exec:java -Dexec.mainClass="com.ibm.research.ergs.ingestion.loader.BulkLoader" -Dexec.args="$REPO_NAME $DOCKER_DATA_DIR $FORMAT $BASE_URI $DOCKER_PROPERTIES_FILE" -Dexec.cleanupDaemonThreads=false 32 | 33 | #delete the data from mapped directory 34 | rm -r $MAPPED_DATA_DIR/* 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/NewVariableGenerator.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql; 12 | 13 | /** 14 | * A generator of new fresh variables 15 | * @author achille 16 | * 17 | */ 18 | public class NewVariableGenerator { 19 | private String prefix; 20 | private int suffixCount; 21 | public NewVariableGenerator(String prefix) { 22 | this(prefix, 0); 23 | } 24 | public NewVariableGenerator(String prefix, int suffixCount) { 25 | super(); 26 | this.prefix = prefix; 27 | this.suffixCount = suffixCount; 28 | } 29 | 30 | public String createNewVariable(){ 31 | return prefix+(suffixCount++); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /IngestionPipeline/GraphIngestion/src/main/java/com/ibm/research/ergs/ingestion/graphdb/ConnectionMode.java: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************* 3 | * Copyright 2020 IBM Corporation and others. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | *******************************************************************************/ 15 | package com.ibm.research.ergs.ingestion.graphdb; 16 | 17 | /** 18 | * This enum is used for loading connection mode. Current loading support direct and server based 19 | * connection mode. 20 | * 21 | * @author Sumit Neelam (sumit.neelam@in.ibm.com) 22 | * 23 | */ 24 | public enum ConnectionMode { 25 | Direct, Server; 26 | } 27 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | janusgraph-docker: 4 | image: janusgraph/janusgraph:0.4.0 5 | container_name: ergo_janusgraph 6 | user: root 7 | volumes: 8 | - "./docker/janusgraph/:/etc/opt/janusgraph/:ro" 9 | - "./docker/data/index:/var/lib/janusgraph/index" 10 | ports: 11 | - "8182:8182" 12 | depends_on: 13 | - cass-docker 14 | links: 15 | - cass-docker 16 | cass-docker: 17 | image: cassandra:2.2.16 18 | container_name: ergo_cass 19 | user: root 20 | environment: 21 | - CASSANDRA_START_RPC=true 22 | volumes: 23 | - "./docker/data/cass:/var/lib/cassandra" 24 | ergo-docker: 25 | image: rdf4j:ergo 26 | container_name: ergo_rdf4j 27 | user: root 28 | build: 29 | context: . 30 | dockerfile: docker/rdf4j/Dockerfile 31 | ports: 32 | - "8080:8080" 33 | volumes: 34 | - "./docker/data/rdf4j:/root/.RDF4J/" 35 | - "./docker/bulkloading/data:/usr/local/tomcat/bulkloading/data" 36 | - "./docker/bulkloading/bulkload.properties:/usr/local/tomcat/bulkload.properties" 37 | depends_on: 38 | - cass-docker 39 | - janusgraph-docker 40 | links: 41 | - cass-docker 42 | - janusgraph-docker 43 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/ruleref/IRDFStoreDBSchemaProcessor.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.ruleref; 12 | 13 | import com.ibm.research.owlql.rule.Predicate; 14 | import com.ibm.research.owlql.rule.RuleSystem; 15 | 16 | public interface IRDFStoreDBSchemaProcessor { 17 | 18 | 19 | public void setRuleSystem(RuleSystem rs); 20 | public RuleSystem convertDLPredicateToDBTablePredicate(); 21 | 22 | /** 23 | * definition of a table with a single column and a single row. 24 | * We use that table to add in sql 25 | * query select statement that return a single constant value 26 | * (e.g select 3 from singletonTable) 27 | */ 28 | public CreatableTable getSingletonTable(); 29 | 30 | public CreatableTable getDBTable(Predicate p); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /IngestionPipeline/GraphIngestion/src/main/java/com/ibm/research/ergs/ingestion/loader/ConstantParameters.java: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************* 3 | * Copyright 2020 IBM Corporation and others. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | *******************************************************************************/ 15 | package com.ibm.research.ergs.ingestion.loader; 16 | 17 | /** 18 | * This class contains internal (external user can't see these) loading related options. 19 | * 20 | * @author Sumit Neelam (sumit.neelam@in.ibm.com) 21 | * 22 | */ 23 | public class ConstantParameters { 24 | public static boolean COLLECT_STATISTICS = true; 25 | public static boolean FULL_PREDICATE_FLAG = true; 26 | public static boolean MULTIVALUED_PROPERTY = true; 27 | } 28 | -------------------------------------------------------------------------------- /QueryEngine/SPARQLQueryEngine/src/main/java/com/ibm/research/ergs/query/engine/SPARQLQueryProcessor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2020 IBM Corporation and others. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.ibm.research.ergs.query.engine; 17 | 18 | /** 19 | * It is used for executing a SPARQL query 20 | * 21 | * @author Udit Sharma 22 | * 23 | */ 24 | public interface SPARQLQueryProcessor { 25 | /** 26 | * Executes SPARQL query 27 | * 28 | * @param queryString {@link String} containing SPARQL query 29 | * @return result of SPARQL query 30 | */ 31 | public QueryResultSet executeQuery(String queryString); 32 | } 33 | -------------------------------------------------------------------------------- /DCO1.1.txt: -------------------------------------------------------------------------------- 1 | Developer's Certificate of Origin 1.1 2 | 3 | By making a contribution to this project, I certify that: 4 | 5 | (a) The contribution was created in whole or in part by me and I 6 | have the right to submit it under the open source license 7 | indicated in the file; or 8 | 9 | (b) The contribution is based upon previous work that, to the best 10 | of my knowledge, is covered under an appropriate open source 11 | license and I have the right under that license to submit that 12 | work with modifications, whether created in whole or in part 13 | by me, under the same open source license (unless I am 14 | permitted to submit under a different license), as indicated 15 | in the file; or 16 | 17 | (c) The contribution was provided directly to me by some other 18 | person who certified (a), (b) or (c) and I have not modified 19 | it. 20 | 21 | (d) I understand and agree that this project and the contribution 22 | are public and that a record of the contribution (including all 23 | personal information I submit with it, including my sign-off) is 24 | maintained indefinitely and may be redistributed consistent with 25 | this project or the open source license(s) involved. 26 | -------------------------------------------------------------------------------- /QueryEngine/SPARQLQueryEngine/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | SPARQLQueryEngine 6 | 7 | com.ibm.research.reasoning 8 | QueryEngine 9 | 0.0.1-SNAPSHOT 10 | 11 | 12 | 13 | 14 | org.apache.maven.plugins 15 | maven-compiler-plugin 16 | 3.6.1 17 | 18 | 1.8 19 | 1.8 20 | 21 | 22 | 23 | 24 | 25 | 26 | com.ibm.research.reasoning 27 | SPARQLToGremlin 28 | 0.0.1-SNAPSHOT 29 | 30 | 31 | org.eclipse.rdf4j 32 | rdf4j-queryrender 33 | ${rdf4j.version} 34 | 35 | 36 | quetzal-RDF 37 | quetzal-RDF 38 | 0.0.1-SNAPSHOT 39 | 40 | 41 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/BoundVariablePredicate.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.rule; 12 | 13 | 14 | /** 15 | * Predicate whose first argument is a variable and the others arguments indicate the values 16 | * that this variable can take. 17 | * @author fokoue 18 | * 19 | */ 20 | public class BoundVariablePredicate extends Predicate { 21 | 22 | public BoundVariablePredicate(int arity) { 23 | super(Rule.BUILT_IN_BOUND_VAR, arity); 24 | assert arity >= 2 : arity; 25 | } 26 | 27 | public BoundVariablePredicate clone() { 28 | return new BoundVariablePredicate(getArity()); 29 | } 30 | 31 | Predicate cloneWithNonZeroArity() { 32 | return clone(); 33 | } 34 | 35 | public boolean equals(Object o) { 36 | if (o instanceof BoundVariablePredicate) { 37 | return super.equals(o); 38 | } else { 39 | return false; 40 | } 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/ruleref/ExistInverseDataPropertyAnnotatedPredicate.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.ruleref; 12 | 13 | import org.semanticweb.owlapi.model.OWLDataFactory; 14 | import org.semanticweb.owlapi.model.OWLDataProperty; 15 | 16 | public class ExistInverseDataPropertyAnnotatedPredicate extends 17 | DLAnnotatedPredicate { 18 | 19 | protected OWLDataProperty prop; 20 | protected OWLDataFactory fac; 21 | public ExistInverseDataPropertyAnnotatedPredicate( 22 | OWLDataProperty prop, OWLDataFactory fac) { 23 | super(fac.getOWLObjectSomeValuesFrom( fac.getOWLObjectProperty(prop.getIRI()).getInverseProperty().getSimplified(), fac.getOWLThing())); 24 | this.prop = prop; 25 | this.fac = fac; 26 | } 27 | 28 | public DLAnnotatedPredicate clone() { 29 | return new ExistInverseDataPropertyAnnotatedPredicate(prop, fac); 30 | } 31 | 32 | public OWLDataProperty getProperty() { 33 | return prop; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-workbench/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | rdf4j-workbench 6 | war 7 | 8 | com.ibm.research.reasoning 9 | rdf4j 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | 14 | 15 | maven-compiler-plugin 16 | 3.7.0 17 | 18 | 1.8 19 | 1.8 20 | 21 | 22 | 23 | maven-war-plugin 24 | 3.0.0 25 | 26 | src/main/webapp 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.eclipse.rdf4j 34 | rdf4j-http-workbench 35 | war 36 | ${rdf4j.version} 37 | 38 | 39 | 40 | org.eclipse.rdf4j 41 | rdf4j-config 42 | ${rdf4j.version} 43 | provided 44 | 45 | 46 | com.ibm.research.reasoning 47 | rdf4j-repository 48 | 0.0.1-SNAPSHOT 49 | 50 | 51 | -------------------------------------------------------------------------------- /QueryEngine/README.md: -------------------------------------------------------------------------------- 1 | This project contains different modules for exposing query related services. Query Engine consists of three main modules. 2 | 1. **Query Expansion**: This module expands the input SPARQL query as a union of multiple conjunctive queries to find some of the implicit solutions to the query. It uses another open-source library [Quetzal](https://github.com/Quetzal-RDF/quetzal) for query expansion that can handle any SPARQL 1.0 query and OWL-QL knowledge bases. 3 | 2. **Query Preprocessing**: SPARQL queries are declarative in nature. This implies that the user can enter the triple patterns in any order without worrying about the order in which these patterns will be used during query execution. As part of query preprocessing, we reorder the query patterns in SPARQL declarative queries such that it can be directly translated using the SPARQL-Gremlin translator. 4 | 3. **SPARQL to Gremlin Translation**: This module acts as a middle-ware between the query endpoint and the underlying property graph database such that the target system is viewed as an RDF store by the end-user. We use the meta graph constructed during the data ingestion phase to differentiate between edge traversals andproperty traversals at the time of query translation. 5 | 6 | **Limitations**: The following constructs are not supported. 7 | 1. String functions: STRLEN, SUBSTR, UCASE, LCASE, STRBEFORE, STRAFTER, ENCODE_FOR_URI,CONCAT, REPLACE. 8 | 2. Dataset Definition: FROM, FROM NAMED and GRAPH. 9 | 3. Functions on Dates and Times: NOW, YEAR, MONTH, DAY, HOURS, MINUTES, SECONDS, TIMEZONE, TZ. 10 | 4. Hash Functions: MD5, SHA1, SHA256, SHA384, SHA512. 11 | Most of these limitations are there because there are no equivalent gremlin operations for these clauses. 12 | -------------------------------------------------------------------------------- /docker/rdf4j/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tomcat:7.0.96 2 | 3 | MAINTAINER Ankita Likhyani 4 | 5 | #ENV RDF4J_VERSION="3.0.0" 6 | #ENV RDF4J_DATA="/opt/eclipse-rdf4j-${RDF4J_VERSION}/data" 7 | #ENV JVM_PARAMS="-Xmx4g" 8 | 9 | ##RUN curl -sS -o /tmp/rdf4j.zip -L http://download.eclipse.org/rdf4j/eclipse-rdf4j-${RDF4J_VERSION}-sdk.zip && \ 10 | # cd /opt && \ 11 | # unzip /tmp/rdf4j.zip && \ 12 | # rm /tmp/rdf4j.zip 13 | 14 | #RUN mv /opt/eclipse-rdf4j-${RDF4J_VERSION}/war/*.war /usr/local/tomcat/webapps 15 | 16 | #RUN echo "CATALINA_OPTS=\"\$CATALINA_OPTS \$JVM_PARAMS -Dorg.eclipse.rdf4j.appdata.basedir=\$RDF4J_DATA\"" >> /usr/local/tomcat/bin/setenv.sh 17 | 18 | #VOLUME ${RDF4J_DATA} 19 | 20 | COPY . /usr/local/tomcat/ 21 | 22 | ARG MAVEN_VERSION=3.6.3 23 | 24 | ARG USER_HOME_DIR="/root" 25 | 26 | RUN mkdir -p /usr/share/maven && \ 27 | curl -fsSL http://apache.osuosl.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz | tar -xzC /usr/share/maven --strip-components=1 && \ 28 | ln -s /usr/share/maven/bin/mvn /usr/bin/mvn 29 | 30 | ENV MAVEN_HOME /usr/share/maven 31 | 32 | ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2" 33 | 34 | ENV MAVEN_OPTS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1" 35 | 36 | #RUN apt-get update && apt-get -y install openjdk-8-jdk && cp -rp /usr/lib/jvm/java-8-openjdk-amd64/lib/tools.jar /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/tools.jar 37 | RUN mvn clean install -Dmaven.test.skip=true 38 | #&& mvn package -Dmaven.test.skip=true 39 | 40 | RUN cp -pr /usr/local/tomcat/RDF4J/rdf4j-workbench/target/rdf4j-workbench-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/rdf4j-workbench.war 41 | 42 | RUN cp -rp /usr/local/tomcat/RDF4J/rdf4j-server/target/rdf4j-server-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/rdf4j-server.war 43 | EXPOSE 8080 44 | -------------------------------------------------------------------------------- /IngestionPipeline/README.md: -------------------------------------------------------------------------------- 1 | Ingestion Module is responsible for storing RDF data into property graph format. It implements the core RDF4J repository APIs that enable handling and ingesting the input data through various RDF4J supported input mechanisms. Currently, JanusGraph is used as property graph backend for data storage. Specifically, ingestion module offers following features: 2 | 3 | #### Schema Translation and loading: 4 | Schema translation is responsible for transforming input triple data into the property graph model. It builds schema of property graph which decides nodes structure, edges and their properties and translates triple appropriately to node property or edge during loading. 5 | 6 | #### Metadata for Supporting Query Translation: 7 | For supporting execution of SPARQL queries on property graph, metadata is stored as sub-graph which provides schema translation related information to Query Translation module 8 | 9 | #### Parallel Ingestion and Index Utilization: 10 | For making loading process faster we have developed parallel approach by dividing loading task across threads. 11 | 12 | We make use of the different indexing mechanisms provided by Janus Graph for faster query execution. It enables to reduce query execution 13 | time and to execute complex text keyword based queries. 14 | 15 | #### Forward Chaining enabled Ingestion: 16 | For executing reasoning queries more efficiently current ingestion pipeline supports enabling forward chaining during data ingestion. Currently, we support RDFS reasoning and few OWL constructs which includes *owl:inverseOf, owl:symmetric, owl:TransitiveProperty*. Currently, we do not have full support for forward chaining in parallel loading, e.g., we do not support parallel ingestion for forward chaining for *owl:TransitiveProperty*. In future, we will add this feature with other OWL axioms. 17 | -------------------------------------------------------------------------------- /IngestionPipeline/GraphIngestion/src/main/java/com/ibm/research/ergs/ingestion/graphdb/JanusGraphConnection.java: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************* 3 | * Copyright 2020 IBM Corporation and others. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | *******************************************************************************/ 15 | package com.ibm.research.ergs.ingestion.graphdb; 16 | 17 | import java.io.InputStream; 18 | 19 | /** 20 | * interface of JanusGraoh connection. 21 | * 22 | * @author Sumit Neelam (sumit.neelam@in.ibm.com) 23 | * 24 | */ 25 | public interface JanusGraphConnection { 26 | 27 | /** 28 | * This function creates required graph for storing ontology data. 29 | */ 30 | public void createOntologyBaseGraph(InputStream tboxStream); 31 | 32 | /** 33 | * returns schema creator class object for creating new properties and edges schema 34 | * 35 | * @return 36 | */ 37 | public SchemaCreator getSchemaCreator(); 38 | 39 | /** 40 | * returns laoder class object 41 | * 42 | * @return 43 | */ 44 | public GraphDBLoad getLoader(); 45 | 46 | /** 47 | * It builds combined index on all graph properties for text queries 48 | * 49 | * @param indexName 50 | */ 51 | public void buildAllPropertyExternalIndex(String indexName); 52 | } 53 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/RuleGoalNode.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.rule; 12 | 13 | import java.util.List; 14 | 15 | public class RuleGoalNode { 16 | 17 | private Adornment adornment; 18 | private List children; 19 | 20 | RuleGoalNode(Adornment adornment, List children) { 21 | super(); 22 | this.adornment = adornment; 23 | this.children = children; 24 | } 25 | public Adornment getAdornment() { 26 | return adornment; 27 | } 28 | public void setAdornment(Adornment adornment) { 29 | this.adornment = adornment; 30 | } 31 | public List getChildren() { 32 | return children; 33 | } 34 | public boolean equals(Object o) { 35 | if (o==this) { 36 | return true; 37 | } 38 | if (o instanceof RuleGoalNode) { 39 | RuleGoalNode other =(RuleGoalNode)o; 40 | return adornment.equals(other.adornment) 41 | && children.equals(other.children); 42 | } 43 | return false; 44 | } 45 | 46 | public int hashCode() { 47 | return adornment.hashCode()+ 31*children.hashCode(); 48 | } 49 | 50 | public boolean isGoal() { 51 | return adornment.isAdornmentOnPredicate(); 52 | } 53 | 54 | public boolean isRule() { 55 | return adornment.isAdornmentOnRule(); 56 | } 57 | 58 | public void addChild(RuleGoalNode node) { 59 | children.add(node); 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/IOWLQLCompiler.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql; 12 | 13 | import java.util.Set; 14 | 15 | import org.apache.jena.query.Query; 16 | 17 | import com.ibm.research.owlql.rule.RuleSystem; 18 | 19 | public interface IOWLQLCompiler { 20 | 21 | public abstract NormalizedOWLQLTbox getTBox(); 22 | 23 | 24 | /** 25 | * performs query reformulation 26 | * @param q 27 | * @return 28 | */ 29 | public Set compile(ConjunctiveQuery q); 30 | 31 | /** 32 | * performs query reformulation 33 | * @param q 34 | * @return 35 | */ 36 | public String compileToSQL(ConjunctiveQuery q, boolean returnIDs); 37 | 38 | public Query compileToUnionQuery(ConjunctiveQuery q); 39 | 40 | public RuleSystem compileToRules(ConjunctiveQuery q); 41 | 42 | public boolean canCompileToSPARQL(); 43 | 44 | public boolean canCompileToSQL(boolean returnIDs); 45 | 46 | public boolean canCompileToRules(); 47 | 48 | /** 49 | * returns whether the compiler can produce a non-flattened union query. 50 | * If true is returned, then {@link #compileToUnionQuery(ConjunctiveQuery)} will return 51 | * a non-null value. 52 | * @return 53 | */ 54 | public boolean canCompileToUnionSPARQL(); 55 | 56 | /** 57 | * 58 | * @return 59 | */ 60 | public ConsistencyCheckResult computeConsistencyCheck(); 61 | } 62 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/VariableExpr.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.rule; 12 | 13 | 14 | /** 15 | * a variable 16 | * @author Achille Fokoue 17 | * 18 | */ 19 | public class VariableExpr extends Expr{ 20 | 21 | 22 | private String varName; 23 | 24 | public VariableExpr(String varName) { 25 | super(); 26 | this.varName = varName; 27 | } 28 | 29 | @Override 30 | public boolean isConstant() { 31 | return false; 32 | } 33 | @Override 34 | public boolean isVariable() { 35 | return true; 36 | } 37 | public String getName() { 38 | return varName; 39 | } 40 | 41 | public void setName(String varName) { 42 | this.varName = varName; 43 | } 44 | 45 | @Override 46 | public ConstantExpr asConstant() { 47 | return null; 48 | } 49 | 50 | @Override 51 | public VariableExpr asVariable() { 52 | return this; 53 | } 54 | 55 | public boolean equals(Object o) { 56 | if (o==this) { 57 | return true; 58 | } 59 | if (o instanceof VariableExpr) { 60 | return varName.equals(((VariableExpr)o).getName()); 61 | } 62 | return false; 63 | } 64 | 65 | public int hashCode() { 66 | return varName.hashCode(); 67 | } 68 | 69 | public String toString() { 70 | return varName; 71 | } 72 | 73 | @Override 74 | public VariableExpr clone() { 75 | return new VariableExpr(varName); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/utils/SPARQLFileParser.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.utils; 12 | 13 | import java.io.BufferedReader; 14 | import java.io.IOException; 15 | import java.io.Reader; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | import java.util.StringTokenizer; 19 | 20 | 21 | 22 | /** 23 | * Utitlies methods to read a file or an inputstream consisting of semicolon separated SPARQL queries. 24 | * @author achille 25 | * 26 | */ 27 | public class SPARQLFileParser { 28 | 29 | /** 30 | * reads an input stream consisting of semicolon separated SPARQL queries, and returns the list of SPARQL 31 | * queries as strings. 32 | * @param ins 33 | * @return 34 | * @throws IOException 35 | */ 36 | public static String[] readQueries(Reader ins) throws IOException { 37 | 38 | BufferedReader in = new BufferedReader(ins); 39 | StringBuffer buf = new StringBuffer(); 40 | String line = null; 41 | while ((line=in.readLine())!=null) { 42 | if (!line.startsWith("#")) { 43 | buf.append(line+"\n"); 44 | } 45 | } 46 | StringTokenizer t = new StringTokenizer(buf.toString(),";"); 47 | List ret = new ArrayList(); 48 | while (t.hasMoreTokens()) { 49 | String query = t.nextToken().trim(); 50 | if (!"".equals(query)) { 51 | ret.add(query); 52 | } 53 | } 54 | return ret.toArray(new String[ret.size()]); 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/rdf/store/sparql11/model/Variable.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.rdf.store.sparql11.model; 12 | 13 | /** 14 | * models a variable 15 | */ 16 | public class Variable { 17 | private boolean isSystemVariable; 18 | private String name; 19 | 20 | public Variable(String name) { 21 | this.name = name; 22 | this.isSystemVariable = false; 23 | } 24 | 25 | public Variable(String name, boolean isSystemVariable) { 26 | assert ! name.contains(":"); 27 | this.name = name; 28 | this.isSystemVariable = isSystemVariable; 29 | } 30 | 31 | public boolean isSystemVariable() 32 | { 33 | return isSystemVariable; 34 | } 35 | 36 | public String getName() { return name; } 37 | 38 | public String toString() { return "?" + name; } 39 | 40 | @Override 41 | public int hashCode() { 42 | final int prime = 31; 43 | int result = 1; 44 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 45 | return result; 46 | } 47 | 48 | @Override 49 | public boolean equals(Object obj) { 50 | if (this == obj) 51 | return true; 52 | if (obj == null) 53 | return false; 54 | if (getClass() != obj.getClass()) 55 | return false; 56 | Variable other = (Variable) obj; 57 | if (name == null) { 58 | if (other.name != null) 59 | return false; 60 | } else if (!name.equals(other.name)) 61 | return false; 62 | return true; 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /QueryEngine/SPARQLQueryEngine/src/main/java/com/ibm/research/ergs/query/engine/QueryResultSet.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2020 IBM Corporation and others. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.ibm.research.ergs.query.engine; 17 | 18 | import java.util.Set; 19 | import java.util.stream.Stream; 20 | 21 | /** 22 | * This class is responsible for maintaining the result set of the query 23 | * 24 | * @author Udit Sharma 25 | * 26 | */ 27 | public class QueryResultSet { 28 | private Stream resultStream; 29 | private Set queryVariables; 30 | 31 | /** 32 | * Constructs {@link QueryResultSet} 33 | * 34 | * @param resultStream {@link Stream} containing result for the query 35 | * @param queryVariables {@link Set} of variables in query 36 | */ 37 | public QueryResultSet(Stream resultStream, Set queryVariables) { 38 | this.resultStream = resultStream; 39 | this.queryVariables = queryVariables; 40 | } 41 | 42 | /** 43 | * 44 | * @return query result stream 45 | */ 46 | public Stream getResultStream() { 47 | return resultStream; 48 | } 49 | 50 | /** 51 | * 52 | * @return {@link Set} of variables in query 53 | */ 54 | public Set getQueryVariables() { 55 | return queryVariables; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/src/main/java/com/ibm/research/ergs/rdf4j/repository/config/ExpressiveReasoningGraphStoreRepositoryFactory.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2020 IBM Corporation and others. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.ibm.research.ergs.rdf4j.repository.config; 17 | 18 | import org.eclipse.rdf4j.repository.Repository; 19 | import org.eclipse.rdf4j.repository.config.RepositoryConfigException; 20 | import org.eclipse.rdf4j.repository.config.RepositoryFactory; 21 | import org.eclipse.rdf4j.repository.config.RepositoryImplConfig; 22 | 23 | /** 24 | * {@link RepositoryFactory} for ERGS 25 | * 26 | * @author Udit Sharma 27 | * 28 | */ 29 | public class ExpressiveReasoningGraphStoreRepositoryFactory implements RepositoryFactory { 30 | 31 | public static final String REPOSITORY_TYPE = "ergs:ExpressiveReasoningGraphStoreRepository"; 32 | 33 | @Override 34 | public String getRepositoryType() { 35 | return REPOSITORY_TYPE; 36 | } 37 | 38 | @Override 39 | public ExpressiveReasoningGraphStoreRepositoryConfig getConfig() { 40 | return new ExpressiveReasoningGraphStoreRepositoryConfig(); 41 | } 42 | 43 | @Override 44 | public Repository getRepository(RepositoryImplConfig config) throws RepositoryConfigException { 45 | return ((ExpressiveReasoningGraphStoreRepositoryConfig) config).buildRepository(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/RuleFormatter.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.rule; 12 | 13 | import java.util.Arrays; 14 | import java.util.List; 15 | 16 | public class RuleFormatter { 17 | 18 | public static final String formatRule( String head, String... subgoals ) { 19 | return formatRule( head, Arrays.asList( subgoals ) ); 20 | } 21 | public static final String formatRule( String head, List subgoals ) { 22 | return formatRule(head, subgoals, true); 23 | } 24 | public static final String formatRule( String head, List subgoals, boolean forRuleSystemParsing) { 25 | if (subgoals.size() == 0) return head + (forRuleSystemParsing ? ";" : ""); 26 | String rule = head + " :- " + subgoals.get(0); 27 | for(String g : subgoals.subList( 1, subgoals.size() )) 28 | rule += " ^ " + g; 29 | return rule + (forRuleSystemParsing ? ";" : ""); 30 | } 31 | public static final String formatAtomicFormula( String pred, String ... args ) { 32 | return formatAtomicFormula(pred, Arrays.asList( args )); 33 | } 34 | public static final String formatAtomicFormula( String pred, List args ) { 35 | return pred + formatArgs(args); 36 | } 37 | 38 | public static final String formatArgs(String ... vars) { return formatArgs(Arrays.asList( vars )); } 39 | public static final String formatArgs(List vars) { 40 | if (vars.size() == 0) return "()"; 41 | String s = "(" + vars.get(0); 42 | for (String var : vars.subList( 1, vars.size() )) s += "," + var; 43 | return s + ")"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/RuleGoalGraph.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.rule; 12 | 13 | import java.util.Collections; 14 | import java.util.HashMap; 15 | import java.util.HashSet; 16 | import java.util.LinkedList; 17 | import java.util.Map; 18 | import java.util.Set; 19 | 20 | public class RuleGoalGraph { 21 | 22 | 23 | 24 | 25 | private Map adorn2Node; 26 | private Set ruleNodes; 27 | private Set goalNodes; 28 | private RuleGoalNode topGoal; 29 | 30 | public RuleGoalGraph(PredicateAdornment goal) { 31 | adorn2Node = new HashMap(); 32 | ruleNodes = new HashSet(); 33 | goalNodes = new HashSet(); 34 | topGoal = add(goal); 35 | } 36 | 37 | public RuleGoalNode get(Adornment ad) { 38 | RuleGoalNode ret = adorn2Node.get(ad); 39 | return ret; 40 | } 41 | public RuleGoalNode add(Adornment ad) { 42 | RuleGoalNode ret = adorn2Node.get(ad); 43 | if (ret==null) { 44 | ret= new RuleGoalNode(ad, new LinkedList()); 45 | adorn2Node.put(ad,ret); 46 | if (ret.isGoal()) { 47 | goalNodes.add(ret); 48 | } else { 49 | assert ret.isRule(); 50 | ruleNodes.add(ret); 51 | } 52 | } 53 | return ret; 54 | } 55 | public RuleGoalNode getTopGoalNode() { 56 | return topGoal; 57 | } 58 | 59 | public Set getGoalNodes() { 60 | return Collections.unmodifiableSet(goalNodes); 61 | } 62 | 63 | public Set getRuleNodes() { 64 | return Collections.unmodifiableSet(ruleNodes); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/ruleref/TriplePredicate.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.ruleref; 12 | 13 | import java.util.HashSet; 14 | import java.util.Set; 15 | 16 | import com.ibm.research.owlql.rule.AtomicFormula; 17 | import com.ibm.research.owlql.rule.Expr; 18 | import com.ibm.research.owlql.rule.Predicate; 19 | import com.ibm.research.owlql.rule.Rule; 20 | import com.ibm.research.owlql.rule.VariableExpr; 21 | /** 22 | * A predicate representing a rdf triple 23 | * @author fokoue 24 | * 25 | */ 26 | public class TriplePredicate extends Predicate { 27 | 28 | public static final String TRIPLE_PREDICATE = "triple"; 29 | public static Set getPredicateVariables(Rule r) { 30 | Set ret = new HashSet(); 31 | for (AtomicFormula af: r.getBody()) { 32 | if (af.getPredicate() instanceof TriplePredicate) { 33 | assert af.getPredicate().getArity() == 3; 34 | Expr e; 35 | if ((e=af.getArguments().get(1)).isVariable()) { 36 | ret.add((VariableExpr)e); 37 | } 38 | } 39 | } 40 | if (r.getHead().getPredicate() instanceof TriplePredicate) { 41 | assert r.getHead().getPredicate().getArity() == 3; 42 | Expr e; 43 | if ((e= r.getHead().getArguments().get(1)).isVariable()) { 44 | ret.add((VariableExpr)e); 45 | } 46 | } 47 | return ret; 48 | } 49 | 50 | 51 | 52 | public TriplePredicate() { 53 | super(TRIPLE_PREDICATE, 3); 54 | } 55 | 56 | @Override 57 | public Predicate clone() { 58 | return super.clone(); 59 | } 60 | 61 | Predicate cloneWithNonZeroArity() { 62 | return clone(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-server/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | rdf4j-server 6 | war 7 | 8 | com.ibm.research.reasoning 9 | rdf4j 10 | 0.0.1-SNAPSHOT 11 | 12 | 13 | 14 | 15 | maven-compiler-plugin 16 | 3.7.0 17 | 18 | 1.8 19 | 1.8 20 | 21 | 22 | 23 | maven-war-plugin 24 | 3.0.0 25 | 26 | src/main/webapp 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.eclipse.rdf4j 35 | rdf4j-http-server 36 | war 37 | ${rdf4j.version} 38 | 39 | 40 | com.ibm.research.reasoning 41 | rdf4j-repository 42 | 0.0.1-SNAPSHOT 43 | 44 | 45 | xerces 46 | xercesImpl 47 | 2.12.0 48 | 49 | 50 | org.eclipse.rdf4j 51 | rdf4j-console 52 | ${rdf4j.version} 53 | 54 | 55 | 56 | org.eclipse.rdf4j 57 | rdf4j-http-server-spring 58 | ${rdf4j.version} 59 | 60 | 61 | org.eclipse.rdf4j 62 | rdf4j-tools 63 | ${rdf4j.version} 64 | pom 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/utils/FilterInvalidTriples.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.utils; 12 | 13 | import java.io.FileNotFoundException; 14 | import java.io.FileOutputStream; 15 | import java.io.IOException; 16 | import java.net.MalformedURLException; 17 | import java.net.URL; 18 | import java.util.Iterator; 19 | 20 | import org.apache.jena.graph.Triple; 21 | import org.apache.jena.riot.Lang; 22 | import org.apache.jena.riot.RDFDataMgr; 23 | import org.apache.jena.riot.system.Checker; 24 | import org.apache.jena.riot.writer.NTriplesWriter; 25 | 26 | import com.ibm.wala.util.Predicate; 27 | import com.ibm.wala.util.collections.FilterIterator; 28 | 29 | public class FilterInvalidTriples { 30 | 31 | private static Iterator filterTriples(URL url, String baseURI, 32 | Lang lang) throws MalformedURLException, IOException { 33 | Iterator ts = RDFDataMgr.createIteratorTriples( 34 | url.openStream(), lang, baseURI); 35 | return new FilterIterator(ts, new Predicate() { 36 | private int i = 0; 37 | private final Checker checker = new Checker(); 38 | 39 | @Override 40 | public boolean test(Triple t) { 41 | return !t.getObject().isLiteral() || checker.checkLiteral(t.getObject(), i++, 0); 42 | } 43 | 44 | }); 45 | } 46 | 47 | public static void filterDataFile(String dataFile, URL uri, 48 | FileOutputStream riotOut, Lang language) 49 | throws MalformedURLException, IOException { 50 | Iterator ts = filterTriples(uri, dataFile, language); 51 | NTriplesWriter.write(riotOut, ts); 52 | } 53 | 54 | public static void main(String[] args) throws FileNotFoundException, 55 | IOException { 56 | String fileName = args[0]; 57 | URL baseURI = new URL(args[1]); 58 | filterDataFile(fileName, baseURI, new FileOutputStream(fileName + "_filter.nt"), Lang.NT); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/src/main/java/com/ibm/research/ergs/rdf4j/query/ExpressiveReasoningGraphStoreBooleanQuery.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2020 IBM Corporation and others. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.ibm.research.ergs.rdf4j.query; 17 | 18 | import org.eclipse.rdf4j.query.BooleanQuery; 19 | import org.eclipse.rdf4j.query.QueryEvaluationException; 20 | import com.ibm.research.ergs.query.engine.QueryResultSet; 21 | import com.ibm.research.ergs.query.engine.SPARQLQueryProcessor; 22 | 23 | /** 24 | * SPARQL ASK query for ERGS repository 25 | * 26 | * @author Udit Sharma 27 | * 28 | */ 29 | public class ExpressiveReasoningGraphStoreBooleanQuery extends AbstractExpressiveReasoningGraphStoreQuery implements BooleanQuery { 30 | 31 | /** 32 | * It constructs SPARQL ASK query for ERGS repository 33 | * 34 | * @param queryProcessor query execution engine 35 | * @param queryString query string 36 | * @param baseIRI base IRI for the query 37 | */ 38 | public ExpressiveReasoningGraphStoreBooleanQuery(SPARQLQueryProcessor queryProcessor, String queryString, 39 | String baseIRI) { 40 | super(queryProcessor, queryString, baseIRI); 41 | } 42 | 43 | @Override 44 | public void setMaxExecutionTime(int maxExecTime) { 45 | throw new UnsupportedOperationException("not implemented"); 46 | } 47 | 48 | @Override 49 | public int getMaxExecutionTime() { 50 | throw new UnsupportedOperationException("not implemented"); 51 | } 52 | 53 | @Override 54 | public boolean evaluate() throws QueryEvaluationException { 55 | QueryResultSet result = queryProcessor.executeQuery(queryString); 56 | Iterable it = 57 | (Iterable) result.getResultStream().map(Object::toString)::iterator; 58 | return it.iterator().hasNext(); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/src/main/java/com/ibm/research/ergs/rdf4j/janusgraph/JanusGraphConnection.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2020 IBM Corporation and others. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.ibm.research.ergs.rdf4j.janusgraph; 17 | 18 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 19 | 20 | import com.ibm.research.ergs.ingestion.loader.LoadRDFData; 21 | import com.ibm.research.ergs.query.engine.SPARQLQueryProcessor; 22 | 23 | /** 24 | * It is used for performing operations on the graph connection 25 | * 26 | * @author Udit Sharma 27 | * 28 | */ 29 | public interface JanusGraphConnection { 30 | 31 | /** 32 | * It initializes the connection 33 | */ 34 | public void initialize(); 35 | 36 | /** 37 | * It return traversal object for the graph connection 38 | * 39 | * @return graph traversal source 40 | */ 41 | public GraphTraversalSource getTraversalSource(); 42 | 43 | /** 44 | * It returns the graph/table name used by the graph connection 45 | * 46 | * @return graph name 47 | */ 48 | public String getTableName(); 49 | 50 | /** 51 | * It checks whether the connection is initialized or not 52 | * 53 | * @return flag containing initialization status 54 | */ 55 | public boolean isInitialized(); 56 | 57 | /** 58 | * It closes the connection 59 | */ 60 | public void close(); 61 | 62 | /** 63 | * It deletes the graph/table associated with graph connection 64 | */ 65 | public void deleteGraph(); 66 | 67 | /** 68 | * It returns query processor for executing SPARQL queries 69 | * 70 | * @return SPARQLQueryProcessor object 71 | */ 72 | public SPARQLQueryProcessor getSPARQLQueryProcessor(); 73 | 74 | /** 75 | * It returns RDFF loader for loading RDF data 76 | * 77 | * @return LoadRDFData object 78 | */ 79 | public LoadRDFData getRDFLoader(); 80 | 81 | } 82 | -------------------------------------------------------------------------------- /IngestionPipeline/GraphIngestion/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | GraphIngestion 6 | GraphReasoning 7 | GraphReasoning 8 | 9 | com.ibm.research.reasoning 10 | IngestionPipeline 11 | 0.0.1-SNAPSHOT 12 | 13 | 14 | 15 | 16 | org.apache.maven.plugins 17 | maven-compiler-plugin 18 | 3.6.1 19 | 20 | 1.8 21 | 1.8 22 | 23 | 24 | 25 | 26 | 27 | 32 | 33 | org.slf4j 34 | slf4j-api 35 | ${slf4j.version} 36 | 37 | 38 | org.slf4j 39 | slf4j-simple 40 | ${slf4j.version} 41 | 42 | 43 | org.janusgraph 44 | janusgraph-all 45 | ${janusgraph.version} 46 | 47 | 48 | io.netty 49 | netty-all 50 | ${netty4.version} 51 | 52 | 53 | org.eclipse.rdf4j 54 | rdf4j-rio-rdfxml 55 | ${rdf4j.version} 56 | 57 | 58 | org.eclipse.rdf4j 59 | rdf4j-rio-turtle 60 | ${rdf4j.version} 61 | 62 | 63 | net.sourceforge.owlapi 64 | jfact 65 | ${jfact.version} 66 | 67 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/ConsistencyCheckResult.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql; 12 | 13 | import org.apache.jena.query.Query; 14 | 15 | /** 16 | * result of a consistency check performed based on a QL Tbox only. 17 | * The result is one of the following: 18 | *
    19 | *
  • consis
  • 20 | *
21 | * @author fokoue 22 | * 23 | */ 24 | public class ConsistencyCheckResult { 25 | 26 | private Boolean consistent; 27 | private Query inconsistencyDetectionAskQuery; 28 | 29 | ConsistencyCheckResult(boolean consistent) { 30 | this.consistent = consistent; 31 | inconsistencyDetectionAskQuery = null; 32 | } 33 | ConsistencyCheckResult(Boolean consistent, 34 | Query inconsistencyDetectionAskQuery) { 35 | super(); 36 | this.consistent = consistent; 37 | this.inconsistencyDetectionAskQuery = inconsistencyDetectionAskQuery; 38 | assert consistent != null || inconsistencyDetectionAskQuery !=null; 39 | } 40 | 41 | /** 42 | * returns the result of the consistency check based only of a QL Tbox analysis. 43 | * It returns one of the following three values: 44 | *
    45 | *
  • {@link Boolean#TRUE} to indicate that an Abox cannot be inconsistent based on the analyzed QL Tbox
  • 46 | *
  • {@link Boolean#FALSE} to indicate that the analyzed Tbox is inconsistent (regardless of the consisdered Abox)
  • 47 | *
  • null to indicate that the consistency status depends of the content of the Abox. In this case, 48 | * the method {@link #getInconsistencyDetectionAskQuery()} will return the ask query that needs to be evaluated against an Abox to 49 | * ascertain its inconsistency * 50 | *
  • 51 | * Tbox; 52 | * @return 53 | */ 54 | public Boolean isConsistent() { 55 | return consistent; 56 | } 57 | 58 | /** 59 | * returns an ask query that should be evaluated against a Abox to determine whether is inconsistent. 60 | * The evaluation of the returned query against an Abox A yields true iff. A is inconsistent. 61 | * @return 62 | */ 63 | public Query getInconsistencyDetectionAskQuery() { 64 | return inconsistencyDetectionAskQuery; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/log4j.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # for production, you should probably set the root to INFO 18 | # and the pattern to %c instead of %l. (%l is slower.) 19 | 20 | # output messages into a rolling log file as well as stdout 21 | log4j.rootLogger=OFF,stdout 22 | 23 | # stdout 24 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 25 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 26 | log4j.appender.stdout.layout.ConversionPattern=%5p %d{ISO8601} (%F:%L) %m%n 27 | 28 | # stdout 29 | #log4j.appender.stdout=org.apache.log4j.ConsoleAppender 30 | #log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 31 | #log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p <%t> [%c{1}] %m %n 32 | 33 | # rolling log file for Helix 34 | log4j.appender.R2=org.apache.log4j.RollingFileAppender 35 | log4j.appender.R2.maxFileSize=6MB 36 | log4j.appender.R2.maxBackupIndex=1 37 | log4j.appender.R2.layout=org.apache.log4j.PatternLayout 38 | log4j.appender.R2.layout.ConversionPattern=%5p %d{ISO8601} %m [%t -- %C (line %L)] %n 39 | # Edit the next line to point to your logs directory 40 | log4j.appender.R2.File=/tmp/DB2_RDF.log 41 | #log4j.logger.com.ibm.rdf.store.sparql11.stopt.LPPlanner=DEBUG,R2 42 | #log4j.logger.com.ibm.rdf.store.sparql11.stopt.lpplanner=INFO,R2 43 | #log4j.logger.com.ibm.rdf.store.sparql11.stopt.lpplanner.AndPatternInternalComponentView=ERROR,R2 44 | log4j.logger.com.ibm.rdf.store.sparql11.QueryProcessorImpl=DEBUG,R2 45 | log4j.logger.com.ibm.rdf.store.sparql11.DB2JazzQueryUtilityTest=INFO,R2 46 | # Helix classes to logger at a different level from DEBUG 47 | #log4j.logger.com.ibm.research.helix.rdb.RdbQueryProcessor=TRACE 48 | 49 | # Application logging options 50 | # We don't need to see DEBUG messages from Jena, HttpClient, or RDFParserRegistry 51 | log4j.logger.org.openrdf=WARN 52 | # Turn off all the annoying warnings about "String not in Unicode Normal Form" 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /QueryEngine/SPARQLToGremlin/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | SPARQLToGremlin 6 | 7 | com.ibm.research.reasoning 8 | QueryEngine 9 | 0.0.1-SNAPSHOT 10 | 11 | 12 | 13 | 14 | org.apache.maven.plugins 15 | maven-compiler-plugin 16 | 3.6.1 17 | 18 | 1.8 19 | 1.8 20 | 21 | 22 | 23 | 24 | 25 | 26 | io.netty 27 | netty-all 28 | ${netty4.version} 29 | 30 | 31 | org.slf4j 32 | slf4j-api 33 | ${slf4j.version} 34 | 35 | 36 | 37 | org.slf4j 38 | slf4j-simple 39 | ${slf4j.version} 40 | 41 | 42 | org.slf4j 43 | slf4j-log4j12 44 | ${slf4j.version} 45 | 46 | 47 | org.janusgraph 48 | janusgraph-all 49 | ${janusgraph.version} 50 | 51 | 52 | org.eclipse.rdf4j 53 | rdf4j-model 54 | ${rdf4j.version} 55 | 56 | 57 | org.eclipse.rdf4j 58 | rdf4j-queryparser-api 59 | ${rdf4j.version} 60 | 61 | 62 | org.eclipse.rdf4j 63 | rdf4j-queryparser-sparql 64 | ${rdf4j.version} 65 | 66 | 67 | org.eclipse.rdf4j 68 | rdf4j-rio-rdfxml 69 | ${rdf4j.version} 70 | 71 | 72 | org.eclipse.rdf4j 73 | rdf4j-repository-sparql 74 | ${rdf4j.version} 75 | 76 | 77 | org.eclipse.rdf4j 78 | rdf4j-rio-turtle 79 | ${rdf4j.version} 80 | 81 | 82 | -------------------------------------------------------------------------------- /evaluation/README.md: -------------------------------------------------------------------------------- 1 | This Readme contains instructions and step to reproduce experiments number. Here we have explained steps for getting LUBM 1000 university dataset, similar steps can be followed for getting experiments number for other datasets also. 2 | ### Machine Configuration: 3 | Experiments are performed on RHEL machine with 128 GB RAM, 16 cores and 1TB HDD. 4 | 5 | ### Steps: 6 | 1. Download LUBM data generator from http://swat.cse.lehigh.edu/projects/lubm/uba1.7.zip and generate 1000 university data. 7 | 2. Setup ERGS system using mavan build as provided in main [README](https://github.com/IBM/expressive-reasoning-graph-store/blob/master/README.md) file and create new ERGS repository 8 | 3. Modify [BulkLoader.java](https://github.com/IBM/expressive-reasoning-graph-store/blob/master/IngestionPipeline/GraphIngestion/src/main/java/com/ibm/research/ergs/ingestion/loader/BulkLoader.java) on [Line 74 and 75](https://github.com/IBM/expressive-reasoning-graph-store/blob/eee973c353cd05de842c376a0dda95dcc2396f76/IngestionPipeline/GraphIngestion/src/main/java/com/ibm/research/ergs/ingestion/loader/BulkLoader.java#L74) with appropriate storage backend parameters: 9 | ``` 10 | configuration.addProperty("storage.backend", "hbase"); 11 | configuration.addProperty("storage.hostname", "127.0.0.1"); 12 | 13 | for hbase backend 14 | ``` 15 | ``` 16 | configuration.addProperty("storage.backend", "cql"); 17 | configuration.addProperty("storage.hostname", "127.0.0.1"); 18 | 19 | for cassandra backend 20 | ``` 21 | 22 | 4. Load RDF data into JanusGraph with modified BulkLoader.java with following arguments: 23 | ``` 24 | 25 | ``` 26 | Where: 27 | * repository_id: `` 28 | * dataset_directory: `` 29 | * dataset_format: "rdf" 30 | * base_uri: "http://swat.cse.lehigh.edu/onto/univ-bench.owl" 31 | * properties_file: [docker/bulkloading/bulkload.properties](https://github.com/IBM/expressive-reasoning-graph-store/blob/master/docker/bulkloading/bulkload.properties) 32 | 33 | 34 | 4. After data loading use [ComputeTime.java](https://github.com/IBM/expressive-reasoning-graph-store/blob/master/RDF4J/rdf4j-repository/src/test/java/com/ibm/research/ergs/rdf4j/repository/ComputeTime.java) file to generate execution time for each [query](https://github.com/IBM/expressive-reasoning-graph-store/blob/master/RDF4J/rdf4j-repository/src/test/resources/lubm/queries.txt) with following arguments. 35 | ``` 36 | 37 | ``` 38 | Where: 39 | * repository_id: `` 40 | * query: `` 41 | 42 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | quetzal-RDF 6 | quetzal-RDF 7 | 0.0.1-SNAPSHOT 8 | Quetzal 9 | RDF store for multiple backends 10 | jar 11 | 12 | com.ibm.research.reasoning 13 | QueryEngine 14 | 0.0.1-SNAPSHOT 15 | 16 | 17 | src 18 | 19 | 20 | src 21 | 22 | **/*.java 23 | 24 | 25 | 26 | 27 | 28 | org.apache.maven.plugins 29 | maven-compiler-plugin 30 | 3.6.1 31 | 32 | 1.8 33 | 1.8 34 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | org.eclipse.rdf4j 46 | rdf4j-queryparser-sparql 47 | ${rdf4j.version} 48 | 49 | 50 | org.eclipse.rdf4j 51 | rdf4j-queryrender 52 | ${rdf4j.version} 53 | 54 | 55 | org.eclipse.rdf4j 56 | rdf4j-queryalgebra-model 57 | ${rdf4j.version} 58 | 59 | 60 | org.apache.jena 61 | jena-core 62 | ${jena.version} 63 | 64 | 65 | junit 66 | junit 67 | 4.10 68 | 69 | 70 | org.apache.jena 71 | jena-arq 72 | ${jena.version} 73 | 74 | 75 | net.sourceforge.owlapi 76 | owlapi-distribution 77 | ${owlapi.version} 78 | 79 | 80 | com.ibm.wala 81 | com.ibm.wala.util 82 | 1.3.7 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/src/main/java/com/ibm/research/ergs/rdf4j/query/ExpressiveReasoningGraphStoreGraphQuery.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2020 IBM Corporation and others. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.ibm.research.ergs.rdf4j.query; 17 | 18 | import org.eclipse.rdf4j.query.GraphQuery; 19 | import org.eclipse.rdf4j.query.GraphQueryResult; 20 | import org.eclipse.rdf4j.query.QueryEvaluationException; 21 | import org.eclipse.rdf4j.rio.RDFHandler; 22 | import org.eclipse.rdf4j.rio.RDFHandlerException; 23 | import com.ibm.research.ergs.query.engine.QueryResultSet; 24 | import com.ibm.research.ergs.query.engine.SPARQLQueryProcessor; 25 | 26 | /** 27 | * SPARQL CONSTRUCT/DESCRIBE query for ERGS repository 28 | * 29 | * @author Udit-Sharma 30 | * 31 | */ 32 | public class ExpressiveReasoningGraphStoreGraphQuery extends AbstractExpressiveReasoningGraphStoreQuery implements GraphQuery { 33 | /** 34 | * It constructs SPARQL CONSTRUCT/DESCRIBE query for ERGS repository 35 | * 36 | * @param queryProcessor query execution engine 37 | * @param queryString query string 38 | * @param baseIRI base IRI for the query 39 | */ 40 | public ExpressiveReasoningGraphStoreGraphQuery(SPARQLQueryProcessor queryProcessor, String queryString, 41 | String baseIRI) { 42 | super(queryProcessor, queryString, baseIRI); 43 | } 44 | 45 | @Override 46 | public void setMaxExecutionTime(int maxExecTime) { 47 | throw new UnsupportedOperationException("not implemented"); 48 | 49 | } 50 | 51 | @Override 52 | public int getMaxExecutionTime() { 53 | throw new UnsupportedOperationException("not implemented"); 54 | } 55 | 56 | @Override 57 | public GraphQueryResult evaluate() throws QueryEvaluationException { 58 | QueryResultSet result = queryProcessor.executeQuery(queryString); 59 | return new ExpressiveReasoningGraphStoreGraphQueryResult(result.getResultStream()); 60 | } 61 | 62 | @Override 63 | public void evaluate(RDFHandler handler) throws QueryEvaluationException, RDFHandlerException { 64 | try (GraphQueryResult result = evaluate()) { 65 | handler.startRDF(); 66 | while (result.hasNext()) { 67 | handler.handleStatement(result.next()); 68 | } 69 | handler.endRDF(); 70 | } 71 | 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/src/main/java/com/ibm/research/ergs/rdf4j/query/ExpressiveReasoningGraphStoreTupleQuery.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2020 IBM Corporation and others. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.ibm.research.ergs.rdf4j.query; 17 | 18 | import org.eclipse.rdf4j.query.QueryEvaluationException; 19 | import org.eclipse.rdf4j.query.TupleQuery; 20 | import org.eclipse.rdf4j.query.TupleQueryResult; 21 | import org.eclipse.rdf4j.query.TupleQueryResultHandler; 22 | import org.eclipse.rdf4j.query.TupleQueryResultHandlerException; 23 | import com.ibm.research.ergs.query.engine.QueryResultSet; 24 | import com.ibm.research.ergs.query.engine.SPARQLQueryProcessor; 25 | 26 | /** 27 | * SPARQL SELECT query for ERGS repository 28 | * 29 | * @author Udit Sharma 30 | * 31 | */ 32 | public class ExpressiveReasoningGraphStoreTupleQuery 33 | extends AbstractExpressiveReasoningGraphStoreQuery implements TupleQuery { 34 | 35 | /** 36 | * It constructs SPARQL SELECT query for ERGS repository 37 | * 38 | * @param queryProcessor query execution engine 39 | * @param queryString query string 40 | * @param baseIRI base IRI for the query 41 | */ 42 | public ExpressiveReasoningGraphStoreTupleQuery(SPARQLQueryProcessor queryProcessor, 43 | String queryString, String baseIRI) { 44 | super(queryProcessor, queryString, baseIRI); 45 | } 46 | 47 | @Override 48 | public void setMaxExecutionTime(int maxExecTime) { 49 | throw new UnsupportedOperationException("not implemented"); 50 | 51 | } 52 | 53 | @Override 54 | public int getMaxExecutionTime() { 55 | throw new UnsupportedOperationException("not implemented"); 56 | } 57 | 58 | @Override 59 | public TupleQueryResult evaluate() throws QueryEvaluationException { 60 | QueryResultSet result = queryProcessor.executeQuery(queryString); 61 | return new ExpressiveReasoningGraphStoreTupleQueryResult(result.getResultStream(), 62 | result.getQueryVariables()); 63 | 64 | } 65 | 66 | @Override 67 | public void evaluate(TupleQueryResultHandler handler) 68 | throws QueryEvaluationException, TupleQueryResultHandlerException { 69 | TupleQueryResult result = evaluate(); 70 | handler.startQueryResult(result.getBindingNames()); 71 | while (result.hasNext()) { 72 | handler.handleSolution(result.next()); 73 | } 74 | handler.endQueryResult(); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing In General 2 | Our project welcomes external contributions. If you have an itch, please feel 3 | free to scratch it. 4 | 5 | To contribute code or documentation, please submit a **FIXME** [pull request](https://github.com/IBM/expressive-reasoning-graph-store/pulls). 6 | 7 | A good way to familiarize yourself with the codebase and contribution process is 8 | to look for and tackle low-hanging fruit in the **FIXME** [issue tracker](https://github.com/IBM/expressive-reasoning-graph-store/issues). 9 | Before embarking on a more ambitious contribution, please quickly [get in touch](https://github.com/IBM/expressive-reasoning-graph-store/blob/master/MAINTAINERS.md) with us. 10 | 11 | **Note: We appreciate your effort, and want to avoid a situation where a contribution 12 | requires extensive rework (by you or by us), sits in backlog for a long time, or 13 | cannot be accepted at all!** 14 | 15 | ### Proposing new features 16 | 17 | If you would like to implement a new feature, please **FIXME** [raise an issue](https://github.com/IBM/expressive-reasoning-graph-store/issues) 18 | before sending a pull request so the feature can be discussed. This is to avoid 19 | you wasting your valuable time working on a feature that the project developers 20 | are not interested in accepting into the code base. 21 | 22 | ### Fixing bugs 23 | 24 | If you would like to fix a bug, please **FIXME** [raise an issue](https://github.com/IBM/expressive-reasoning-graph-store/issues) before sending a 25 | pull request so it can be tracked. 26 | 27 | ### Merge approval 28 | 29 | The project maintainers use LGTM (Looks Good To Me) in comments on the code 30 | review to indicate acceptance. A change requires LGTMs from two of the 31 | maintainers of each component affected. 32 | 33 | For a list of the maintainers, see the [MAINTAINERS.md](MAINTAINERS.md) page. 34 | 35 | ## Legal 36 | 37 | Each source file must include a license header for the Apache 38 | Software License 2.0. Using the SPDX format is the simplest approach. 39 | e.g. 40 | 41 | ``` 42 | /* 43 | Copyright All Rights Reserved. 44 | 45 | SPDX-License-Identifier: Apache-2.0 46 | */ 47 | ``` 48 | 49 | We have tried to make it as easy as possible to make contributions. This 50 | applies to how we handle the legal aspects of contribution. We use the 51 | same approach - the [Developer's Certificate of Origin 1.1 (DCO)](https://github.com/IBM/expressive-reasoning-graph-store/blob/master/DCO1.1.txt) - that the Linux® Kernel [community](https://elinux.org/Developer_Certificate_Of_Origin) 52 | uses to manage code contributions. 53 | 54 | We simply ask that when submitting a patch for review, the developer 55 | must include a sign-off statement in the commit message. 56 | 57 | Here is an example Signed-off-by line, which indicates that the 58 | submitter accepts the DCO: 59 | 60 | ``` 61 | Signed-off-by: John Doe 62 | ``` 63 | 64 | You can include this automatically when you commit a change to your 65 | local git repository using the following command: 66 | 67 | ``` 68 | git commit -s 69 | ``` 70 | 71 | ## Setup and Testing 72 | ERGS is a multi-module maven project. It can be compiled, tested, and installed with the usual maven lifecycle phases from the command line. 73 | 74 | ## Coding style guidelines 75 | Use [Google Coding conventions](https://google.github.io/styleguide/javaguide.html) 76 | -------------------------------------------------------------------------------- /docker/janusgraph/gremlin-server.yaml: -------------------------------------------------------------------------------- 1 | host: 0.0.0.0 2 | port: 8182 3 | scriptEvaluationTimeout: 300000 4 | channelizer: org.janusgraph.channelizers.JanusGraphWebSocketChannelizer 5 | graphManager: org.janusgraph.graphdb.management.JanusGraphManager 6 | graphs: { 7 | ConfigurationManagementGraph: /etc/opt/janusgraph/janusgraph.properties 8 | } 9 | scriptEngines: { 10 | gremlin-groovy: { 11 | plugins: { org.janusgraph.graphdb.tinkerpop.plugin.JanusGraphGremlinPlugin: {}, 12 | org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {}, 13 | org.apache.tinkerpop.gremlin.tinkergraph.jsr223.TinkerGraphGremlinPlugin: {}, 14 | org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]}, 15 | org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {files: []}}}} 16 | serializers: 17 | - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }} 18 | - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }} 19 | - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }} 20 | # Older serialization versions for backwards compatibility: 21 | - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }} 22 | - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: {ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }} 23 | - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} 24 | - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }} 25 | - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }} 26 | - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }} 27 | processors: 28 | - { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }} 29 | - { className: org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor, config: { cacheExpirationTime: 600000, cacheMaxSize: 1000 }} 30 | metrics: { 31 | consoleReporter: {enabled: true, interval: 180000}, 32 | csvReporter: {enabled: true, interval: 180000, fileName: /tmp/gremlin-server-metrics.csv}, 33 | jmxReporter: {enabled: true}, 34 | slf4jReporter: {enabled: true, interval: 180000}, 35 | gangliaReporter: {enabled: false, interval: 180000, addressingMode: MULTICAST}, 36 | graphiteReporter: {enabled: false, interval: 180000}} 37 | maxInitialLineLength: 4096 38 | maxHeaderSize: 8192 39 | maxChunkSize: 8192 40 | maxContentLength: 65536000 41 | maxAccumulationBufferComponents: 1024 42 | resultIterationBatchSize: 64 43 | writeBufferLowWaterMark: 32768 44 | writeBufferHighWaterMark: 65536 45 | -------------------------------------------------------------------------------- /QueryEngine/SPARQLToGremlin/src/main/java/com/ibm/research/ergs/query/translation/TransformZeroLengthTriple.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2020 IBM Corporation and others. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.ibm.research.ergs.query.translation; 17 | 18 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 19 | import org.eclipse.rdf4j.query.algebra.Var; 20 | import org.eclipse.rdf4j.query.algebra.ZeroLengthPath; 21 | import com.ibm.research.ergs.query.utils.RDF4JHelper; 22 | 23 | /** 24 | * This class is responsible to translating Zero length property path expressions in SPARQL query to 25 | * equivalent Gremlin traversals 26 | * 27 | * @author Udit Sharma 28 | * 29 | */ 30 | public class TransformZeroLengthTriple { 31 | 32 | /** 33 | * It converts Zero length property path expression 34 | * 35 | * @param traversal current traversal 36 | * @param triple triple pattern 37 | * @param isInverted True if traversal should start from object, False if it should start from 38 | * object of triple 39 | * @param queryData data specific to given query 40 | */ 41 | public static void transform(GraphTraversal traversal, ZeroLengthPath triple, 42 | boolean isInverted, QueryData queryData) { 43 | Var subject = triple.getSubjectVar(); 44 | Var object = triple.getObjectVar(); 45 | if (isInverted) { 46 | copy(traversal, object, subject, queryData); 47 | } else { 48 | copy(traversal, subject, object, queryData); 49 | } 50 | } 51 | 52 | /** 53 | * it copies the contents of subject to object 54 | * 55 | * @param traversal current traversal 56 | * @param subject subject of the triple 57 | * @param object object of the triple 58 | * @param queryData data specific to given query 59 | */ 60 | public static void copy(GraphTraversal traversal, Var subject, Var object, 61 | QueryData queryData) { 62 | String subjVar = queryData.getAnonymousVariable(subject); 63 | if (RDF4JHelper.isIRI(subject)) { 64 | traversal = traversal.select(subjVar).has("id", RDF4JHelper.getValue(subject.getValue())); 65 | } else if (RDF4JHelper.isVariable(subject)) { 66 | traversal = traversal.select(subjVar).values("id").as(subject.getName()); 67 | } 68 | 69 | String objVar = queryData.getAnonymousVariable(object); 70 | traversal = traversal.select(subjVar).as(objVar); 71 | 72 | if (RDF4JHelper.isIRI(object)) { 73 | traversal = traversal.select(objVar).has("id", RDF4JHelper.getValue(object.getValue())); 74 | } else if (RDF4JHelper.isVariable(object)) { 75 | traversal = traversal.select(objVar).values("id").as(object.getName()); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/ConstantExpr.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.rule; 12 | 13 | import java.net.URI; 14 | 15 | 16 | /** 17 | * a constant argument of a {@link AtomicFormula} 18 | * @author Achille Fokoue 19 | * 20 | */ 21 | public class ConstantExpr extends Expr { 22 | 23 | private Object value; 24 | 25 | 26 | public ConstantExpr(String value) { 27 | super(); 28 | this.value = value; 29 | } 30 | public ConstantExpr(Integer value) { 31 | super(); 32 | this.value = value; 33 | } 34 | public ConstantExpr(Double value) { 35 | super(); 36 | this.value = value; 37 | } 38 | public ConstantExpr(Long value) { 39 | super(); 40 | this.value = value; 41 | } 42 | public ConstantExpr(URI value) { 43 | super(); 44 | this.value = value; 45 | } 46 | 47 | public ConstantExpr(Object value) { 48 | super(); 49 | this.value = value; 50 | } 51 | @Override 52 | public boolean isConstant() { 53 | return true; 54 | } 55 | @Override 56 | public boolean isVariable() { 57 | return false; 58 | } 59 | 60 | public Object getValue() { 61 | return value; 62 | } 63 | 64 | 65 | 66 | 67 | 68 | @Override 69 | public ConstantExpr asConstant() { 70 | return this; 71 | } 72 | @Override 73 | public VariableExpr asVariable() { 74 | return null; 75 | } 76 | 77 | @Override 78 | public int hashCode() { 79 | final int prime = 31; 80 | int result = 1; 81 | result = prime * result + ((value == null) ? 0 : value.hashCode()); 82 | return result; 83 | } 84 | @Override 85 | public boolean equals(Object obj) { 86 | if (this == obj) 87 | return true; 88 | if (obj == null) 89 | return false; 90 | if (getClass() != obj.getClass()) 91 | return false; 92 | ConstantExpr other = (ConstantExpr) obj; 93 | if (value == null) { 94 | if (other.value != null) 95 | return false; 96 | } else if (!value.equals(other.value)) 97 | return false; 98 | return true; 99 | } 100 | public String toString() { 101 | if (value instanceof String) { 102 | return "'"+ value.toString()+"'"; 103 | } else if (value instanceof URI){ 104 | return "<"+value.toString()+">"; 105 | } 106 | return value.toString(); 107 | } 108 | @Override 109 | public ConstantExpr clone() { 110 | if (value instanceof Integer) { 111 | return new ConstantExpr((Integer) value); 112 | } else if (value instanceof Long) { 113 | return new ConstantExpr((Long) value); 114 | } else if (value instanceof Double) { 115 | return new ConstantExpr((Double) value); 116 | } else if (value instanceof URI) { 117 | return new ConstantExpr((URI) value); 118 | } else { 119 | 120 | return new ConstantExpr(value.toString()); 121 | } 122 | } 123 | 124 | 125 | 126 | } 127 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/Expr.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.rule; 12 | 13 | import java.net.URI; 14 | import java.net.URISyntaxException; 15 | import java.text.ParseException; 16 | import java.util.StringTokenizer; 17 | 18 | 19 | 20 | 21 | 22 | /** 23 | * An expression used as an argument of an {@link AtomicFormula} 24 | * Note: In this simple implementation, there are only 25 | * two expressions: variables and constants. 26 | 27 | * @author Achille Fokoue 28 | * 29 | */ 30 | public abstract class Expr { 31 | 32 | /** 33 | * whether this argument is a constant. 34 | ** 35 | * @return 36 | */ 37 | public abstract boolean isConstant(); 38 | 39 | public abstract ConstantExpr asConstant(); 40 | /** 41 | * whether this argument is a variable. 42 | ** 43 | * @return 44 | */ 45 | public abstract boolean isVariable(); 46 | public abstract VariableExpr asVariable(); 47 | 48 | 49 | public static Expr parse(String s ) throws ParseException { 50 | s=s.trim(); 51 | if (s.length()==0) { 52 | throw new ParseException(" the empty string is not a valid expression", 0); 53 | } 54 | int firstCh = s.charAt(0); 55 | // 56 | if (Character.isLetter(firstCh) ) { 57 | 58 | StringTokenizer tok= new StringTokenizer(s); 59 | int numOfTokens = 0; 60 | while(tok.hasMoreTokens()) { 61 | numOfTokens++; 62 | tok.nextToken(); 63 | if (numOfTokens>1) { 64 | throw new ParseException("Invalid variable: "+s,0); 65 | } 66 | } 67 | return new VariableExpr(s); 68 | } else { 69 | if (s.length()>1) { 70 | if (s.startsWith("'") && s.endsWith("'")) { 71 | return new ConstantExpr(s.substring(1,s.length()-1)); 72 | } 73 | if (s.startsWith("\"") && s.endsWith("\"")) { 74 | return new ConstantExpr(s.substring(1,s.length()-1)); 75 | } 76 | if (s.startsWith("<") && s.endsWith(">")) { 77 | try { 78 | return new ConstantExpr(new URI(s.substring(1,s.length()-1))); 79 | } catch (URISyntaxException e) { 80 | throw new ParseException("Invalid URI: "+ s+". Error message: "+e.getMessage(), 0); 81 | } 82 | } 83 | } 84 | try { 85 | long value = Long.parseLong(s); 86 | if (value<=Integer.MAX_VALUE && value>=Integer.MIN_VALUE) { 87 | return new ConstantExpr(new Integer((int)value)); 88 | } 89 | return new ConstantExpr(new Long(value)); 90 | } catch (NumberFormatException e) { 91 | try { 92 | double value = Double.parseDouble(s); 93 | return new ConstantExpr(new Double(value)); 94 | } catch (NumberFormatException ex) { 95 | throw new ParseException("Invalid constant " + s, 0); 96 | } 97 | 98 | 99 | } 100 | 101 | } 102 | } 103 | 104 | public abstract Expr clone(); 105 | 106 | } 107 | -------------------------------------------------------------------------------- /IngestionPipeline/GraphIngestion/src/main/java/com/ibm/research/ergs/ingestion/graphdb/SchemaCreator.java: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************* 3 | * Copyright 2020 IBM Corporation and others. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | *******************************************************************************/ 15 | package com.ibm.research.ergs.ingestion.graphdb; 16 | 17 | /** 18 | * It holds scheme creation functions. 19 | * 20 | * @author Sumit Neelam (sumit.neelam@in.ibm.com) 21 | * 22 | */ 23 | public interface SchemaCreator { 24 | /** 25 | * It creates JanusGraph property. 26 | * 27 | * @param propertyName: property name 28 | * @param propertyType: property datatype 29 | * @param multivalued: is multivalued 30 | * @param isSet: multivalued property should contains unique values. 31 | */ 32 | public void createProperty(String propertyName, String propertyType, boolean multivalued, 33 | boolean isSet); 34 | 35 | /** 36 | * It creates JanusGraph indexed property. 37 | * 38 | * @param propertyName: property name 39 | * @param propertyType: property datatype 40 | * @param isUnique 41 | * @param multivalued: is multivalued 42 | * @param isSet: multivalued property should contains unique values. 43 | */ 44 | public void createIndexProperty(String propertyName, String propertyType, boolean isUnique, 45 | boolean multivalued, boolean isSet); 46 | 47 | /** 48 | * It creates JanusGraph external indexed property. 49 | * 50 | * @param propertyName: property name 51 | * @param indexName: name of index in indexing backend 52 | * @param propertyType: property datatype 53 | * @param multivalued: is multivalued 54 | * @param isSet: multivalued property should contains unique values. 55 | * @param indexType: type values {"text", "string", "textstring" 56 | */ 57 | public void createExternalIndexProperty(String propertyName, String indexName, 58 | String propertyType, boolean multivalued, boolean isSet, String indexType); 59 | 60 | /** 61 | * It creates JanusGraph indexed edge property. 62 | * 63 | * @param propertyName: property name 64 | * @param propertyType: property datatype 65 | * @param isUnique 66 | * @param multivalued: is multivalued 67 | * @param isSet: multivalued property should contains unique values. 68 | */ 69 | public void createEdgeIndexProperty(String propertyName, String propertyType, boolean isUnique); 70 | 71 | /** 72 | * It creates JanusGraph edge. 73 | * 74 | * @param edgeLabel 75 | */ 76 | public void createEdgeLabel(String edgeLabel); 77 | 78 | /** 79 | * It creates JanusGraph simple edge, i.e., avoids parallel edge for edgeLabel. 80 | * 81 | * @param edgeLabel 82 | */ 83 | public void createSimpleEdgeLabel(String edgeLabel); 84 | 85 | /** 86 | * commits graph creation operations 87 | */ 88 | public void commit(); 89 | } 90 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/PredicateAdornment.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.rule; 12 | 13 | import java.util.Iterator; 14 | import java.util.List; 15 | 16 | public class PredicateAdornment implements Adornment { 17 | 18 | private Predicate predicate; 19 | private List boundArguments; 20 | 21 | 22 | public PredicateAdornment(Predicate predicate, List boundArgumentPositions) { 23 | super(); 24 | this.predicate = predicate; 25 | this.boundArguments = boundArgumentPositions; 26 | assert checkConsistency(); 27 | } 28 | 29 | public boolean checkConsistency() { 30 | for (Iterator it = boundArguments.iterator();it.hasNext();) { 31 | int pos = it.next(); 32 | assert pos getBoundArguments() { 44 | return boundArguments; 45 | } 46 | 47 | public boolean isBoundArgument(int pos) { 48 | return boundArguments.contains(pos); 49 | } 50 | 51 | /** 52 | * returns the list of free arguments. Note that list is 53 | * compute as the difference between {@link AtomicFormula#getArguments()} 54 | * and {@link #getBoundArguments()}. Therefore, it should be 55 | * recomputed if one of those two lists is updated. 56 | * @return 57 | */ 58 | /*public List getFreeVariables() { 59 | List ret = new ArrayList(pred.getArguments()); 60 | ret.removeAll(boundArguments); 61 | return new ArrayList(ret); 62 | }*/ 63 | 64 | public boolean equals(Object o) { 65 | if (o==this) { 66 | return true; 67 | } 68 | if (o instanceof PredicateAdornment) { 69 | PredicateAdornment other =(PredicateAdornment)o; 70 | return predicate.equals(other.predicate) 71 | && boundArguments.equals(other.boundArguments); 72 | } 73 | return false; 74 | } 75 | 76 | public int hashCode() { 77 | return predicate.hashCode()+ 31*boundArguments.hashCode(); 78 | } 79 | 80 | 81 | 82 | public Predicate getPredicate() { 83 | return predicate; 84 | } 85 | 86 | public boolean isAdornmentOnPredicate() { 87 | return true; 88 | } 89 | 90 | public boolean isAdornmentOnRule() { 91 | return false; 92 | } 93 | 94 | public PredicateAdornment asPredicateAdornment() { 95 | return this; 96 | } 97 | 98 | public RuleAdornment asRuleAdornment() { 99 | return null; 100 | } 101 | 102 | @Override 103 | public String toString() { 104 | return "PredicateAdornment [predicate=" + predicate 105 | + ", boundArguments=" + boundArguments + "]"; 106 | } 107 | 108 | 109 | 110 | 111 | 112 | } 113 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/src/main/resources/janusgraph-hbase-configurationgraph.properties: -------------------------------------------------------------------------------- 1 | # JanusGraph configuration sample: Cassandra over a socket 2 | # 3 | # This file connects to a Cassandra daemon running on localhost via 4 | # Thrift. Cassandra must already be started before starting JanusGraph 5 | # with this file. 6 | 7 | gremlin.graph=org.janusgraph.core.ConfiguredGraphFactory 8 | 9 | # The primary persistence provider used by JanusGraph. This is required. 10 | # It should be set one of JanusGraph's built-in shorthand names for its 11 | # standard storage backends (shorthands: berkeleyje, cassandrathrift, 12 | # cassandra, astyanax, embeddedcassandra, hbase, inmemory) or to the full 13 | # package and classname of a custom/third-party StoreManager 14 | # implementation. 15 | # 16 | # Default: (no default value) 17 | # Data Type: String 18 | # Mutability: LOCAL 19 | storage.backend=hbase 20 | 21 | # The configuration management graph reserved for use with JanusGraphManager 22 | # and ConfiguredGraphFactory 23 | graph.graphname=ConfigurationManagementGraph 24 | # The hostname or comma-separated list of hostnames of storage backend 25 | # servers. This is only applicable to some storage backends, such as 26 | # cassandra and hbase. 27 | # 28 | # Default: 127.0.0.1 29 | # Data Type: class java.lang.String[] 30 | # Mutability: LOCAL 31 | storage.hostname=127.0.0.1 32 | 33 | # Whether to enable JanusGraph's database-level cache, which is shared 34 | # across all transactions. Enabling this option speeds up traversals by 35 | # holding hot graph elements in memory, but also increases the likelihood 36 | # of reading stale data. Disabling it forces each transaction to 37 | # independently fetch graph elements from storage before reading/writing 38 | # them. 39 | # 40 | # Default: false 41 | # Data Type: Boolean 42 | # Mutability: MASKABLE 43 | cache.db-cache = true 44 | 45 | # How long, in milliseconds, database-level cache will keep entries after 46 | # flushing them. This option is only useful on distributed storage 47 | # backends that are capable of acknowledging writes without necessarily 48 | # making them immediately visible. 49 | # 50 | # Default: 50 51 | # Data Type: Integer 52 | # Mutability: GLOBAL_OFFLINE 53 | # 54 | # Settings with mutability GLOBAL_OFFLINE are centrally managed in 55 | # JanusGraph's storage backend. After starting the database for the first 56 | # time, this file's copy of this setting is ignored. Use JanusGraph's 57 | # Management System to read or modify this value after bootstrapping. 58 | cache.db-cache-clean-wait = 20 59 | 60 | # Default expiration time, in milliseconds, for entries in the 61 | # database-level cache. Entries are evicted when they reach this age even 62 | # if the cache has room to spare. Set to 0 to disable expiration (cache 63 | # entries live forever or until memory pressure triggers eviction when set 64 | # to 0). 65 | # 66 | # Default: 10000 67 | # Data Type: Long 68 | # Mutability: GLOBAL_OFFLINE 69 | # 70 | # Settings with mutability GLOBAL_OFFLINE are centrally managed in 71 | # JanusGraph's storage backend. After starting the database for the first 72 | # time, this file's copy of this setting is ignored. Use JanusGraph's 73 | # Management System to read or modify this value after bootstrapping. 74 | cache.db-cache-time = 180000 75 | 76 | # Size of JanusGraph's database level cache. Values between 0 and 1 are 77 | # interpreted as a percentage of VM heap, while larger values are 78 | # interpreted as an absolute size in bytes. 79 | # 80 | # Default: 0.3 81 | # Data Type: Double 82 | # Mutability: MASKABLE 83 | cache.db-cache-size = 0.5 84 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/Predicate.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.rule; 12 | 13 | public class Predicate { 14 | 15 | public static final char NEGATION_SYMBOL = '!'; 16 | public static final char OPTIONAL_SYMBOL = '*'; 17 | private boolean isNegated; 18 | private boolean isOptional; 19 | private String name; 20 | protected int arity; 21 | public Predicate(String name, int arity, boolean isNegated, boolean isOptional) { 22 | super(); 23 | if (isNegated && isOptional) { 24 | throw new RuntimeException("Negated and optional predicate not allowed!"); 25 | } 26 | this.name = name; 27 | this.arity = arity; 28 | this.isNegated = isNegated; 29 | this.isOptional = isOptional; 30 | } 31 | public Predicate(String name, int arity) { 32 | this(name, arity,false, false); 33 | } 34 | public Predicate clone() { 35 | return new Predicate(name,arity,isNegated, isOptional); 36 | } 37 | Predicate cloneWithNonZeroArity() { 38 | return arity!=0? 39 | new Predicate(name,arity): new Predicate(name, 1); 40 | } 41 | public int getArity() { 42 | return arity; 43 | } 44 | public String getName() { 45 | return name; 46 | } 47 | public boolean isNegated() { 48 | return isNegated; 49 | } 50 | 51 | public Predicate negate() { 52 | if (!isNegated && isOptional) { 53 | throw new RuntimeException("Negated and optional predicate not allowed!"); 54 | } 55 | return new Predicate(name, arity, !isNegated, isOptional); 56 | } 57 | public boolean isOptional() { 58 | return isOptional; 59 | } 60 | public Predicate switchOptionalFlag() { 61 | if (isNegated && !isOptional) { 62 | throw new RuntimeException("Negated and optional predicate not allowed!"); 63 | } 64 | return new Predicate(name, arity, isNegated, !isOptional); 65 | } 66 | 67 | public Predicate withoutQualification() { 68 | return new Predicate(name, arity, false, false); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | final int prime = 31; 74 | int result = 1; 75 | result = prime * result + arity; 76 | result = prime * result + (isNegated ? 1231 : 1237); 77 | result = prime * result + (isOptional ? 1231 : 1237); 78 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 79 | return result; 80 | } 81 | @Override 82 | public boolean equals(Object obj) { 83 | if (this == obj) 84 | return true; 85 | if (obj == null) 86 | return false; 87 | if (getClass() != obj.getClass()) 88 | return false; 89 | Predicate other = (Predicate) obj; 90 | if (arity != other.arity) 91 | return false; 92 | if (isNegated != other.isNegated) 93 | return false; 94 | if (isOptional != other.isOptional) 95 | return false; 96 | if (name == null) { 97 | if (other.name != null) 98 | return false; 99 | } else if (!name.equals(other.name)) 100 | return false; 101 | return true; 102 | } 103 | public String toString() { 104 | return (isNegated? NEGATION_SYMBOL+"":"")+(isOptional? OPTIONAL_SYMBOL:"")+name; 105 | } 106 | 107 | 108 | } 109 | -------------------------------------------------------------------------------- /IngestionPipeline/GraphIngestion/src/main/java/com/ibm/research/ergs/ingestion/graphdb/JanusGraphSchemaConstant.java: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************* 3 | * Copyright 2020 IBM Corporation and others. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | *******************************************************************************/ 15 | package com.ibm.research.ergs.ingestion.graphdb; 16 | 17 | /** 18 | * This class contains JanusGraph internal schema related constants 19 | * 20 | * @author Sumit Neelam (sumit.neelam@in.ibm.com) 21 | * 22 | */ 23 | public class JanusGraphSchemaConstant { 24 | public static String ID_PROPERTY = "id"; 25 | public static String ORG_ID_PROPERTY = "oid"; 26 | 27 | public static String STATNODE_INSTANCE_COUNT_KEY = "instancecount"; 28 | public static String STATNODE_DOMAIN_COUNT_KEY = "domaincount"; 29 | public static String STATNODE_RANGE_COUNT_KEY = "rangecount"; 30 | public static String STATNODE_RANGE_UNIQUE_VALUES_KEY = "uniquevalues"; 31 | 32 | public static String INFERRED_RELATION = "inferred"; 33 | public static String EDGE_TYPE_KEY = "reltype"; 34 | 35 | private static final String CONTEXT_PROPERTY_CONST = "context"; 36 | private static final String SUMMARYNODE_CONTEXT_PROPERTY_VALUE_CONST = "summary"; 37 | private static final String SUMMARYNODE_AND_DATANODE_EDGE_LABEL_CONST = "summaryOf"; 38 | private static final String SUMMARYNODE_ID_CONST = "sid"; 39 | private static final String SUMMARYEDGECOUNTPROPERTY_CONST = "count"; 40 | private static final String SUMMARYCOUNTPROPERTY_CONST = "nodecount"; 41 | private static final String SUMMARYEDGE_CONST = "connectedTO"; 42 | private static final String SUMMARYEDGELABELPROPERTY_CONST = "edgeLabel"; 43 | private static final String SUMMARYNODE_TYPE_CONST = "type"; 44 | 45 | /* 46 | * summary specific constant 47 | */ 48 | public static String CONTEXT_PROPERTY = "context"; 49 | public static String SUMMARYNODE_CONTEXT_PROPERTY_VALUE = "summary"; 50 | public static String SUMMARYNODE_AND_DATANODE_EDGE_LABEL = "summaryOf"; 51 | public static String SUMMARYNODE_ID = "sid"; 52 | public static String SUMMARYEDGECOUNTPROPERTY = "count"; 53 | public static String SUMMARYCOUNTPROPERTY = "nodecount"; 54 | public static String SUMMARYEDGE = "connectedTO"; 55 | public static String SUMMARYEDGELABELPROPERTY = "edgeLabel"; 56 | public static String SUMMARYNODE_TYPE = "type"; 57 | 58 | public static String baseURIStr; 59 | 60 | public static void updateConstVariable(String baseURI) { 61 | baseURIStr = baseURI; 62 | CONTEXT_PROPERTY = baseURI + CONTEXT_PROPERTY_CONST; 63 | SUMMARYNODE_CONTEXT_PROPERTY_VALUE = baseURI + SUMMARYNODE_CONTEXT_PROPERTY_VALUE_CONST; 64 | SUMMARYNODE_AND_DATANODE_EDGE_LABEL = baseURI + SUMMARYNODE_AND_DATANODE_EDGE_LABEL_CONST; 65 | SUMMARYNODE_ID = baseURI + SUMMARYNODE_ID_CONST; 66 | SUMMARYEDGECOUNTPROPERTY = baseURI + SUMMARYEDGECOUNTPROPERTY_CONST; 67 | SUMMARYCOUNTPROPERTY = baseURI + SUMMARYCOUNTPROPERTY_CONST; 68 | SUMMARYEDGE = baseURI + SUMMARYEDGE_CONST; 69 | SUMMARYEDGELABELPROPERTY = baseURI + SUMMARYEDGELABELPROPERTY_CONST; 70 | SUMMARYNODE_TYPE = baseURI + SUMMARYNODE_TYPE_CONST; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/MagicSetPredicate.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.rule; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class MagicSetPredicate extends Predicate { 17 | 18 | private UniqueBindingPredicate predicate; 19 | 20 | static MagicSetPredicate createMagicSetPredicate(UniqueBindingPredicate predicate) { 21 | int arity = 0; 22 | for (int i=0;i args = new ArrayList(predicate.getArity()); 36 | for (int i=0;i 2 | 4 | ]> 5 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
    21 | 22 | 23 | 24 | 27 | 86 | 87 | 88 | 89 | 92 | 95 | 96 | 97 | 98 | 101 | 104 | 105 | 106 | 107 | 108 | 114 | 115 | 116 |
    25 | 26 | 28 | 85 |
    90 | 91 | 93 | 94 |
    99 | 100 | 102 | 103 |
    109 | 112 | 113 |
    117 |
    118 |
    119 | 120 |
    121 | -------------------------------------------------------------------------------- /IngestionPipeline/GraphIngestion/src/main/java/com/ibm/research/ergs/ingestion/graphdb/GraphDBLoad.java: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************* 3 | * Copyright 2020 IBM Corporation and others. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | *******************************************************************************/ 15 | package com.ibm.research.ergs.ingestion.graphdb; 16 | 17 | import java.util.ArrayList; 18 | import java.util.HashMap; 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | import org.eclipse.rdf4j.model.Literal; 22 | 23 | /** 24 | * This interface contains graph related load operations. 25 | * 26 | * @author Sumit Neelam (sumit.neelam@in.ibm.com) 27 | * 28 | */ 29 | public interface GraphDBLoad { 30 | /** 31 | * This is entry point for writing data into graph. It first creates type edges, then creates 32 | * vertex properties followed by edges 33 | * 34 | * @param sourceID 35 | * @param typeMap 36 | * @param properties 37 | * @param edges 38 | * @param sameAsList 39 | * @param propertyKeys 40 | * @param conflictingLabels 41 | * @throws Exception 42 | */ 43 | public void createCompleteNode(String sourceID, HashMap> typeMap, 44 | HashMap> properties, HashMap> edges, 45 | ArrayList sameAsList, HashMap propertyKeys, 46 | HashMap conflictingLabels) throws Exception; 47 | 48 | /** 49 | * Creates vertex set. This is called for degree 0 vertex from {@link TriplesBatch} 50 | * 51 | * @param nodeIdSubList 52 | */ 53 | public void createVertexSet(Set nodeIdSubList); 54 | 55 | /** 56 | * This function writes schema information for new properties, edges, conflicting labels (used for 57 | * both property and edge), external indexing property 58 | * 59 | * @param propertyKeys 60 | * @param edgeLabels 61 | * @param conflictingLabels 62 | * @param cycleNewIndexProp 63 | * @param cycleDeletePropertyKeys 64 | * @param cycleDeleteEdgeLabels 65 | * @param totalExtIndex 66 | */ 67 | public void writeSchemaInformation(HashMap propertyKeys, 68 | HashSet edgeLabels, HashMap conflictingLabels, 69 | HashMap cycleNewIndexProp, HashSet cycleDeletePropertyKeys, 70 | HashSet cycleDeleteEdgeLabels, int totalExtIndex); 71 | 72 | /** 73 | * return existing property keys of graph 74 | * 75 | * @return: property keys and their data type 76 | */ 77 | public HashMap getPropertyKeys(); 78 | 79 | /** 80 | * return existing edges of graph 81 | * 82 | * @return: set of edges 83 | */ 84 | public Set getEdgeLabels(); 85 | 86 | /** 87 | * return existing conflicting labels of graph 88 | * 89 | * @return: conflicting labels 90 | */ 91 | public HashMap getConflictingLabels(); 92 | 93 | /** 94 | * return existing number of indexed property (of external backend) of graph 95 | * 96 | * @return 97 | */ 98 | public int getExteralIndexCount(); 99 | 100 | /** 101 | * commits the data 102 | * 103 | * @throws Exception 104 | */ 105 | public void commit() throws Exception; 106 | } 107 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-workbench/src/main/webapp/transformations/create-ergs-repository.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
    19 | 20 | 21 | 22 | 25 | 32 | 33 | 34 | 35 | 38 | 42 | 45 | 46 | 47 | 50 | 54 | 55 | 56 | 57 | 60 | 79 | 83 | 84 | 85 | 88 | 105 | 108 | 109 | 110 | 111 | 118 | 119 | 120 |
    23 | 24 | 26 | 31 |
    36 | 37 | 39 | 41 | 43 | 44 |
    48 | 49 | 51 | 53 |
    58 | 59 | 61 | 63 | 64 | 65 | 66 | 77 | 78 | 80 | 82 |
    86 | 87 | 89 | 90 | 91 | 92 | 93 | 104 | 106 | 107 |
    112 | 115 | 117 |
    121 |
    122 | 124 |
    125 | 126 |
    127 | -------------------------------------------------------------------------------- /docker/janusgraph/janusgraph.properties: -------------------------------------------------------------------------------- 1 | # Copyright 2019 JanusGraph Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # JanusGraph configuration sample: Cassandra over a socket 16 | # 17 | # This file connects to a Cassandra daemon running on localhost via 18 | # Thrift. Cassandra must already be started before starting JanusGraph 19 | # with this file. 20 | 21 | gremlin.graph=org.janusgraph.core.JanusGraphFactory 22 | 23 | # The primary persistence provider used by JanusGraph. This is required. 24 | # It should be set one of JanusGraph's built-in shorthand names for its 25 | # standard storage backends (shorthands: berkeleyje, cassandrathrift, 26 | # cassandra, astyanax, embeddedcassandra, cql, hbase, inmemory) or to the 27 | # full package and classname of a custom/third-party StoreManager 28 | # implementation. 29 | # 30 | # Default: (no default value) 31 | # Data Type: String 32 | # Mutability: LOCAL 33 | storage.backend=cql 34 | 35 | # The hostname or comma-separated list of hostnames of storage backend 36 | # servers. This is only applicable to some storage backends, such as 37 | # cassandra and hbase. 38 | # 39 | # Default: 127.0.0.1 40 | # Data Type: class java.lang.String[] 41 | # Mutability: LOCAL 42 | storage.hostname=cass-docker 43 | 44 | # Whether to enable JanusGraph's database-level cache, which is shared 45 | # across all transactions. Enabling this option speeds up traversals by 46 | # holding hot graph elements in memory, but also increases the likelihood 47 | # of reading stale data. Disabling it forces each transaction to 48 | # independently fetch graph elements from storage before reading/writing 49 | # them. 50 | # 51 | # Default: false 52 | # Data Type: Boolean 53 | # Mutability: MASKABLE 54 | cache.db-cache = true 55 | 56 | # How long, in milliseconds, database-level cache will keep entries after 57 | # flushing them. This option is only useful on distributed storage 58 | # backends that are capable of acknowledging writes without necessarily 59 | # making them immediately visible. 60 | # 61 | # Default: 50 62 | # Data Type: Integer 63 | # Mutability: GLOBAL_OFFLINE 64 | # 65 | # Settings with mutability GLOBAL_OFFLINE are centrally managed in 66 | # JanusGraph's storage backend. After starting the database for the first 67 | # time, this file's copy of this setting is ignored. Use JanusGraph's 68 | # Management System to read or modify this value after bootstrapping. 69 | cache.db-cache-clean-wait = 20 70 | 71 | # Default expiration time, in milliseconds, for entries in the 72 | # database-level cache. Entries are evicted when they reach this age even 73 | # if the cache has room to spare. Set to 0 to disable expiration (cache 74 | # entries live forever or until memory pressure triggers eviction when set 75 | # to 0). 76 | # 77 | # Default: 10000 78 | # Data Type: Long 79 | # Mutability: GLOBAL_OFFLINE 80 | # 81 | # Settings with mutability GLOBAL_OFFLINE are centrally managed in 82 | # JanusGraph's storage backend. After starting the database for the first 83 | # time, this file's copy of this setting is ignored. Use JanusGraph's 84 | # Management System to read or modify this value after bootstrapping. 85 | cache.db-cache-time = 180000 86 | 87 | # Size of JanusGraph's database level cache. Values between 0 and 1 are 88 | # interpreted as a percentage of VM heap, while larger values are 89 | # interpreted as an absolute size in bytes. 90 | # 91 | # Default: 0.3 92 | # Data Type: Double 93 | # Mutability: MASKABLE 94 | cache.db-cache-size = 0.5 95 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/RuleAdornment.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.rule; 12 | 13 | import java.util.HashSet; 14 | import java.util.Iterator; 15 | import java.util.Set; 16 | 17 | public class RuleAdornment implements Adornment{ 18 | 19 | private Rule rule; 20 | private int position; 21 | private Set boundVariables; 22 | private Set freeVariables; 23 | 24 | public RuleAdornment(Rule rule, Set boundVariables, Set freeVariables, int position) { 25 | super(); 26 | this.rule = rule; 27 | this.boundVariables = boundVariables; 28 | this.freeVariables = freeVariables; 29 | this.position = position; 30 | assert checkConsistency(); 31 | } 32 | 33 | private boolean checkConsistency() { 34 | Set ruleVars = getAllRuleVariables(); 35 | Set boundAndFreeVariables = new HashSet(boundVariables); 36 | boundAndFreeVariables.addAll(freeVariables); 37 | assert boundAndFreeVariables.equals(ruleVars) 38 | :"freeVars: "+freeVariables+"\n boundVars: "+boundVariables 39 | +"\n all rule vars: "+getAllRuleVariables(); 40 | Set inter = new HashSet(boundVariables); 41 | inter.retainAll(freeVariables); 42 | assert inter.isEmpty() 43 | :"The following variables appear to be both free and bound: "+ inter; 44 | return true; 45 | } 46 | 47 | public Set getBoundVariables() { 48 | return boundVariables; 49 | } 50 | 51 | public Set getFreeVariables() { 52 | return freeVariables; 53 | } 54 | 55 | public Set getAllRuleVariables() { 56 | return new HashSet(rule.getAllRuleVariables()); 57 | } 58 | 59 | public boolean equals(Object o) { 60 | if (o==this) { 61 | return true; 62 | } 63 | if (o instanceof RuleAdornment) { 64 | RuleAdornment other =(RuleAdornment)o; 65 | return rule.equals(other.rule) 66 | && position == other.position 67 | && boundVariables.equals(other.boundVariables); 68 | } 69 | return false; 70 | } 71 | 72 | public int hashCode() { 73 | return rule.hashCode()+ 31*(boundVariables.hashCode()+31*position); 74 | } 75 | 76 | 77 | 78 | 79 | 80 | public int getPosition() { 81 | return position; 82 | } 83 | 84 | public RuleAdornment next() { 85 | if (position+1 newFreeVars = new HashSet(getFreeVariables()); 88 | Set newBoundVars = new HashSet(getBoundVariables()); 89 | AtomicFormula curAf = rule.getBody().get(position); 90 | if (!curAf.getPredicate().isNegated() 91 | && !curAf.getPredicate().isOptional()) { 92 | // make sure that the current atomic formula is not negated or optional 93 | // before changing the adornment 94 | for (Iterator it= curAf.getArguments().iterator();it.hasNext();) { 95 | Expr e = it.next(); 96 | if (e.isVariable()) { 97 | VariableExpr var = (VariableExpr) e; 98 | newBoundVars.add(var); 99 | newFreeVars.remove(var); 100 | } else { 101 | assert e.isConstant(); 102 | } 103 | } 104 | } 105 | return new RuleAdornment(rule,newBoundVars,newFreeVars,newPos); 106 | 107 | } else { 108 | return null; 109 | } 110 | } 111 | 112 | public PredicateAdornment asPredicateAdornment() { 113 | return null; 114 | } 115 | 116 | public RuleAdornment asRuleAdornment() { 117 | return this; 118 | } 119 | 120 | public boolean isAdornmentOnPredicate() { 121 | return false; 122 | } 123 | 124 | public boolean isAdornmentOnRule() { 125 | return true; 126 | } 127 | 128 | public Rule getRule() { 129 | return rule; 130 | } 131 | 132 | 133 | 134 | } 135 | -------------------------------------------------------------------------------- /IngestionPipeline/GraphIngestion/src/main/java/com/ibm/research/ergs/ingestion/loader/BulkLoader.java: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************* 3 | * Copyright 2020 IBM Corporation and others. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | *******************************************************************************/ 15 | package com.ibm.research.ergs.ingestion.loader; 16 | 17 | import java.io.File; 18 | import java.io.FileReader; 19 | import java.util.Properties; 20 | import org.apache.commons.configuration.BaseConfiguration; 21 | import org.apache.commons.configuration.Configuration; 22 | import org.eclipse.rdf4j.rio.RDFFormat; 23 | import org.janusgraph.core.JanusGraph; 24 | import org.janusgraph.core.JanusGraphFactory; 25 | 26 | /** 27 | * Class contains bulk loader function executed from docker environment. 28 | * 29 | * @author Sumit Neelam (sumit.neelam@in.ibm.com) 30 | * 31 | */ 32 | public class BulkLoader { 33 | public static void main(String args[]) { 34 | boolean success = true; 35 | if (args.length < 5) { 36 | System.out 37 | .println("Insufficient arguments. Following should be sructure of input arguments."); 38 | System.out 39 | .println("BulkLoader "); 40 | success = false; 41 | } 42 | String graphName = null; 43 | File inputFile = null; 44 | RDFFormat rdfFormat = null; 45 | String baseURI = null; 46 | Properties properties = new Properties(); 47 | try { 48 | graphName = args[0]; 49 | inputFile = new File(args[1]); 50 | String format = args[2]; 51 | baseURI = args[3]; 52 | properties.load(new FileReader(args[4])); 53 | 54 | if (format.equalsIgnoreCase("rdf")) { 55 | rdfFormat = RDFFormat.RDFXML; 56 | } else if (format.equalsIgnoreCase("turtle")) { 57 | rdfFormat = RDFFormat.TURTLE; 58 | } else if (format.equalsIgnoreCase("ntriples")) { 59 | rdfFormat = RDFFormat.NTRIPLES; 60 | } else if (format.equalsIgnoreCase("n3")) { 61 | rdfFormat = RDFFormat.N3; 62 | } else { 63 | System.out.println("Unsupported input file type:" + format); 64 | System.out.println("Please choose one of following: 'rdf', 'turtle', 'ntriples', 'n3'"); 65 | success = false; 66 | } 67 | } catch (Exception e) { 68 | System.out.println("Exception in input property File: " + e); 69 | success = false; 70 | } 71 | if (success) { 72 | Configuration configuration = new BaseConfiguration(); 73 | configuration.addProperty("gremlin.graph", "org.janusgraph.core.JanusGraphFactory"); 74 | configuration.addProperty("storage.backend", "cql"); 75 | configuration.addProperty("storage.hostname", "cass-docker"); 76 | configuration.addProperty("storage.cql.keyspace", graphName); 77 | configuration.addProperty("cache.db-cache", true); 78 | configuration.addProperty("cache.db-cache-clean-wait", 20); 79 | configuration.addProperty("cache.db-cache-time", 180000); 80 | configuration.addProperty("cache.db-cache-size", 0.5); 81 | configuration.addProperty("ids.block-size", 48000000); 82 | configuration.addProperty("storage.transactions", false); 83 | configuration.addProperty("storage.write-time", 1000000); 84 | configuration.addProperty("schema.default", "none"); 85 | configuration.addProperty("storage.batch-loading", true); 86 | 87 | JanusGraph janusGraph = JanusGraphFactory.open(configuration); 88 | LoadRDFData loadRDFData = new LoadRDFData(janusGraph, properties); 89 | 90 | if (inputFile.isDirectory()) { 91 | loadRDFData.loadDirectoryAllFiles(inputFile, rdfFormat, baseURI); 92 | } else { 93 | loadRDFData.loadFromFile(inputFile, rdfFormat, baseURI); 94 | } 95 | 96 | janusGraph.close(); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /IngestionPipeline/GraphIngestion/src/main/java/com/ibm/research/ergs/ingestion/loader/CreateGraphFoundationSchema.java: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************* 3 | * Copyright 2020 IBM Corporation and others. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | *******************************************************************************/ 15 | package com.ibm.research.ergs.ingestion.loader; 16 | 17 | import java.io.InputStream; 18 | import java.util.Properties; 19 | import org.apache.tinkerpop.gremlin.driver.Client; 20 | import org.janusgraph.core.JanusGraph; 21 | import com.ibm.research.ergs.ingestion.graphdb.JanusGraphConnection; 22 | import com.ibm.research.ergs.ingestion.graphdb.JanusGraphConnectionDirectMode; 23 | import com.ibm.research.ergs.ingestion.graphdb.JanusGraphConnectionServerMode; 24 | import com.ibm.research.ergs.ingestion.graphdb.JanusGraphSchemaConstant; 25 | import com.ibm.research.ergs.ingestion.graphdb.SchemaCreator; 26 | 27 | /** 28 | * This class contains function for creating base graph schema. 29 | * 30 | * @author Sumit Neelam (sumit.neelam@in.ibm.com) 31 | * 32 | */ 33 | public class CreateGraphFoundationSchema { 34 | JanusGraphConnection janusGraphConnection; 35 | // SchemaCreator schemaCreator; 36 | InputStream tboxStream; 37 | 38 | /** 39 | * Construcs {@link CreateGraphFoundationSchema} for direct load 40 | * 41 | * @param janusGraph 42 | */ 43 | public CreateGraphFoundationSchema(JanusGraph janusGraph, InputStream tboxStream, 44 | Properties properties) { 45 | janusGraphConnection = new JanusGraphConnectionDirectMode(janusGraph); 46 | this.tboxStream = tboxStream; 47 | InputParameters.setParemeters(properties, null); 48 | } 49 | 50 | /** 51 | * Construcs {@link CreateGraphFoundationSchema} for server based load. 52 | * 53 | * @param client 54 | * @param graphName 55 | */ 56 | public CreateGraphFoundationSchema(Client client, String graphName, InputStream tboxStream, 57 | Properties properties) { 58 | janusGraphConnection = new JanusGraphConnectionServerMode(client, graphName); 59 | this.tboxStream = tboxStream; 60 | InputParameters.setParemeters(properties, null); 61 | } 62 | 63 | /** 64 | * creates base graph schema 65 | */ 66 | public void createGraphFoundationSchema() { 67 | createGraphBaseSchema(janusGraphConnection.getSchemaCreator()); 68 | janusGraphConnection.createOntologyBaseGraph(tboxStream); 69 | } 70 | 71 | private void createGraphBaseSchema(SchemaCreator schemaCreator) { 72 | schemaCreator.createIndexProperty(JanusGraphSchemaConstant.ID_PROPERTY, "string", false, true, 73 | true); 74 | schemaCreator.createIndexProperty(JanusGraphSchemaConstant.ORG_ID_PROPERTY, "string", false, 75 | true, true); 76 | 77 | schemaCreator.createProperty("type", "string", true, true); 78 | schemaCreator.createProperty("totalExtIndex", "integer", false, false); 79 | schemaCreator.createIndexProperty("label_prop", "string", false, true, true); 80 | schemaCreator.createIndexProperty("label_edge", "string", false, true, true); 81 | schemaCreator.createProperty(JanusGraphSchemaConstant.STATNODE_INSTANCE_COUNT_KEY, "long", 82 | false, false); 83 | schemaCreator.createProperty(JanusGraphSchemaConstant.STATNODE_DOMAIN_COUNT_KEY, "long", false, 84 | false); 85 | schemaCreator.createProperty(JanusGraphSchemaConstant.STATNODE_RANGE_COUNT_KEY, "long", false, 86 | false); 87 | schemaCreator.createProperty(JanusGraphSchemaConstant.STATNODE_RANGE_UNIQUE_VALUES_KEY, 88 | "string", true, true); 89 | schemaCreator.createProperty("language", "string", false, false); 90 | schemaCreator.createProperty("datatype", "string", false, false); 91 | schemaCreator.createProperty("isInferred", "boolean", false, false); 92 | schemaCreator.createEdgeLabel("edgeClass"); 93 | schemaCreator.createProperty("ontology", "string", false, false); 94 | schemaCreator.commit(); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/rule/UniqueBindingPredicate.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.rule; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Collections; 15 | import java.util.HashSet; 16 | import java.util.List; 17 | import java.util.Set; 18 | 19 | public class UniqueBindingPredicate extends Predicate { 20 | 21 | private List boundArguments; 22 | 23 | public static UniqueBindingPredicate createUniqueBindingPredicate(PredicateAdornment predAd) { 24 | StringBuffer buf = new StringBuffer(); 25 | buf.append(predAd.getPredicate().getName()+"_"); 26 | for (int i=0;i boundArgumentPositions) { 37 | this(name, arity, boundArgumentPositions, false, false); 38 | } 39 | private UniqueBindingPredicate(String name, int arity, List boundArgumentPositions, boolean isNegated, boolean isOptional) { 40 | super(name, arity, isNegated, isOptional); 41 | this.boundArguments = new ArrayList(boundArgumentPositions); 42 | } 43 | public UniqueBindingPredicate clone() { 44 | return new UniqueBindingPredicate(getName(),getArity(), new ArrayList(boundArguments), isNegated(), isOptional()); 45 | } 46 | 47 | public Predicate negate() { 48 | return new UniqueBindingPredicate(getName(),getArity(), new ArrayList(boundArguments), !isNegated(), isOptional()); 49 | } 50 | public Predicate switchOptionalFlag() { 51 | return new UniqueBindingPredicate(getName(),getArity(), new ArrayList(boundArguments), isNegated(), !isOptional()); 52 | } 53 | public Predicate withoutQualification() { 54 | return new UniqueBindingPredicate(getName(),getArity(), new ArrayList(boundArguments), false, false); 55 | } 56 | 57 | UniqueBindingPredicate cloneWithNonZeroArity() { 58 | return getArity()!=0? 59 | new UniqueBindingPredicate(getName(),getArity(), new ArrayList(boundArguments),isNegated(),isOptional()) 60 | : new UniqueBindingPredicate(getName(),1, new ArrayList(boundArguments), isNegated(), isOptional()); 61 | 62 | 63 | } 64 | public List getBoundArguments() { 65 | return Collections.unmodifiableList(boundArguments); 66 | } 67 | boolean isBoundArgument(int pos) { 68 | return boundArguments.contains(pos); 69 | } 70 | List getBoundVariablesList(AtomicFormula f) { 71 | 72 | assert this.equals(f.getPredicate()); 73 | List ret = new ArrayList(); 74 | Set alreadySeenVars = new HashSet(); 75 | for (int i=0;i variableMapping; 38 | // Set of variables in query 39 | private Set queryVariables; 40 | private MetaData queryMetadata; 41 | private Map aliasForaggregators; 42 | private GenericQueryConversion queryConvertor; 43 | 44 | /** 45 | * Constructs {@link QueryData} 46 | * 47 | * @param queryMetadata {@link MetaData} for quey 48 | * @param queryConvertor {@link GenericQueryConversion} for query 49 | */ 50 | public QueryData(MetaData queryMetadata, GenericQueryConversion queryConvertor) { 51 | this.counter = 0; 52 | this.variableMapping = new HashMap(); 53 | this.queryVariables = new HashSet(); 54 | this.aliasForaggregators = new HashMap(); 55 | this.queryMetadata = queryMetadata; 56 | this.queryConvertor = queryConvertor; 57 | } 58 | 59 | /** 60 | * It adds variable to the {@link Set} Of query variables 61 | * 62 | * @param variables {@link Collection} of the variables to add 63 | */ 64 | public void addQueryVariable(Collection variables) { 65 | this.queryVariables.addAll(variables); 66 | } 67 | 68 | /** 69 | * It adds a single variable to the {@link Set} Of query variables 70 | * 71 | * @param variable variable to add 72 | */ 73 | public void addQueryVariable(String variable) { 74 | this.queryVariables.add(variable); 75 | } 76 | 77 | /** 78 | * Add alias for aggregate operator 79 | * 80 | * @param operator aggregate 81 | * @param alias alias for aggregate 82 | */ 83 | public void addAlias(AggregateOperator operator, String alias) { 84 | this.aliasForaggregators.put(operator, alias); 85 | } 86 | 87 | /** 88 | * 89 | * @return {@link MetaData} for query 90 | */ 91 | public MetaData getQueryMetaData() { 92 | return queryMetadata; 93 | } 94 | 95 | /** 96 | * 97 | * @return variables in query 98 | */ 99 | public Set getQueryVariables() { 100 | return queryVariables; 101 | } 102 | 103 | /** 104 | * 105 | * @param operator {@link AggregateOperator} 106 | * @return alias for aggregate expression 107 | */ 108 | public String getAlias(AggregateOperator operator) { 109 | return aliasForaggregators.get(operator); 110 | } 111 | 112 | /** 113 | * 114 | * @return {@link GenericQueryConversion} for query 115 | */ 116 | public GenericQueryConversion getQueryConvertor() { 117 | return queryConvertor; 118 | } 119 | 120 | /** 121 | * 122 | * @return A new anonymous variable. Used during query translation 123 | */ 124 | public String getAnonymousVariable() { 125 | counter++; 126 | return "temp" + counter; 127 | } 128 | 129 | /** 130 | * 131 | * @return anonymous variable mapped to vat 132 | */ 133 | public String getAnonymousVariable(Var var) { 134 | if (variableMapping.get(var) == null) { 135 | variableMapping.put(var, getAnonymousVariable()); 136 | } 137 | 138 | return variableMapping.get(var); 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /QueryEngine/SPARQLToGremlin/src/main/java/com/ibm/research/ergs/query/metadata/TriplesMetaData.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2020 IBM Corporation and others. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.ibm.research.ergs.query.metadata; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | import org.eclipse.rdf4j.query.algebra.ArbitraryLengthPath; 21 | import org.eclipse.rdf4j.query.algebra.BinaryTupleOperator; 22 | import org.eclipse.rdf4j.query.algebra.StatementPattern; 23 | import org.eclipse.rdf4j.query.algebra.TupleExpr; 24 | import org.eclipse.rdf4j.query.algebra.UnaryTupleOperator; 25 | import org.eclipse.rdf4j.query.algebra.Var; 26 | import com.ibm.research.ergs.query.utils.RDF4JHelper; 27 | 28 | /** 29 | * This class is responsible for extracting StatementPattern containing a given variable 30 | * 31 | * @author Udit Sharma 32 | * 33 | */ 34 | public class TriplesMetaData { 35 | private Map triples; 36 | PropertyTypeMetaData propertyTypeMetadata; 37 | 38 | /** 39 | * Constructs {@link TriplesMetaData} 40 | * 41 | * @param root root of the query parse tree 42 | * @param propertyTypeMetadata {@link PropertyTypeMetaData} for query 43 | */ 44 | public TriplesMetaData(TupleExpr root, PropertyTypeMetaData propertyTypeMetadata) { 45 | super(); 46 | this.triples = new HashMap(); 47 | this.propertyTypeMetadata = propertyTypeMetadata; 48 | process(root); 49 | // System.out.println(triples); 50 | } 51 | 52 | /** 53 | * Get triple having Variable var 54 | * 55 | * @param var variable 56 | * @return {@link StatementPattern} 57 | */ 58 | public StatementPattern getTriples(Var var) { 59 | return triples.get(var); 60 | } 61 | 62 | /** 63 | * Populates triples with {@link StatementPattern} for variables in {@link TupleExpr} 64 | * 65 | * @param tupleExpr 66 | */ 67 | private void process(TupleExpr tupleExpr) { 68 | if (tupleExpr instanceof UnaryTupleOperator) { 69 | process((UnaryTupleOperator) tupleExpr); 70 | } else if (tupleExpr instanceof BinaryTupleOperator) { 71 | process((BinaryTupleOperator) tupleExpr); 72 | } else if (tupleExpr instanceof StatementPattern) { 73 | process((StatementPattern) tupleExpr); 74 | } else if (tupleExpr instanceof ArbitraryLengthPath) { 75 | process((ArbitraryLengthPath) tupleExpr); 76 | } else { 77 | // Ignore 78 | } 79 | } 80 | 81 | /** 82 | * Populates triples with {@link StatementPattern} for variables in {@link UnaryTupleOperator} 83 | * 84 | * @param tupleExpr 85 | */ 86 | private void process(UnaryTupleOperator tupleExpr) { 87 | process(tupleExpr.getArg()); 88 | } 89 | 90 | /** 91 | * Populates triples with {@link StatementPattern} for variables in {@link BinaryTupleOperator} 92 | * 93 | * @param tupleExpr 94 | */ 95 | private void process(BinaryTupleOperator tupleExpr) { 96 | process(tupleExpr.getLeftArg()); 97 | process(tupleExpr.getRightArg()); 98 | } 99 | 100 | /** 101 | * Populates triples with {@link StatementPattern} for variables in {@link StatementPattern} 102 | * 103 | * @param tupleExpr 104 | */ 105 | private void process(StatementPattern tupleExpr) { 106 | // only populate for object and predicate 107 | Var object = tupleExpr.getObjectVar(); 108 | Var predicate = tupleExpr.getPredicateVar(); 109 | if (RDF4JHelper.isVariable(predicate)) { 110 | triples.put(predicate, tupleExpr); 111 | } 112 | if (RDF4JHelper.isVariable(object)) { 113 | triples.put(object, tupleExpr); 114 | } 115 | } 116 | 117 | /** 118 | * Populates triples with {@link StatementPattern} for variables in {@link ArbitraryLengthPath} 119 | * 120 | * @param tupleExpr 121 | */ 122 | private void process(ArbitraryLengthPath tupleExpr) { 123 | process(tupleExpr.getPathExpression()); 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | rdf4j-repository 6 | 7 | com.ibm.research.reasoning 8 | rdf4j 9 | 0.0.1-SNAPSHOT 10 | 11 | 12 | 13 | 14 | org.apache.maven.plugins 15 | maven-compiler-plugin 16 | 3.6.1 17 | 18 | 1.8 19 | 1.8 20 | 21 | 22 | 23 | 24 | 25 | 26 | org.eclipse.rdf4j 27 | rdf4j-bom 28 | ${rdf4j.version} 29 | pom 30 | import 31 | 32 | 33 | com.ibm.research.reasoning 34 | SPARQLQueryEngine 35 | 0.0.1-SNAPSHOT 36 | 37 | 38 | com.ibm.research.reasoning 39 | GraphIngestion 40 | 0.0.1-SNAPSHOT 41 | 42 | 43 | 44 | org.eclipse.rdf4j 45 | rdf4j-queryrender 46 | ${rdf4j.version} 47 | 48 | 49 | org.eclipse.rdf4j 50 | rdf4j-rio-rdfxml 51 | ${rdf4j.version} 52 | 53 | 54 | org.eclipse.rdf4j 55 | rdf4j-rio-turtle 56 | ${rdf4j.version} 57 | 58 | 59 | org.eclipse.rdf4j 60 | rdf4j-repository-api 61 | ${rdf4j.version} 62 | 63 | 64 | org.eclipse.rdf4j 65 | rdf4j-repository-http 66 | ${rdf4j.version} 67 | 68 | 69 | org.eclipse.rdf4j 70 | rdf4j-queryresultio-api 71 | ${rdf4j.version} 72 | 73 | 74 | org.eclipse.rdf4j 75 | rdf4j-queryparser-api 76 | ${rdf4j.version} 77 | 78 | 79 | org.eclipse.rdf4j 80 | rdf4j-queryparser-sparql 81 | ${rdf4j.version} 82 | 83 | 84 | org.eclipse.rdf4j 85 | rdf4j-queryparser-serql 86 | ${rdf4j.version} 87 | 88 | 89 | org.eclipse.rdf4j 90 | rdf4j-repository-manager 91 | test 92 | ${rdf4j.version} 93 | 94 | 95 | org.eclipse.rdf4j 96 | rdf4j-queryalgebra-evaluation 97 | ${rdf4j.version} 98 | 99 | 100 | org.eclipse.rdf4j 101 | rdf4j-queryresultio-text 102 | ${rdf4j.version} 103 | 104 | 105 | org.eclipse.rdf4j 106 | rdf4j-rio-api 107 | ${rdf4j.version} 108 | 109 | 110 | org.eclipse.rdf4j 111 | rdf4j-rio-n3 112 | ${rdf4j.version} 113 | 114 | 115 | org.eclipse.rdf4j 116 | rdf4j-rio-ntriples 117 | ${rdf4j.version} 118 | 119 | 120 | org.eclipse.rdf4j 121 | rdf4j-sparql-testsuite 122 | ${rdf4j.version} 123 | 124 | 125 | net.sourceforge.owlapi 126 | jfact 127 | ${jfact.version} 128 | 129 | 130 | junit 131 | junit 132 | ${junit.version} 133 | test 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/SubPropertyComputation.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql; 12 | 13 | import java.util.Collections; 14 | import java.util.HashSet; 15 | import java.util.Set; 16 | 17 | import org.semanticweb.owlapi.model.OWLDataFactory; 18 | import org.semanticweb.owlapi.model.OWLDataPropertyExpression; 19 | import org.semanticweb.owlapi.model.OWLObjectProperty; 20 | import org.semanticweb.owlapi.model.OWLObjectPropertyExpression; 21 | import org.semanticweb.owlapi.model.OWLOntology; 22 | import org.semanticweb.owlapi.model.OWLPropertyExpression; 23 | import org.semanticweb.owlapi.model.OWLSubPropertyAxiom; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import com.ibm.research.owlql.TaxonomyBuilder.SubsumptionComputation; 28 | import com.ibm.research.utils.OCUtils; 29 | import com.ibm.wala.util.graph.Graph; 30 | 31 | public class SubPropertyComputation implements SubsumptionComputation { 32 | private static final Logger logger = LoggerFactory.getLogger(SubPropertyComputation.class); 33 | 34 | 35 | 36 | public static void main(String[] args) throws Exception { 37 | OWLOntology ont = OCUtils.load(args); 38 | OWLDataFactory fac = ont.getOWLOntologyManager().getOWLDataFactory(); 39 | NormalizedOWLQLTbox tbox = new NormalizedOWLQLTbox(ont); 40 | SubPropertyComputation subcomp = new SubPropertyComputation(tbox); 41 | logger.info("Properties:\n"); 42 | for (OWLObjectProperty op : ont.getObjectPropertiesInSignature()) { 43 | System.out.println(op); 44 | } 45 | assert tbox.getNormalizedAxioms().equals(new NormalizedOWLQLTbox(tbox.getNormalizedOntology()).getNormalizedAxioms()); 46 | /*boolean test = subcomp.isSubumedBy( 47 | fac.getOWLObjectProperty(IRI.create("http://semantics.crl.ibm.com/univ-bench-dl.owl#isStudentOf")), 48 | fac.getOWLObjectProperty(IRI.create("http://semantics.crl.ibm.com/univ-bench-dl.owl#isMemberOf"))); 49 | logger.info("univ#isStudentOf is subproperty of univ#isMemberOf: "+test); 50 | */ 51 | 52 | TaxonomyBuilder taxoBuilder = new TaxonomyBuilder( 53 | ont.getObjectPropertiesInSignature(), 54 | fac.getOWLTopObjectProperty(), 55 | fac.getOWLBottomObjectProperty(), 56 | subcomp); 57 | taxoBuilder.build(); 58 | Graph.TaxoNode> lattice = taxoBuilder.getLattice(); 59 | 60 | logger.info("{}", lattice); 61 | logger.info("Number of direct subsumption tests performed: {}", subcomp.numOfDirectSubsumptionTests); 62 | long size = ont.getObjectPropertiesInSignature().size(); 63 | logger.info("Worst Case number of direct subsumption tests performed: {}^2 = {}",size, size*size); 64 | 65 | 66 | } 67 | private NormalizedOWLQLTbox tbox; 68 | protected int numOfDirectSubsumptionTests; 69 | public SubPropertyComputation(NormalizedOWLQLTbox tbox) { 70 | super(); 71 | this.tbox = tbox; 72 | numOfDirectSubsumptionTests =0; 73 | } 74 | 75 | @Override 76 | public boolean isSubumedBy(OWLPropertyExpression sub, 77 | OWLPropertyExpression sup) { 78 | numOfDirectSubsumptionTests++; 79 | return tbox.isSubProperty(sub, sup); 80 | } 81 | 82 | @Override 83 | public Set getToldSubsumers( 84 | OWLPropertyExpression sub) { 85 | if (!sub.isAnonymous()) { 86 | Set ret = new HashSet(); 87 | Set axioms;// = new HashSet(); 88 | if (sub.isObjectPropertyExpression()) { 89 | axioms = tbox.getNormalizedOntology().getObjectSubPropertyAxiomsForSubProperty( 90 | (OWLObjectPropertyExpression) sub); 91 | } else if (!sub.isAnonymous()) { 92 | axioms = tbox.getNormalizedOntology().getDataSubPropertyAxiomsForSubProperty( 93 | ((OWLDataPropertyExpression) sub).asOWLDataProperty()); 94 | } else { 95 | axioms = Collections.EMPTY_SET; 96 | } 97 | if (axioms!=null) { 98 | for (OWLSubPropertyAxiom ax: axioms) { 99 | assert ax.getSubProperty().equals(sub) : ax+"\n"+sub; 100 | ret.add(ax.getSuperProperty()); 101 | } 102 | } 103 | return ret; 104 | } 105 | return Collections.EMPTY_SET; 106 | } 107 | 108 | 109 | } 110 | -------------------------------------------------------------------------------- /QueryEngine/SPARQLToGremlin/src/main/java/com/ibm/research/ergs/query/utils/PropertyMapping.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2020 IBM Corporation and others. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | package com.ibm.research.ergs.query.utils; 17 | 18 | import java.util.Collection; 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 23 | import org.apache.tinkerpop.gremlin.structure.Column; 24 | 25 | /** 26 | * It is used for fetching type, indexing, existence information for properties in DB. 27 | * 28 | * @author Udit Sharma 29 | * 30 | */ 31 | public class PropertyMapping { 32 | private static String DATATYPE_PROPERTY_ID = "propertyKeys"; 33 | private static String OBJECT_PROPERTY_ID = "edgeLabels"; 34 | private static String CONFLICTING_PROPERTY_ID = "conflicts"; 35 | private static String INDEX_ID = "indexProp"; 36 | 37 | private GraphTraversalSource g; 38 | 39 | /** 40 | * Constructs {@link PropertyMapping} 41 | * 42 | * @param g traversal source 43 | */ 44 | public PropertyMapping(GraphTraversalSource g) { 45 | this.g = g; 46 | } 47 | 48 | /** 49 | * 50 | * @param property property IRI 51 | * @return True if property is present in DB false otherwise 52 | */ 53 | public boolean isProperty(String property) { 54 | return isDataTypeProperty(property) | isObjectProperty(property) 55 | | isConflictingProperty(property); 56 | } 57 | 58 | /** 59 | * 60 | * @param property property IRI 61 | * @return True if property is data type property false otherwise 62 | */ 63 | public boolean isDataTypeProperty(String property) { 64 | try { 65 | return g.V().has("id", DATATYPE_PROPERTY_ID).has(property).hasNext(); 66 | } catch (Exception e) { 67 | return false; 68 | } 69 | } 70 | 71 | /** 72 | * 73 | * @param property property IRI 74 | * @return True if property is object property false otherwise 75 | */ 76 | public boolean isObjectProperty(String property) { 77 | try { 78 | return g.V().has("id", OBJECT_PROPERTY_ID).has(property).hasNext(); 79 | } catch (Exception e) { 80 | return false; 81 | } 82 | } 83 | 84 | /** 85 | * 86 | * @param property property IRI 87 | * @return True if property is conflicting/mixed property false otherwise 88 | */ 89 | public boolean isConflictingProperty(String property) { 90 | try { 91 | return g.V().has("id", CONFLICTING_PROPERTY_ID).has(property).hasNext(); 92 | } catch (Exception e) { 93 | return false; 94 | } 95 | } 96 | 97 | /** 98 | * 99 | * @param property property IRI 100 | * @return True if property is indexed false otherwise 101 | */ 102 | public boolean isIndexed(String property) { 103 | try { 104 | return g.V().has("id", INDEX_ID).has(property).hasNext(); 105 | } catch (Exception e) { 106 | return false; 107 | } 108 | 109 | } 110 | 111 | /** 112 | * 113 | * @return {@link Set} of all the data type properties present in DB 114 | */ 115 | public Set getAllDataTypeProperties() { 116 | GraphTraversal> tr = 117 | g.V().has("id", DATATYPE_PROPERTY_ID).valueMap().select(Column.keys); 118 | return new HashSet(tr.next()); 119 | } 120 | 121 | /** 122 | * 123 | * @return {@link Set} of all the object properties present in DB 124 | */ 125 | public Set getAllObjectProperties() { 126 | GraphTraversal> tr = 127 | g.V().has("id", OBJECT_PROPERTY_ID).valueMap().select(Column.keys); 128 | return new HashSet(tr.next()); 129 | } 130 | 131 | /** 132 | * 133 | * @return {@link Set} of all the conflicting properties present in DB 134 | */ 135 | public Set getAllConflictingProperties() { 136 | GraphTraversal> tr = 137 | g.V().has("id", CONFLICTING_PROPERTY_ID).valueMap().select(Column.keys); 138 | return new HashSet(tr.next()); 139 | } 140 | 141 | /** 142 | * 143 | * @return {@link String} containing TBox for given graph 144 | */ 145 | public String getTbox() { 146 | return (String) g.V().has("id", "tbox").values("ontology").tryNext().orElse(null); 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/ruleref/DeleteUnboundVariables.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql.ruleref; 12 | 13 | import java.util.ArrayList; 14 | import java.util.HashSet; 15 | import java.util.LinkedList; 16 | import java.util.List; 17 | import java.util.Set; 18 | 19 | import org.semanticweb.owlapi.model.OWLClassExpression; 20 | import org.semanticweb.owlapi.model.OWLDataFactory; 21 | import org.semanticweb.owlapi.model.OWLDataPropertyExpression; 22 | import org.semanticweb.owlapi.model.OWLObjectPropertyExpression; 23 | import org.semanticweb.owlapi.model.OWLPropertyExpression; 24 | 25 | import com.ibm.research.owlql.rule.AtomicFormula; 26 | import com.ibm.research.owlql.rule.Expr; 27 | import com.ibm.research.owlql.rule.Rule; 28 | import com.ibm.research.owlql.rule.RuleSystem; 29 | import com.ibm.research.owlql.rule.VariableExpr; 30 | 31 | /** 32 | * Delete unbound variable 33 | * @author achille 34 | * 35 | */ 36 | public class DeleteUnboundVariables { 37 | 38 | protected OWLDataFactory fac; 39 | 40 | public DeleteUnboundVariables(OWLDataFactory fac) { 41 | super(); 42 | this.fac = fac; 43 | } 44 | 45 | public Rule deleteUnboundVariables(Rule r) { 46 | Set uvars = new HashSet(r.getUnboundVariables()); 47 | if (uvars.isEmpty()) { 48 | return r; 49 | } 50 | AtomicFormula newHead = r.getHead(); 51 | List newBody = new LinkedList(); 52 | for (AtomicFormula af: r.getBody()) { 53 | if (!(af.getPredicate() instanceof DLAnnotatedPredicate)) { 54 | newBody.add(af); 55 | continue; 56 | } 57 | DLAnnotatedPredicate p = (DLAnnotatedPredicate) af.getPredicate(); 58 | if (p.getArity()==0) { 59 | newBody.add(af); 60 | } else if (p.getArity() == 1) { 61 | assert p.getClassAnnotation()!= null : p; 62 | Expr e = af.getArguments().get(0); 63 | if (uvars.contains(e)) { 64 | // p_A(unbound) --> p_A() 65 | newBody.add(new AtomicFormula( 66 | p.decreaseArity(), new ArrayList(0))); 67 | } else { 68 | newBody.add(af); 69 | } 70 | } else if (p.getArity() == 2) { 71 | assert p.getPropertyAnnotation()!= null : p; 72 | Expr e1 = af.getArguments().get(0); 73 | Expr e2 = af.getArguments().get(1); 74 | 75 | if (!uvars.contains(e1) && !uvars.contains(e2)) { 76 | newBody.add(af); 77 | } else if (!uvars.contains(e1) && uvars.contains(e2)) { 78 | // p_R(bound, unbound) --> p_some(R)(bound) 79 | OWLPropertyExpression prop = p.getPropertyAnnotation(); 80 | OWLClassExpression some ; 81 | if (prop.isObjectPropertyExpression()) { 82 | some =fac.getOWLObjectSomeValuesFrom( (OWLObjectPropertyExpression) prop, fac.getOWLThing()); 83 | } else { 84 | some =fac.getOWLDataSomeValuesFrom( (OWLDataPropertyExpression) prop, fac.getTopDatatype()); 85 | 86 | } 87 | DLAnnotatedPredicate newPred = new DLAnnotatedPredicate(some, false); 88 | newBody.add(new AtomicFormula(newPred, e1)); 89 | 90 | } else if (uvars.contains(e1) && !uvars.contains(e2)) { 91 | //p_R(unbound, bound) --> p_some(inv(R))(bound) 92 | OWLPropertyExpression prop = p.getPropertyAnnotation(); 93 | OWLClassExpression some ; 94 | if (prop.isObjectPropertyExpression()) { 95 | some =fac.getOWLObjectSomeValuesFrom( ((OWLObjectPropertyExpression) prop).getInverseProperty().getSimplified(), fac.getOWLThing()); 96 | DLAnnotatedPredicate newPred = new DLAnnotatedPredicate(some, false); 97 | newBody.add(new AtomicFormula(newPred, e2)); 98 | } else { 99 | OWLDataPropertyExpression dprop = (OWLDataPropertyExpression) prop; 100 | ExistInverseDataPropertyAnnotatedPredicate newPred = new ExistInverseDataPropertyAnnotatedPredicate(dprop.asOWLDataProperty(), fac); 101 | newBody.add(new AtomicFormula(newPred, e2)); 102 | } 103 | } else { 104 | // p_R(unbound, unbound) --> p_some(R)() 105 | OWLPropertyExpression prop = p.getPropertyAnnotation(); 106 | DLAnnotatedPredicate newPred = new DLAnnotatedPredicate(prop, true); 107 | newBody.add(new AtomicFormula(newPred, new ArrayList(0))); 108 | } 109 | } else { 110 | throw new RuntimeException("Maximum arity for DL predicates is 2: "+ af); 111 | } 112 | } 113 | return new Rule(newHead, newBody,r.getId()); 114 | } 115 | 116 | public RuleSystem deleteUnboundVariables(RuleSystem rs) { 117 | List newRules = new ArrayList(rs.getRules().size()); 118 | for (Rule r:rs.getRules()) { 119 | newRules.add(deleteUnboundVariables(r)); 120 | } 121 | return new RuleSystem(newRules); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/ruleref/DLAnnotatedPredicate.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. All rights reserved. This program and the accompanying 3 | * materials are made available under the terms of the Eclipse Public License v1.0 which accompanies 4 | * this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html 5 | * 6 | * Contributors: IBM Corporation - initial API and implementation 7 | *****************************************************************************/ 8 | package com.ibm.research.owlql.ruleref; 9 | 10 | import org.semanticweb.owlapi.apibinding.OWLManager; 11 | import org.semanticweb.owlapi.model.OWLClassExpression; 12 | import org.semanticweb.owlapi.model.OWLObject; 13 | import org.semanticweb.owlapi.model.OWLObjectPropertyExpression; 14 | import org.semanticweb.owlapi.model.OWLOntologyManager; 15 | import org.semanticweb.owlapi.model.OWLPropertyExpression; 16 | import org.semanticweb.owlapi.util.SimpleRenderer; 17 | import com.ibm.research.owlql.rule.Predicate; 18 | 19 | /** 20 | * A predicate annotated with a DL role or concept expression. 21 | * 22 | * @author achille 23 | * 24 | */ 25 | public class DLAnnotatedPredicate extends Predicate { 26 | 27 | public static final String NAME_PREFIX = "P"; 28 | protected OWLClassExpression classAnnotation; 29 | protected OWLPropertyExpression propAnnotation; 30 | protected static OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); 31 | 32 | private static String getName(int arity, OWLObject annotation) { 33 | // OWLFunctionalSyntaxRenderer render = new OWLFunctionalSyntaxRenderer( ) 34 | SimpleRenderer ren = new SimpleRenderer(); 35 | annotation.accept(ren); 36 | String ret = NAME_PREFIX + "[" + arity + ", " + ren.toString() + "]"; 37 | return ret; 38 | } 39 | 40 | public DLAnnotatedPredicate(OWLClassExpression classAnnotation) { 41 | this(classAnnotation, false); 42 | } 43 | 44 | public DLAnnotatedPredicate(OWLClassExpression classAnnotation, boolean zeroPredicate) { 45 | super(getName(zeroPredicate ? 0 : 1, classAnnotation), zeroPredicate ? 0 : 1); 46 | this.classAnnotation = classAnnotation; 47 | } 48 | 49 | public DLAnnotatedPredicate(OWLPropertyExpression propAnnotation) { 50 | this(propAnnotation, false); 51 | } 52 | 53 | public DLAnnotatedPredicate(OWLPropertyExpression propAnnotation, boolean zeroPredicate) { 54 | super(getName(zeroPredicate ? 0 : 2, 55 | propAnnotation = (propAnnotation instanceof OWLObjectPropertyExpression 56 | ? ((OWLObjectPropertyExpression) propAnnotation).getSimplified() 57 | : propAnnotation)), 58 | zeroPredicate ? 0 : 2); 59 | this.propAnnotation = propAnnotation; 60 | } 61 | 62 | public boolean hasClassAnnotation() { 63 | return classAnnotation != null; 64 | } 65 | 66 | public OWLClassExpression getClassAnnotation() { 67 | return classAnnotation; 68 | } 69 | 70 | public boolean hasPropertyAnnotation() { 71 | return propAnnotation != null; 72 | } 73 | 74 | public OWLPropertyExpression getPropertyAnnotation() { 75 | return propAnnotation; 76 | } 77 | 78 | @Override 79 | public DLAnnotatedPredicate clone() { 80 | return classAnnotation != null ? new DLAnnotatedPredicate(classAnnotation, getArity() == 0) 81 | : new DLAnnotatedPredicate(propAnnotation); 82 | } 83 | 84 | public DLAnnotatedPredicate decreaseArity() { 85 | if (getArity() == 0) { 86 | throw new RuntimeException("Arity already at 0, and cannot be decreased further."); 87 | } 88 | DLAnnotatedPredicate ret = clone(); 89 | ret.arity--; 90 | return ret; 91 | 92 | } 93 | 94 | public OWLObject getAnnotation() { 95 | return classAnnotation != null ? classAnnotation : propAnnotation; 96 | } 97 | 98 | Predicate cloneWithNonZeroArity() { 99 | return clone(); 100 | } 101 | 102 | 103 | @Override 104 | public int hashCode() { 105 | final int prime = 31; 106 | int result = super.hashCode(); 107 | result = prime * result + ((classAnnotation == null) ? 0 : classAnnotation.hashCode()); 108 | result = prime * result + ((propAnnotation == null) ? 0 : propAnnotation.hashCode()); 109 | return result; 110 | } 111 | 112 | @Override 113 | public boolean equals(Object obj) { 114 | if (this == obj) { 115 | return true; 116 | } 117 | if (!super.equals(obj)) { 118 | return false; 119 | } 120 | if (getClass() != obj.getClass()) { 121 | return false; 122 | } 123 | DLAnnotatedPredicate other = (DLAnnotatedPredicate) obj; 124 | if (classAnnotation == null) { 125 | if (other.classAnnotation != null) { 126 | return false; 127 | } 128 | } else if (!classAnnotation.equals(other.classAnnotation)) { 129 | return false; 130 | } 131 | if (propAnnotation == null) { 132 | if (other.propAnnotation != null) { 133 | return false; 134 | } 135 | } else if (!propAnnotation.equals(other.propAnnotation)) { 136 | return false; 137 | } 138 | return true; 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /IngestionPipeline/GraphIngestion/src/main/java/com/ibm/research/ergs/ingestion/loader/Main.java: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************* 3 | * Copyright 2020 IBM Corporation and others. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | *******************************************************************************/ 15 | package com.ibm.research.ergs.ingestion.loader; 16 | 17 | import java.io.File; 18 | import java.io.FileInputStream; 19 | import java.io.FileReader; 20 | import java.io.InputStream; 21 | import java.util.Properties; 22 | import org.apache.tinkerpop.gremlin.driver.Client; 23 | import org.apache.tinkerpop.gremlin.driver.Cluster; 24 | import org.apache.tinkerpop.gremlin.driver.MessageSerializer; 25 | import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0; 26 | import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper; 27 | import org.eclipse.rdf4j.rio.RDFFormat; 28 | import org.janusgraph.core.JanusGraph; 29 | import org.janusgraph.core.JanusGraphFactory; 30 | import org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry; 31 | 32 | 33 | /** 34 | * This is main class for running ingestion modele. This is used for only for checking ingestion 35 | * module separately. 36 | * 37 | * @author Sumit Neelam (sumit.neelam@in.ibm.com) 38 | * 39 | */ 40 | public class Main { 41 | public static void main(String args[]) { 42 | 43 | if (args.length < 1) { 44 | System.out.println("Insufficient arguments: property file missing"); 45 | System.exit(0); 46 | } 47 | Properties properties = new Properties(); 48 | try { 49 | properties.load(new FileReader(args[0])); 50 | } catch (Exception e) { 51 | System.out.println("Exception in input property File: " + e); 52 | System.exit(0); 53 | } 54 | 55 | long startTime = System.nanoTime(); 56 | 57 | boolean SERVER_MODE = false; 58 | LoadRDFData loadRDFData; 59 | 60 | if (SERVER_MODE) { 61 | GryoMapper.Builder kryo = GryoMapper.build().addRegistry(JanusGraphIoRegistry.getInstance()); 62 | MessageSerializer serializer = new GryoMessageSerializerV3d0(kryo); 63 | Cluster cluster = Cluster.build("localhost").serializer(serializer).create(); 64 | Client client = cluster.connect("123456"); 65 | 66 | String tboxFile = "src/test/resources/univ-bench.owl"; 67 | InputStream i = null; 68 | try { 69 | i = new FileInputStream(tboxFile); 70 | } catch (Exception e) { 71 | e.printStackTrace(); 72 | System.exit(0); 73 | } 74 | 75 | startTime = System.nanoTime(); 76 | CreateGraphFoundationSchema schemaCreator = 77 | new CreateGraphFoundationSchema(client, "lubmtest", i, properties); 78 | schemaCreator.createGraphFoundationSchema(); 79 | 80 | loadRDFData = new LoadRDFData(client, "lubmtest", properties); 81 | File loadDirectory = new File("src/main/resources/lubm1u-1File"); 82 | RDFFormat rdfFormat = RDFFormat.RDFXML; 83 | String baseURI = "http://swat.cse.lehigh.edu/onto/univ-bench.owl"; 84 | 85 | loadRDFData.loadDirectoryAllFiles(loadDirectory, rdfFormat, baseURI); 86 | 87 | client.close(); 88 | cluster.close(); 89 | } else { 90 | String tboxFile = "src/test/resources/univ-bench.owl"; 91 | String janusGraphPropFile = "src/test/resources/janusgraph-hbase.properties"; 92 | String dataDir = "src/test/resources/lubm1u"; 93 | RDFFormat rdfFormat = RDFFormat.RDFXML; 94 | String baseURI = "http://swat.cse.lehigh.edu/onto/univ-bench.owl"; 95 | 96 | InputStream i = null; 97 | try { 98 | i = new FileInputStream(tboxFile); 99 | } catch (Exception e) { 100 | e.printStackTrace(); 101 | System.exit(0); 102 | } 103 | JanusGraph janusGraph = 104 | JanusGraphFactory.open(janusGraphPropFile); 105 | 106 | startTime = System.nanoTime(); 107 | CreateGraphFoundationSchema schemaCreator = 108 | new CreateGraphFoundationSchema(janusGraph, i, properties); 109 | schemaCreator.createGraphFoundationSchema(); 110 | 111 | loadRDFData = new LoadRDFData(janusGraph, properties); 112 | 113 | File loadDirectory = new File(dataDir); 114 | 115 | loadRDFData.loadDirectoryAllFiles(loadDirectory, rdfFormat, baseURI); 116 | // loadRDFData.loadFromFile(new File("src/main/resources/univ-bench.owl"), rdfFormat, 117 | // baseURI); 118 | janusGraph.close(); 119 | } 120 | 121 | long totalExecTime = System.nanoTime() - startTime; 122 | System.out.println("\n\nLoading time: " + totalExecTime * 1.0 / 1E6); 123 | System.exit(0); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/SubClassComputation.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql; 12 | 13 | import java.util.Collections; 14 | import java.util.HashMap; 15 | import java.util.HashSet; 16 | import java.util.Map; 17 | import java.util.Set; 18 | 19 | import org.semanticweb.owlapi.model.AxiomType; 20 | import org.semanticweb.owlapi.model.OWLClass; 21 | import org.semanticweb.owlapi.model.OWLClassExpression; 22 | import org.semanticweb.owlapi.model.OWLDataFactory; 23 | import org.semanticweb.owlapi.model.OWLOntology; 24 | import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | 28 | import com.ibm.research.owlql.TaxonomyBuilder.SubsumptionComputation; 29 | import com.ibm.research.utils.OCUtils; 30 | import com.ibm.wala.util.graph.Graph; 31 | 32 | public class SubClassComputation implements SubsumptionComputation { 33 | private static final Logger logger = LoggerFactory.getLogger(SubClassComputation.class); 34 | 35 | public static void main(String[] args) throws Exception { 36 | OWLOntology ont = OCUtils.load(args); 37 | OWLDataFactory fac = ont.getOWLOntologyManager().getOWLDataFactory(); 38 | NormalizedOWLQLTbox tbox = new NormalizedOWLQLTbox(ont); 39 | SubClassComputation subcomp = new SubClassComputation(tbox); 40 | logger.info("Classes:\n"); 41 | for (OWLClass c : ont.getClassesInSignature()) { 42 | System.out.println(c); 43 | } 44 | assert tbox.getNormalizedAxioms().equals(new NormalizedOWLQLTbox(tbox.getNormalizedOntology()).getNormalizedAxioms()); 45 | /*boolean test = subcomp.isSubumedBy( 46 | fac.getOWLObjectProperty(IRI.create("http://semantics.crl.ibm.com/univ-bench-dl.owl#isStudentOf")), 47 | fac.getOWLObjectProperty(IRI.create("http://semantics.crl.ibm.com/univ-bench-dl.owl#isMemberOf"))); 48 | logger.info("univ#isStudentOf is subproperty of univ#isMemberOf: "+test); 49 | */ 50 | 51 | 52 | TaxonomyBuilder taxoBuilder = new TaxonomyBuilder( 53 | new HashSet(ont.getClassesInSignature()), 54 | fac.getOWLThing(), 55 | fac.getOWLNothing(), 56 | subcomp); 57 | taxoBuilder.build(); 58 | Graph.TaxoNode> lattice = taxoBuilder.getLattice(); 59 | 60 | logger.info("{}", lattice); 61 | logger.info("Number of direct subsumption tests performed: {}", subcomp.numOfDirectSubsumptionTests); 62 | long size = ont.getClassesInSignature().size(); 63 | logger.info("Worst Case number of direct subsumption tests performed: {}^2 = {}",size, size*size); 64 | 65 | 66 | } 67 | private NormalizedOWLQLTbox tbox; 68 | protected int numOfDirectSubsumptionTests; 69 | 70 | Map> sub2ToldSubsumers; 71 | public SubClassComputation(NormalizedOWLQLTbox tbox) { 72 | super(); 73 | numOfDirectSubsumptionTests =0; 74 | this.tbox = tbox; 75 | sub2ToldSubsumers = new HashMap>(); 76 | Set axioms = tbox.getNormalizedOntology().getAxioms(AxiomType.SUBCLASS_OF); 77 | int maxToldSubsumers =0; 78 | if (axioms!=null) { 79 | for (OWLSubClassOfAxiom ax: axioms) { 80 | OWLClassExpression sub = ax.getSubClass(); 81 | OWLClassExpression sup = ax.getSuperClass(); 82 | //if (!sub.isAnonymous()) 83 | { 84 | Set s = sub2ToldSubsumers.get(sub); 85 | if (s == null) { 86 | s = new HashSet(); 87 | sub2ToldSubsumers.put(sub, s); 88 | } 89 | s.add(sup); 90 | maxToldSubsumers = Math.max(s.size(), maxToldSubsumers); 91 | } 92 | } 93 | } 94 | logger.debug("Max told subsumers: {}", maxToldSubsumers); 95 | 96 | } 97 | 98 | @Override 99 | public boolean isSubumedBy(OWLClassExpression sub, 100 | OWLClassExpression sup) { 101 | numOfDirectSubsumptionTests++; 102 | return tbox.isSubClass(sub, sup); 103 | } 104 | 105 | @Override 106 | public Set getToldSubsumers(OWLClassExpression sub) { 107 | /*if (!sub.isAnonymous()) { 108 | Set ret = new HashSet(); 109 | Set axioms = tbox.getNormalizedOntology().getSubClassAxiomsForSubClass(sub.asOWLClass()); 110 | if (axioms!=null) { 111 | for (OWLSubClassOfAxiom ax: axioms) { 112 | assert ax.getSubClass().equals(sub) : ax+"\n"+sub; 113 | ret.add(ax.getSuperClass()); 114 | } 115 | } 116 | return ret; 117 | }*/ 118 | Set ret = sub2ToldSubsumers.get(sub); 119 | 120 | return ret!=null? ret : Collections.EMPTY_SET; 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /IngestionPipeline/GraphIngestion/src/main/java/com/ibm/research/ergs/ingestion/loader/InputParameters.java: -------------------------------------------------------------------------------- 1 | 2 | /******************************************************************************* 3 | * Copyright 2020 IBM Corporation and others. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | * or implied. See the License for the specific language governing permissions and limitations under 13 | * the License. 14 | *******************************************************************************/ 15 | package com.ibm.research.ergs.ingestion.loader; 16 | 17 | import java.util.Arrays; 18 | import java.util.HashSet; 19 | import java.util.Properties; 20 | 21 | /** 22 | * Class holds loading related setting and configuration options 23 | * 24 | * @author Sumit Neelam (sumit.neelam@in.ibm.com) 25 | * 26 | */ 27 | public class InputParameters { 28 | public static String TBOXFILE; 29 | public static boolean BUILDSUMMARY; 30 | public static int COMMIT_FREQUENCY; 31 | public static int NUM_THREADS; 32 | 33 | public static String GRAPH_NAME; 34 | public static String EXTERNAL_INDEX_PREFIX; 35 | 36 | public static HashSet GRAPH_INDEX; 37 | public static HashSet EXTERNAL_INDEX_BOTH; 38 | public static HashSet EXTERNAL_INDEX_STRING; 39 | public static HashSet EXTERNAL_INDEX_TEXT; 40 | 41 | public static boolean BUILD_GRAPH_INDEX_ALL_PROPS = false; 42 | public static boolean BUILD_EXTERNAL_INDEX_ALL_PROPS = false; 43 | public static String ALL_EXTERNAL_INDEXTYPE; 44 | 45 | public static boolean BUILD_ALLPROP_INDEX = false; 46 | 47 | public static boolean ENABLE_FORWARD_CHAINING = false; 48 | 49 | public static boolean ADV_LOADING = true; 50 | 51 | public static boolean IS_FULL_ABOX = true; 52 | 53 | public static void setParemeters(Properties properties, String graphName) { 54 | TBOXFILE = properties.getProperty("input.ontology"); 55 | String buildSummary = properties.getProperty("input.buildsummary", "false"); 56 | String commitFrequency = properties.getProperty("input.commitfrequency", "10000"); 57 | String numThreads = properties.getProperty("input.numthreads", "1"); 58 | String graphIndex = properties.getProperty("input.indexprop"); 59 | String textExternalIndex = properties.getProperty("input.textindexprop"); 60 | String stringExternalIndex = properties.getProperty("input.stringindexprop"); 61 | String textStringExternalIndex = properties.getProperty("input.textstringindexprop"); 62 | String buildAllPropIndex = properties.getProperty("input.buildallpropindex", "false"); 63 | String enableForwardChaining = properties.getProperty("input.enableforwardchaining", "false"); 64 | 65 | GRAPH_INDEX = new HashSet(); 66 | EXTERNAL_INDEX_BOTH = new HashSet(); 67 | EXTERNAL_INDEX_STRING = new HashSet(); 68 | EXTERNAL_INDEX_TEXT = new HashSet(); 69 | 70 | BUILDSUMMARY = false; 71 | 72 | GRAPH_NAME = graphName; 73 | 74 | if (buildSummary != null) { 75 | if (buildSummary.equalsIgnoreCase("true")) { 76 | BUILDSUMMARY = true; 77 | } 78 | } 79 | if (graphIndex != null) { 80 | if (graphIndex.equalsIgnoreCase("all")) { 81 | BUILD_GRAPH_INDEX_ALL_PROPS = true; 82 | } else { 83 | GRAPH_INDEX.addAll(Arrays.asList(graphIndex.split(","))); 84 | } 85 | } 86 | if (textExternalIndex != null) { 87 | if (textExternalIndex.equalsIgnoreCase("all")) { 88 | BUILD_EXTERNAL_INDEX_ALL_PROPS = true; 89 | ALL_EXTERNAL_INDEXTYPE = "text"; 90 | } else { 91 | EXTERNAL_INDEX_TEXT.addAll(Arrays.asList(textExternalIndex.split(","))); 92 | } 93 | } 94 | if (stringExternalIndex != null) { 95 | if (stringExternalIndex.equalsIgnoreCase("all")) { 96 | BUILD_EXTERNAL_INDEX_ALL_PROPS = true; 97 | ALL_EXTERNAL_INDEXTYPE = "string"; 98 | } else { 99 | EXTERNAL_INDEX_STRING.addAll(Arrays.asList(stringExternalIndex.split(","))); 100 | } 101 | } 102 | if (textStringExternalIndex != null) { 103 | if (textStringExternalIndex.equalsIgnoreCase("all")) { 104 | BUILD_EXTERNAL_INDEX_ALL_PROPS = true; 105 | ALL_EXTERNAL_INDEXTYPE = "textstring"; 106 | } else { 107 | EXTERNAL_INDEX_BOTH.addAll(Arrays.asList(textStringExternalIndex.split(","))); 108 | } 109 | } 110 | if (buildAllPropIndex != null) { 111 | if (buildAllPropIndex.equalsIgnoreCase("true")) { 112 | BUILD_ALLPROP_INDEX = true; 113 | } 114 | } 115 | if (enableForwardChaining != null) { 116 | if (enableForwardChaining.equalsIgnoreCase("true")) { 117 | ENABLE_FORWARD_CHAINING = true; 118 | } 119 | } 120 | COMMIT_FREQUENCY = Integer.parseInt(commitFrequency); 121 | NUM_THREADS = Integer.parseInt(numThreads); 122 | EXTERNAL_INDEX_PREFIX = graphName + "Index"; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /QueryEngine/QueryExpansion/src/com/ibm/research/owlql/Taxonomy.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2015 IBM Corporation. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * IBM Corporation - initial API and implementation 10 | *****************************************************************************/ 11 | package com.ibm.research.owlql; 12 | 13 | import java.util.Map; 14 | import java.util.Set; 15 | 16 | import org.semanticweb.owlapi.model.OWLClassExpression; 17 | import org.semanticweb.owlapi.model.OWLDataProperty; 18 | import org.semanticweb.owlapi.model.OWLObjectInverseOf; 19 | import org.semanticweb.owlapi.model.OWLObjectProperty; 20 | import org.semanticweb.owlapi.model.OWLPropertyExpression; 21 | 22 | public interface Taxonomy { 23 | 24 | public void build(); 25 | /** 26 | * returns wether sub is a subclass of sup or is equivalent to sup 27 | * @param normalizedSub 28 | * @param normalizedSup 29 | * @return 30 | */ 31 | public boolean isSubClass(OWLClassExpression normalizedSub, 32 | OWLClassExpression normalizedSup); 33 | /** 34 | * returns wether sub is a sub property of sup or is equivalent to sup 35 | * @param normalizedSub 36 | * @param normalizedSup 37 | * @return 38 | */ 39 | 40 | public boolean isSubProperty(OWLPropertyExpression normalizedSub, 41 | OWLPropertyExpression normalizedSup); 42 | /** 43 | * returns subsumees and equivalent class expressions 44 | * @param sup 45 | * @return 46 | */ 47 | public Set getAllSubsumees(OWLClassExpression sup); 48 | /** 49 | * returns subsumers and equivalent class expressions 50 | * @param sup 51 | * @return 52 | */ 53 | public Set getAllSubsumers(OWLClassExpression sub); 54 | /** 55 | * returns subsumees and equivalent class expressions 56 | * @param sup 57 | * @return 58 | */ 59 | public Set getAllSubproperties(OWLPropertyExpression sup); 60 | /** 61 | * computes the most general subsumees 62 | * @param classes 63 | * @param properties 64 | * @return 65 | */ 66 | public Set getMostGeneralSubsumees(Set classes, Set properties); 67 | /** 68 | * computes the most general subsumees. 69 | * This is a generalization of the concept of most general subsumees. 70 | * First some definitions: 71 | *
      72 | *
    1. A ConceptPropertyWildcard represents either an atomic concept, an atomic property or the inverse of an atomic property.
    2. 73 | *
    3. A PropertyWildcard represents either an atomic property or the inverse of an atomic property. 74 | *
    4. A ConceptWildcard represents an atomic concept
    5. 75 | *
    76 | * Let C be the set of atomic concept in the Tbox, and P be the set of atomic properties and inverses of atomic properties. 77 | * Let n = conceptPropertyWildcards, m = propertyWildcards, l = conceptWildcards, 78 | * Q = (C union P)^n * P^m * C^l ( * : cartesian product) 79 | * 80 | * The returned value is UNION{ q in Q} getMostGeneralSubsumees(elements(q) union classes union properties) 81 | * 82 | * @param classes atomic classes 83 | * @param properties properties or inverse properties 84 | * @param conceptPropertyWildcards number of ConceptRoleWildCards. 85 | * @param propertyWildcards. 86 | * @param conceptWildcards 87 | * @return 88 | */ 89 | public Set getMostGeneralSubsumees(Set classes, Set properties, 90 | int conceptPropertyWildcards, int propertyWildcards, int conceptWildcards); 91 | /** 92 | * returns a map associating a number of wildcards processed (>= minimalNumberOfConceptWildcardsToReport) to the most general subsumees for the corresponding number of wildcards. 93 | * In other words, for k>= minimalNumberOfConceptWildcardsToReport), map.get(k) = getMostGeneralSubsumees(classes, properties, 0,0,k) . 94 | * NOTE: for k>= minimalNumberOfConceptWildcardsToReport, map.get(k) may be null if getMostGeneralSubsumees(classes, properties, 0,0,k).isEmpty(). 95 | * @param classes 96 | * @param properties 97 | * @param conceptWildcardsToProcess 98 | * @param minimalNumberOfConceptWildcardsToReport 99 | * @return 100 | */ 101 | public Map> computeMostGeneralSubsumees( 102 | Set classes, 103 | Set properties, 104 | int conceptWildcardsToProcess, 105 | int minimalNumberOfConceptWildcardsToReport); 106 | 107 | public Set applyPropertyWildcard(Set mostGeneralSubmees) ; 108 | 109 | public Set getUnsatisfiableClassExpressions(); 110 | public Set getUnsatisfiablePropertyExpressions(); 111 | 112 | 113 | public Set getInverses(); 114 | public Set getObjectProperties(); 115 | public Set getDataProperties(); 116 | public NormalizedOWLQLTbox getTbox(); 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /RDF4J/rdf4j-repository/src/main/java/com/ibm/research/ergs/rdf4j/query/AbstractExpressiveReasoningGraphStoreQuery.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2020 IBM Corporation and others. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | *******************************************************************************/ 14 | package com.ibm.research.ergs.rdf4j.query; 15 | 16 | import org.eclipse.rdf4j.model.IRI; 17 | import org.eclipse.rdf4j.model.Literal; 18 | import org.eclipse.rdf4j.model.Value; 19 | import org.eclipse.rdf4j.query.BindingSet; 20 | import org.eclipse.rdf4j.query.Dataset; 21 | import org.eclipse.rdf4j.query.Query; 22 | import org.eclipse.rdf4j.query.impl.MapBindingSet; 23 | import com.ibm.research.ergs.query.engine.SPARQLQueryProcessor; 24 | 25 | /** 26 | * SPARQL query for ERGS repository 27 | * 28 | * @author Udit Sharma 29 | * 30 | */ 31 | public abstract class AbstractExpressiveReasoningGraphStoreQuery implements Query { 32 | protected MapBindingSet bindings = new MapBindingSet(); 33 | protected String queryString; 34 | protected String baseIRI; 35 | protected SPARQLQueryProcessor queryProcessor; 36 | 37 | /** 38 | * It constructs SPARQL query for ERGS repository 39 | * 40 | * @param queryProcessor query execution engine 41 | * @param queryString query string 42 | * @param baseIRI base IRI for the query 43 | */ 44 | protected AbstractExpressiveReasoningGraphStoreQuery(SPARQLQueryProcessor queryProcessor, 45 | String queryString, String baseIRI) { 46 | this.queryProcessor = queryProcessor; 47 | this.queryString = queryString; 48 | this.baseIRI = baseIRI; 49 | } 50 | 51 | @Override 52 | public void setBinding(String name, Value value) { 53 | bindings.addBinding(name, value); 54 | 55 | } 56 | 57 | @Override 58 | public void removeBinding(String name) { 59 | bindings.removeBinding(name); 60 | 61 | } 62 | 63 | @Override 64 | public void clearBindings() { 65 | bindings.clear(); 66 | 67 | } 68 | 69 | @Override 70 | public BindingSet getBindings() { 71 | return bindings; 72 | } 73 | 74 | @Override 75 | public void setDataset(Dataset dataset) { 76 | // throw new UnsupportedOperationException(); 77 | 78 | } 79 | 80 | @Override 81 | public Dataset getDataset() { 82 | throw new UnsupportedOperationException(); 83 | } 84 | 85 | @Override 86 | public void setIncludeInferred(boolean includeInferred) { 87 | if (!includeInferred) { 88 | throw new UnsupportedOperationException("Inference can't be disabled."); 89 | } 90 | } 91 | 92 | @Override 93 | public boolean getIncludeInferred() { 94 | return false; 95 | } 96 | 97 | @Override 98 | public void setMaxQueryTime(int maxQueryTime) { 99 | throw new UnsupportedOperationException(); 100 | 101 | } 102 | 103 | @Override 104 | public int getMaxQueryTime() { 105 | throw new UnsupportedOperationException(); 106 | } 107 | 108 | protected String getQueryString() { 109 | if (bindings.size() == 0) { 110 | return queryString; 111 | } 112 | String qry = queryString; 113 | int b = qry.indexOf('{'); 114 | String select = qry.substring(0, b); 115 | String where = qry.substring(b); 116 | for (String name : bindings.getBindingNames()) { 117 | String replacement = getReplacement(bindings.getValue(name)); 118 | if (replacement != null) { 119 | String pattern = "[\\?\\$]" + name + "(?=\\W)"; 120 | select = select.replaceAll(pattern, ""); 121 | where = where.replaceAll(pattern, replacement); 122 | } 123 | } 124 | return select + where; 125 | } 126 | 127 | private String getReplacement(Value value) { 128 | StringBuilder sb = new StringBuilder(); 129 | if (value instanceof IRI) { 130 | return appendValue(sb, (IRI) value).toString(); 131 | } else if (value instanceof Literal) { 132 | return appendValue(sb, (Literal) value).toString(); 133 | } else { 134 | throw new IllegalArgumentException("BNode references not supported by SPARQL end-points"); 135 | } 136 | } 137 | 138 | private StringBuilder appendValue(StringBuilder sb, IRI uri) { 139 | sb.append("<").append(uri.stringValue()).append(">"); 140 | return sb; 141 | } 142 | 143 | private StringBuilder appendValue(StringBuilder sb, Literal lit) { 144 | sb.append('"'); 145 | sb.append(lit.getLabel().replace("\"", "\\\"")); 146 | sb.append('"'); 147 | 148 | if (lit.getLanguage() != null) { 149 | sb.append('@'); 150 | sb.append(lit.getLanguage()); 151 | } else if (lit.getDatatype() != null) { 152 | sb.append("^^<"); 153 | sb.append(lit.getDatatype().stringValue()); 154 | sb.append('>'); 155 | } 156 | return sb; 157 | } 158 | 159 | } 160 | --------------------------------------------------------------------------------