├── .gitignore ├── LICENSE ├── README.md ├── data └── README.md ├── geotriples-core ├── pom.xml └── src │ └── main │ ├── assembly │ └── bin.xml │ └── java │ └── eu │ └── linkedeodata │ └── geotriples │ ├── GeoTriplesCMD.java │ ├── dump_rdf.java │ └── generate_mapping.java ├── geotriples-evaluation ├── pom.xml └── src │ └── main │ └── java │ └── eu │ └── linkedeodata │ └── geotriples │ └── PrintTimeStats.java ├── geotriples-gui ├── pom.xml ├── resources │ ├── AddSourceTable.bxml │ ├── AddSourceTable.json │ ├── GeoTriplesWindow.bxml │ ├── GeoTriplesWindow.json │ ├── GeoTriplesWindow_fr.json │ ├── GeoTriplesWindow_it.json │ ├── MenuBar.bxml │ ├── OpenConnection.json │ ├── add.png │ ├── database_tab.bxml │ ├── delete.png │ ├── detail_pane.bxml │ ├── dumprdf.gif │ ├── generatemapping.gif │ ├── geo_triples_window.bxml │ ├── openconnection.bxml │ ├── sqlconnectionparameters.bxml │ ├── sqlconnectionparameters.json │ ├── table_package.bxml │ └── table_package.bxml.orig └── src │ └── main │ ├── assembly │ └── bin.xml │ └── java │ └── eu │ └── linkedeodata │ └── geotriples │ └── gui │ ├── AddSourceTable.java │ ├── AmountBindMapping.java │ ├── BaseIRIValidator.java │ ├── ChangeCellRenderer.java │ ├── ChangeMapping.java │ ├── CurrencyValidator.java │ ├── CustomOutputStream.java │ ├── GeoTriples.java │ ├── GeoTriplesWindow.java │ ├── OpenConnection.java │ ├── ShapefileFakeConnection.java │ ├── SourceTable.java │ ├── SqlForm.java │ ├── SqlForm.java.orig │ ├── TablePackage.java │ ├── ValueMapping.java │ ├── VolumeMapping.java │ ├── go-down.png │ ├── go-up.png │ └── window.bxml ├── geotriples-ontop ├── pom.xml └── src │ └── main │ └── java │ └── eu │ └── linkedeodata │ └── geotriples │ ├── BGPGroupGenerator.java │ ├── BasicGraphPatternExtractor.java │ ├── NullSesameDataset.java │ └── QueryOntop.java ├── geotriples-processors ├── geotriples-r2rml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ ├── d2rq │ │ ├── d2r_query.java │ │ ├── dump_rdf.java │ │ ├── generate_mapping.java │ │ ├── server.java │ │ └── validate.java │ │ ├── de │ │ └── fuberlin │ │ │ └── wiwiss │ │ │ └── pubby │ │ │ └── negotiation │ │ │ ├── ContentTypeNegotiator.java │ │ │ ├── MediaRangeSpec.java │ │ │ └── PubbyNegotiator.java │ │ ├── eu │ │ └── linkedeodata │ │ │ └── geotriples │ │ │ ├── Config.java │ │ │ ├── GMLLiteral.java │ │ │ ├── GTransormationFunctions.java │ │ │ ├── GeneralCompatibleRelationGroup.java │ │ │ ├── GeneralCompiledMapping.java │ │ │ ├── GeneralConnection.java │ │ │ ├── GeneralFindQuery.java │ │ │ ├── GeneralGraphD2RQ.java │ │ │ ├── GeneralIterator.java │ │ │ ├── GeneralJoinOptimizer.java │ │ │ ├── GeneralMappingGenerator.java │ │ │ ├── GeneralMappingStyle.java │ │ │ ├── GeneralNodeRelation.java │ │ │ ├── GeneralNodeRelationOrderer.java │ │ │ ├── GeneralNodeRelationProjecter.java │ │ │ ├── GeneralNodeRelationUtil.java │ │ │ ├── GeneralParser.java │ │ │ ├── GeneralQueryIterTableSQL.java │ │ │ ├── GeneralR2RMLCompiler.java │ │ │ ├── GeneralR2RMLTarget.java │ │ │ ├── GeneralResourceCollection.java │ │ │ ├── GeneralResultRow.java │ │ │ ├── GeneralResultSet.java │ │ │ ├── GeneralSelectStatementBuilder.java │ │ │ ├── GeneralSystemLoader.java │ │ │ ├── GeneralTripleQueryIter.java │ │ │ ├── GeneralTripleRelation.java │ │ │ ├── GeneralURIMakerRule.java │ │ │ ├── KeyGenerator.java │ │ │ ├── RowHandler.java │ │ │ ├── TableDefUtils.java │ │ │ ├── WKTLiteral.java │ │ │ ├── WP2.java │ │ │ ├── WP2Model.java │ │ │ ├── WP2ModelFactory.java │ │ │ ├── geotiff │ │ │ ├── GeoTiffParser.java │ │ │ ├── GeoTiffReaderExample.java │ │ │ ├── GeoTiffResultRow.java │ │ │ └── KeyGenerator.java │ │ │ ├── gui │ │ │ ├── ColumnReceipt.java │ │ │ └── RecipeMapping.java │ │ │ ├── kml │ │ │ ├── KMLCommandLineTool.java │ │ │ ├── KMLConnection.java │ │ │ ├── KMLManagement.java │ │ │ ├── KMLParser.java │ │ │ ├── KMLSystemLoader.java │ │ │ ├── dump_rdf.java │ │ │ └── generate_mapping.java │ │ │ ├── shapefile │ │ │ ├── ShapeFileParser.java │ │ │ ├── ShapeFileParserGDAL.java │ │ │ ├── ShapefileCommandLineTool.java │ │ │ ├── ShapefileConnection.java │ │ │ ├── ShapefileSystemLoader.java │ │ │ ├── TestGeneration.java │ │ │ ├── TestShapefileParser.java │ │ │ ├── dump_rdf.java │ │ │ └── generate_mapping.java │ │ │ ├── utils │ │ │ ├── John_BaseXMLWriter.java │ │ │ ├── John_PairEntry.java │ │ │ ├── John_Relation.java │ │ │ ├── John_Unparser.java │ │ │ └── OntologyLoader.java │ │ │ └── writers │ │ │ ├── WP2AbbreviatedWriter.java │ │ │ ├── WP2NTripleWriter.java │ │ │ ├── WP2RDFWriterFImpl.java │ │ │ ├── WP2RDFXMLWriter.java │ │ │ └── dimis │ │ │ ├── N3WP2Writer.java │ │ │ ├── WP2N3JenaWriterCommon.java │ │ │ ├── WP2N3JenaWriterPP.java │ │ │ ├── WP2N3JenaWriterTriples.java │ │ │ └── WP2N3TurtleJenaWriter.java │ │ └── org │ │ └── d2rq │ │ ├── CommandLineTool.java │ │ ├── CompiledMapping.java │ │ ├── D2RQException.java │ │ ├── D2RQOptions.java │ │ ├── Log4jHelper.java │ │ ├── ResourceCollection.java │ │ ├── ResourceDescriber.java │ │ ├── SystemLoader.java │ │ ├── algebra │ │ ├── DownloadRelation.java │ │ ├── NodeRelation.java │ │ ├── NodeRelationOrderer.java │ │ ├── NodeRelationProjecter.java │ │ ├── NodeRelationUtil.java │ │ └── TripleRelation.java │ │ ├── assembler │ │ └── D2RQAssembler.java │ │ ├── csv │ │ ├── CSV.java │ │ └── TranslationTableParser.java │ │ ├── db │ │ ├── ResultRow.java │ │ ├── SQLConnection.java │ │ ├── SQLIterator.java │ │ ├── SQLScriptLoader.java │ │ ├── SelectStatementBuilder.java │ │ ├── expr │ │ │ ├── Add.java │ │ │ ├── BinaryOperator.java │ │ │ ├── BooleanToIntegerCaseExpression.java │ │ │ ├── ColumnExpr.java │ │ │ ├── ColumnListEquality.java │ │ │ ├── Concatenation.java │ │ │ ├── Conjunction.java │ │ │ ├── Constant.java │ │ │ ├── Disjunction.java │ │ │ ├── Divide.java │ │ │ ├── Equality.java │ │ │ ├── Expression.java │ │ │ ├── GreaterThan.java │ │ │ ├── GreaterThanOrEqual.java │ │ │ ├── LessThan.java │ │ │ ├── LessThanOrEqual.java │ │ │ ├── Multiply.java │ │ │ ├── Negation.java │ │ │ ├── NotNull.java │ │ │ ├── SQLExpression.java │ │ │ ├── Subtract.java │ │ │ └── UnaryMinus.java │ │ ├── op │ │ │ ├── AliasOp.java │ │ │ ├── AssertUniqueKeyOp.java │ │ │ ├── DatabaseOp.java │ │ │ ├── DistinctOp.java │ │ │ ├── EmptyOp.java │ │ │ ├── InnerJoinOp.java │ │ │ ├── LimitOp.java │ │ │ ├── NamedOp.java │ │ │ ├── OpVisitor.java │ │ │ ├── OrderOp.java │ │ │ ├── ProjectOp.java │ │ │ ├── ProjectionSpec.java │ │ │ ├── SQLOp.java │ │ │ ├── SelectOp.java │ │ │ ├── TableOp.java │ │ │ └── util │ │ │ │ ├── OpMutator.java │ │ │ │ ├── OpRenamer.java │ │ │ │ ├── OpSelecter.java │ │ │ │ └── OpUtil.java │ │ ├── renamer │ │ │ ├── ColumnRenamer.java │ │ │ ├── Renamer.java │ │ │ └── TableRenamer.java │ │ ├── schema │ │ │ ├── ColumnDef.java │ │ │ ├── ColumnName.java │ │ │ ├── ForeignKey.java │ │ │ ├── Identifier.java │ │ │ ├── Inspector.java │ │ │ ├── Key.java │ │ │ ├── TableDef.java │ │ │ └── TableName.java │ │ ├── types │ │ │ ├── DataType.java │ │ │ ├── SQLApproximateNumeric.java │ │ │ ├── SQLBinary.java │ │ │ ├── SQLBit.java │ │ │ ├── SQLBoolean.java │ │ │ ├── SQLCharacterString.java │ │ │ ├── SQLCharacterStringVarying.java │ │ │ ├── SQLDate.java │ │ │ ├── SQLExactNumeric.java │ │ │ ├── SQLGeometry.java │ │ │ ├── SQLInterval.java │ │ │ ├── SQLTime.java │ │ │ ├── SQLTimestamp.java │ │ │ ├── StrdfWKT.java │ │ │ └── UnsupportedDataType.java │ │ └── vendor │ │ │ ├── HSQLDB.java │ │ │ ├── InterbaseOrFirebird.java │ │ │ ├── MySQL.java │ │ │ ├── Oracle.java │ │ │ ├── PostgreSQL.java │ │ │ ├── SQL92.java │ │ │ ├── SQLServer.java │ │ │ └── Vendor.java │ │ ├── download │ │ └── DownloadContentQuery.java │ │ ├── engine │ │ └── QueryIterTableSQL.java │ │ ├── examples │ │ ├── AssemblerExample.java │ │ ├── JenaGraphExample.java │ │ ├── JenaModelExample.java │ │ ├── SPARQLExample.java │ │ └── SystemLoaderExample.java │ │ ├── find │ │ ├── FindQuery.java │ │ ├── TripleQueryIter.java │ │ └── URIMakerRule.java │ │ ├── jena │ │ ├── CachingGraphD2RQ.java │ │ ├── D2RQQueryHandler.java │ │ ├── GraphD2RQ.java │ │ └── ModelD2RQ.java │ │ ├── lang │ │ ├── AliasDeclaration.java │ │ ├── ClassMap.java │ │ ├── CompiledD2RQMapping.java │ │ ├── Configuration.java │ │ ├── D2RQCompiler.java │ │ ├── D2RQMappingVisitor.java │ │ ├── D2RQReader.java │ │ ├── D2RQValidator.java │ │ ├── D2RQWriter.java │ │ ├── Database.java │ │ ├── DownloadMap.java │ │ ├── Join.java │ │ ├── JoinSetParser.java │ │ ├── MapObject.java │ │ ├── Mapping.java │ │ ├── Microsyntax.java │ │ ├── NodeMakerFactory.java │ │ ├── OpBuilder.java │ │ ├── PropertyBridge.java │ │ ├── ResourceMap.java │ │ └── TranslationTable.java │ │ ├── mapgen │ │ ├── D2RQMappingStyle.java │ │ ├── D2RQTarget.java │ │ ├── DirectMappingStyle.java │ │ ├── Filter.java │ │ ├── FilterIncludeExclude.java │ │ ├── FilterMatchAny.java │ │ ├── FilterMatchColumn.java │ │ ├── FilterMatchSchema.java │ │ ├── FilterMatchTable.java │ │ ├── FilterParser.java │ │ ├── IRIEncoder.java │ │ ├── MappingGenerator.java │ │ ├── MappingStyle.java │ │ ├── OntologyTarget.java │ │ ├── R2RMLTarget.java │ │ ├── Target.java │ │ └── UniqueLocalNameGenerator.java │ │ ├── nodes │ │ ├── BindingMaker.java │ │ ├── FixedNodeMaker.java │ │ ├── NodeMaker.java │ │ ├── NodeMakerVisitor.java │ │ ├── NodeSetFilter.java │ │ ├── TypedNodeMaker.java │ │ ├── TypedNodeTransformationMaker.java │ │ └── TypedNodeTransformationMakerList.java │ │ ├── pp │ │ └── PrettyPrinter.java │ │ ├── r2rml │ │ ├── ColumnNameR2RML.java │ │ ├── ComponentCollection.java │ │ ├── ConflictChecker.java │ │ ├── ConstantIRI.java │ │ ├── ConstantShortcut.java │ │ ├── GeometryFunction.java │ │ ├── GeometryParametersTerms.java │ │ ├── Join.java │ │ ├── LanguageTag.java │ │ ├── LogicalTable.java │ │ ├── Mapping.java │ │ ├── MappingComponent.java │ │ ├── MappingTerm.java │ │ ├── MappingValidator.java │ │ ├── MappingVisitor.java │ │ ├── PredicateObjectMap.java │ │ ├── R2RMLCompiler.java │ │ ├── R2RMLReader.java │ │ ├── R2RMLWriter.java │ │ ├── RDFComparator.java │ │ ├── ReferencingGeometryAttributes.java │ │ ├── ReferencingGeometryObjectMap.java │ │ ├── ReferencingObjectMap.java │ │ ├── SQLQuery.java │ │ ├── StringTemplate.java │ │ ├── TableOrViewName.java │ │ ├── TermMap.java │ │ └── TriplesMap.java │ │ ├── server │ │ ├── AutoReloadableDataset.java │ │ ├── ClassMapServlet.java │ │ ├── ConfigLoader.java │ │ ├── D2RQDatasetDesc.java │ │ ├── D2RServer.java │ │ ├── DatasetDescriptionServlet.java │ │ ├── DirectoryServlet.java │ │ ├── JettyLauncher.java │ │ ├── MetadataCreator.java │ │ ├── ModelResponse.java │ │ ├── NamespaceServlet.java │ │ ├── PageServlet.java │ │ ├── RequestParamHandler.java │ │ ├── ResourceDescriptionServlet.java │ │ ├── ResourceServlet.java │ │ ├── RootServlet.java │ │ ├── VelocityWrapper.java │ │ └── WebappInitListener.java │ │ ├── tmp │ │ ├── CompatibleRelationGroup.java │ │ ├── JoinOptimizer.java │ │ └── QueryEngineD2RQ.java │ │ ├── validation │ │ ├── Message.java │ │ ├── PlainTextMessageRenderer.java │ │ ├── Report.java │ │ └── ValidatingRDFParser.java │ │ ├── values │ │ ├── BaseIRIValueMaker.java │ │ ├── BlankNodeIDValueMaker.java │ │ ├── ColumnValueMaker.java │ │ ├── ColumnValueTransformationMaker.java │ │ ├── DecoratingValueMaker.java │ │ ├── TemplateValueMaker.java │ │ ├── TransformationValueMaker.java │ │ ├── Translator.java │ │ └── ValueMaker.java │ │ ├── vocab │ │ ├── D2RConfig.java │ │ ├── D2RQ.java │ │ ├── GEOMETRY_FUNCTIONS.java │ │ ├── ISWC.java │ │ ├── JDBC.java │ │ ├── META.java │ │ ├── RR.java │ │ ├── RRExtra.java │ │ ├── RRX.java │ │ ├── SD.java │ │ ├── SKOS.java │ │ ├── STRING_FUNCTIONS.java │ │ ├── VoID.java │ │ └── VocabularySummarizer.java │ │ └── writer │ │ ├── MappingWriter.java │ │ └── PrettyTurtleWriter.java ├── geotriples-rml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── be │ │ └── ugent │ │ └── mmlab │ │ └── rml │ │ ├── core │ │ ├── ArgumentPosition.java │ │ ├── ConditionalJoinRMLPerformer.java │ │ ├── Config.java │ │ ├── DependencyRMLPerformer.java │ │ ├── JoinRMLPerformer.java │ │ ├── JoinReferenceRMLPerformer.java │ │ ├── KeyGenerator.java │ │ ├── MalformedGeometryException.java │ │ ├── NodeRMLPerformer.java │ │ ├── OntologyGenerator.java │ │ ├── RMLEngine.java │ │ ├── RMLMappingFactory.java │ │ ├── RMLPerformer.java │ │ └── SimpleReferencePerformer.java │ │ ├── dataset │ │ ├── CustomSesameDataset.java │ │ ├── FileSesameDataset.java │ │ ├── StatementCounter.java │ │ └── TupleMatcher.java │ │ ├── function │ │ ├── AbstractFunction.java │ │ ├── Config.java │ │ ├── Function.java │ │ ├── FunctionAdd.java │ │ ├── FunctionAlreadyExists.java │ │ ├── FunctionArea.java │ │ ├── FunctionAsGML.java │ │ ├── FunctionAsWKT.java │ │ ├── FunctionCentroidX.java │ │ ├── FunctionCentroidY.java │ │ ├── FunctionContains.java │ │ ├── FunctionCoordinateDimension.java │ │ ├── FunctionCrosses.java │ │ ├── FunctionDimension.java │ │ ├── FunctionDisjoint.java │ │ ├── FunctionDistance.java │ │ ├── FunctionEQUI.java │ │ ├── FunctionEquals.java │ │ ├── FunctionFactory.java │ │ ├── FunctionGreaterThan.java │ │ ├── FunctionHasSerialization.java │ │ ├── FunctionIntersects.java │ │ ├── FunctionIs3D.java │ │ ├── FunctionIsEmpty.java │ │ ├── FunctionIsSimple.java │ │ ├── FunctionLength.java │ │ ├── FunctionNotDefined.java │ │ ├── FunctionOverlaps.java │ │ ├── FunctionSpatialDimension.java │ │ ├── FunctionSubtract.java │ │ ├── FunctionTouches.java │ │ ├── FunctionWithin.java │ │ ├── GMLConfiguration.java │ │ ├── GMLd.java │ │ ├── GTransormationFunctions.java │ │ └── GeometryFunction.java │ │ ├── main │ │ └── MainTrans.java │ │ ├── mapgen │ │ ├── CSVMappingGenerator.java │ │ ├── RMLMappingGenerator.java │ │ ├── SQLMappingGenerator.java │ │ ├── ShapefileMappingGenerator.java │ │ ├── XMLMappingGenerator.java │ │ └── XMLMappingGeneratorTrans.java │ │ ├── model │ │ ├── AbstractTermMap.java │ │ ├── AbstractTermMapTrans.java │ │ ├── GraphMap.java │ │ ├── InvalidRMLStructureException.java │ │ ├── JoinCondition.java │ │ ├── LogicalSource.java │ │ ├── ObjectMap.java │ │ ├── PredicateMap.java │ │ ├── PredicateObjectMap.java │ │ ├── RMLMapping.java │ │ ├── ReferencingObjectMap.java │ │ ├── StdGraphMap.java │ │ ├── StdJoinCondition.java │ │ ├── StdLogicalSource.java │ │ ├── StdObjectMap.java │ │ ├── StdPredicateMap.java │ │ ├── StdPredicateObjectMap.java │ │ ├── StdReferencingObjectMap.java │ │ ├── StdSubjectMap.java │ │ ├── StdTriplesMap.java │ │ ├── SubjectMap.java │ │ ├── TermMap.java │ │ ├── TermType.java │ │ ├── TriplesMap.java │ │ └── reference │ │ │ ├── ReferenceIdentifier.java │ │ │ └── ReferenceIdentifierImpl.java │ │ ├── processor │ │ ├── AbstractRMLProcessor.java │ │ ├── RMLProcessor.java │ │ ├── RMLProcessorFactory.java │ │ └── concrete │ │ │ ├── CSVProcessor.java │ │ │ ├── ConcreteRMLProcessorFactory.java │ │ │ ├── DatabaseProcessor.java │ │ │ ├── DatabaseProcessorWithManyQueries.java │ │ │ ├── JSONPathProcessor.java │ │ │ ├── RowProcessor.java │ │ │ ├── ShapefileProcessor.java │ │ │ ├── ShapefileProcessorGDAL.java │ │ │ ├── TSVProcessor.java │ │ │ └── XPathProcessor.java │ │ ├── tools │ │ ├── CacheFifo.java │ │ ├── CriticalSection.java │ │ └── CustomRDFDataValidator.java │ │ ├── vocabulary │ │ ├── GEOMETRY_FUNCTIONS.java │ │ ├── Vocab.java │ │ └── VocabTrans.java │ │ └── xml │ │ ├── NamespaceContextAdapter.java │ │ └── XOMBuilder.java └── pom.xml ├── geotriples-spark ├── pom.xml └── src │ └── main │ └── java │ └── eu │ └── linkedeodata │ └── geotriples │ ├── Converters │ └── RML_Converter.java │ ├── SparkMaster.java │ └── utils │ ├── Coordinates2WKT.java │ ├── NTriplesAlternative.java │ ├── NTriplesUtilNoEscape.java │ ├── NullDataSet.java │ ├── SerializedLogger.java │ └── SparkReader.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.txt 2 | *.nt 3 | *.n3 4 | target/ 5 | log/ 6 | pom.xml.tag 7 | pom.xml.releaseBackup 8 | pom.xml.versionsBackup 9 | pom.xml.next 10 | release.properties 11 | dependency-reduced-pom.xml 12 | buildNumber.properties 13 | .* 14 | *.iml 15 | !/.gitignore 16 | -------------------------------------------------------------------------------- /geotriples-core/src/main/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | bin 8 | 9 | zip 10 | 11 | 12 | 13 | target/appassembler/repo 14 | repo 15 | 16 | maven-metadata-appassembler.xml 17 | 18 | 19 | 20 | target/generated-resources/appassembler/booter-unix/etc 21 | etc 22 | 23 | geotriples-mapping.xml 24 | geotriples-rdf.xml 25 | geotriples-all.xml 26 | 27 | 28 | 29 | target/generated-resources/appassembler/booter-unix/bin 30 | bin 31 | 0755 32 | unix 33 | 34 | 35 | target/generated-resources/appassembler/booter-windows/bin 36 | bin 37 | 0755 38 | dos 39 | 40 | 41 | -------------------------------------------------------------------------------- /geotriples-evaluation/src/main/java/eu/linkedeodata/geotriples/PrintTimeStats.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | public class PrintTimeStats { 4 | private static double total_duration=0.0; 5 | 6 | public static void printTime(String text, double time_milliseconds) { 7 | //System.out.println("Time: " + text + " took " + time_milliseconds + " msec"); 8 | } 9 | 10 | public static void addDuration(double duration) { 11 | total_duration+=duration; 12 | } 13 | public static double getDuration(){ 14 | return total_duration; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /geotriples-gui/resources/AddSourceTable.bxml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /geotriples-gui/resources/AddSourceTable.json: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to you under the Apache License, 6 | * Version 2.0 (the "License"); you may not use this file except in 7 | * compliance 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 | { 18 | addSourceTable: "Load Source Table" 19 | } 20 | -------------------------------------------------------------------------------- /geotriples-gui/resources/GeoTriplesWindow.json: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to you under the Apache License, 6 | * Version 2.0 (the "License"); you may not use this file except in 7 | * compliance 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 | { geoTriples: "GeoTriples", 18 | symbol: "Symbol", 19 | companyName: "Company", 20 | value: "Value", 21 | openingValue: "Open", 22 | highValue: "High", 23 | lowValue: "Low", 24 | change: "Change", 25 | volume: "Volume", 26 | addSymbol: "Add symbol", 27 | removeSymbol: "Remove selected symbols", 28 | lastUpdate: "Last Update", 29 | dataProvidedBy: "Tool provided by", 30 | geoTriplesLink: "GeoTriples Home", 31 | generatemapping: "Generate Mapping", 32 | dumprdf: "Generate RDF graph", 33 | mappingpreviewandedit: "Mapping Editor" 34 | } 35 | -------------------------------------------------------------------------------- /geotriples-gui/resources/GeoTriplesWindow_fr.json: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to you under the Apache License, 6 | * Version 2.0 (the "License"); you may not use this file except in 7 | * compliance 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 | { geoTriples: "GeoTriples", 18 | symbol: "Code", 19 | companyName: "Société", 20 | value: "Cours", 21 | openingValue: "Ouverture", 22 | highValue: "+ Haut", 23 | lowValue: "+ Bas", 24 | change: "Variation", 25 | volume: "Volume", 26 | addSymbol: "Ajouter un code", 27 | removeSymbol: "Enlever codes sélectionnés", 28 | lastUpdate: "Dernier échange", 29 | dataProvidedBy: "Données fournies par", 30 | yahooFinance: "Yahoo! Finance", 31 | generatemapping: "Generate Mapping", 32 | dumprdf: "Generate RDF Triples", 33 | mappingpreview: "Preview Mapping" 34 | } 35 | -------------------------------------------------------------------------------- /geotriples-gui/resources/GeoTriplesWindow_it.json: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to you under the Apache License, 6 | * Version 2.0 (the "License"); you may not use this file except in 7 | * compliance 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 | { geoTriples: "GeoTriples", 18 | symbol: "Simbolo", 19 | companyName: "Azienda", 20 | value: "Valore", 21 | openingValue: "Apertura", 22 | highValue: "Alto", 23 | lowValue: "Basso", 24 | change: "Variazione", 25 | volume: "Volume", 26 | addSymbol: "Aggiungi simbolo", 27 | removeSymbol: "Rimuovi simboli selezionati", 28 | lastUpdate: "Ultimo Aggiornamento", 29 | dataProvidedBy: "Tool forniti da", 30 | yahooFinance: "GeoTriples Home", 31 | generatemapping: "Generate Mapping", 32 | dumprdf: "Generate RDF Triples", 33 | mappingpreview: "Preview Mapping" 34 | } 35 | -------------------------------------------------------------------------------- /geotriples-gui/resources/OpenConnection.json: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to you under the Apache License, 6 | * Version 2.0 (the "License"); you may not use this file except in 7 | * compliance 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 | { 18 | chooseConnection: "Open Connection" 19 | } 20 | -------------------------------------------------------------------------------- /geotriples-gui/resources/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-team-UoA/GeoTriples/fa7dfd71ebcbc8555ec4afb165b9b825c9d6dd2a/geotriples-gui/resources/add.png -------------------------------------------------------------------------------- /geotriples-gui/resources/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-team-UoA/GeoTriples/fa7dfd71ebcbc8555ec4afb165b9b825c9d6dd2a/geotriples-gui/resources/delete.png -------------------------------------------------------------------------------- /geotriples-gui/resources/dumprdf.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-team-UoA/GeoTriples/fa7dfd71ebcbc8555ec4afb165b9b825c9d6dd2a/geotriples-gui/resources/dumprdf.gif -------------------------------------------------------------------------------- /geotriples-gui/resources/generatemapping.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-team-UoA/GeoTriples/fa7dfd71ebcbc8555ec4afb165b9b825c9d6dd2a/geotriples-gui/resources/generatemapping.gif -------------------------------------------------------------------------------- /geotriples-gui/resources/sqlconnectionparameters.bxml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 33 |
34 |
35 | -------------------------------------------------------------------------------- /geotriples-gui/resources/sqlconnectionparameters.json: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to you under the Apache License, 6 | * Version 2.0 (the "License"); you may not use this file except in 7 | * compliance 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 | { 18 | chooseConnection: "Open Connection" 19 | } 20 | -------------------------------------------------------------------------------- /geotriples-gui/src/main/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | bin 8 | 9 | zip 10 | 11 | 12 | 13 | target/appassembler/repo 14 | repo 15 | 16 | maven-metadata-appassembler.xml 17 | 18 | 19 | 20 | target/generated-resources/appassembler/booter-unix/etc 21 | etc 22 | 23 | geotriples-gui.xml 24 | 25 | 26 | 27 | target/generated-resources/appassembler/booter-unix/bin 28 | bin 29 | 0755 30 | unix 31 | 32 | 33 | target/generated-resources/appassembler/booter-windows/bin 34 | bin 35 | 0755 36 | dos 37 | 38 | 39 | -------------------------------------------------------------------------------- /geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/AmountBindMapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to you under the Apache License, 6 | * Version 2.0 (the "License"); you may not use this file except in 7 | * compliance 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 | package eu.linkedeodata.geotriples.gui; 18 | 19 | import java.text.DecimalFormat; 20 | import java.text.ParseException; 21 | 22 | import org.apache.pivot.wtk.TextInput; 23 | 24 | public class AmountBindMapping implements TextInput.TextBindMapping { 25 | protected static final DecimalFormat FORMAT = new DecimalFormat("0.00"); 26 | 27 | @Override 28 | public String toString(Object value) { 29 | return FORMAT.format(value); 30 | } 31 | 32 | @Override 33 | public Object valueOf(String text) { 34 | // in case of an empty string to validate, return a default value, to avoid an NPE 35 | if (text.length() < 1) 36 | return ""; 37 | 38 | try { 39 | return FORMAT.parse(text); 40 | } catch (ParseException ex) { 41 | throw new NumberFormatException(ex.getMessage()); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/BaseIRIValidator.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.gui; 2 | 3 | import org.apache.pivot.wtk.Label; 4 | import org.apache.pivot.wtk.validation.Validator; 5 | import org.d2rq.mapgen.IRIEncoder; 6 | 7 | public class BaseIRIValidator implements Validator,Label.TextBindMapping { 8 | 9 | @Override 10 | public boolean isValid(String str) { 11 | if(str.startsWith("http://") && str.length()>7) 12 | { 13 | return true; 14 | } 15 | return false; 16 | } 17 | 18 | @Override 19 | public String toString(Object str) { 20 | if(str instanceof String) 21 | { 22 | return IRIEncoder.encode((String)str); 23 | } 24 | return ""; 25 | } 26 | 27 | @Override 28 | public Object valueOf(String arg0) { 29 | throw new UnsupportedOperationException(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/ChangeMapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to you under the Apache License, 6 | * Version 2.0 (the "License"); you may not use this file except in 7 | * compliance 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 | package eu.linkedeodata.geotriples.gui; 18 | 19 | import java.text.DecimalFormat; 20 | 21 | import org.apache.pivot.wtk.Label; 22 | 23 | /** 24 | * Formats a float as a change value (+ or -). 25 | */ 26 | public class ChangeMapping implements Label.TextBindMapping { 27 | private static final DecimalFormat FORMAT = new DecimalFormat("+0.00;-0.00"); 28 | 29 | @Override 30 | public String toString(Object value) { 31 | return FORMAT.format(value); 32 | } 33 | 34 | @Override 35 | public Object valueOf(String text) { 36 | throw new UnsupportedOperationException(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/CustomOutputStream.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.gui; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | import org.apache.pivot.wtk.TextArea; 7 | 8 | public class CustomOutputStream extends OutputStream { 9 | /** 10 | * This class extends from OutputStream to redirect output to a JTextArrea 11 | * @author www.codejava.net 12 | * 13 | */ 14 | private TextArea textArea; 15 | 16 | public CustomOutputStream(TextArea textArea) { 17 | this.textArea = textArea; 18 | this.textArea.setText(""); 19 | } 20 | 21 | @Override 22 | public void write(int b) throws IOException { 23 | // redirects data to the text area 24 | textArea.setText(textArea.getText().concat(String.valueOf((char)b))); 25 | // scrolls the text area to the end of data 26 | //textArea.setCaretPosition(textArea.getDocument().getLength()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/TablePackage.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.gui; 2 | 3 | import org.apache.pivot.wtk.BoxPane; 4 | import org.apache.pivot.wtk.TableView; 5 | 6 | public class TablePackage { 7 | TableView tableView; 8 | BoxPane detailPane; 9 | 10 | public TablePackage() { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/ValueMapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to you under the Apache License, 6 | * Version 2.0 (the "License"); you may not use this file except in 7 | * compliance 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 | package eu.linkedeodata.geotriples.gui; 18 | 19 | import java.text.DecimalFormat; 20 | 21 | import org.apache.pivot.wtk.Label; 22 | 23 | /** 24 | * Formats a float as a dollar value. 25 | */ 26 | public class ValueMapping implements Label.TextBindMapping { 27 | @SuppressWarnings("unused") 28 | private static final DecimalFormat FORMAT = new DecimalFormat("$0.00"); 29 | 30 | @Override 31 | public String toString(Object value) { 32 | return String.valueOf(value); 33 | } 34 | 35 | @Override 36 | public Object valueOf(String text) { 37 | throw new UnsupportedOperationException(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/VolumeMapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to you under the Apache License, 6 | * Version 2.0 (the "License"); you may not use this file except in 7 | * compliance 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 | package eu.linkedeodata.geotriples.gui; 18 | 19 | import java.text.DecimalFormat; 20 | 21 | import org.apache.pivot.wtk.Label; 22 | 23 | /** 24 | * Formats an int as a volume value (including separator characters). 25 | */ 26 | public class VolumeMapping implements Label.TextBindMapping { 27 | private static DecimalFormat FORMAT = new DecimalFormat(); 28 | 29 | @Override 30 | public String toString(Object value) { 31 | return FORMAT.format(value); 32 | } 33 | 34 | @Override 35 | public Object valueOf(String text) { 36 | // Not needed; this mapping is for load only 37 | throw new UnsupportedOperationException(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/go-down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-team-UoA/GeoTriples/fa7dfd71ebcbc8555ec4afb165b9b825c9d6dd2a/geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/go-down.png -------------------------------------------------------------------------------- /geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/go-up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-team-UoA/GeoTriples/fa7dfd71ebcbc8555ec4afb165b9b825c9d6dd2a/geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/go-up.png -------------------------------------------------------------------------------- /geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/window.bxml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-team-UoA/GeoTriples/fa7dfd71ebcbc8555ec4afb165b9b825c9d6dd2a/geotriples-gui/src/main/java/eu/linkedeodata/geotriples/gui/window.bxml -------------------------------------------------------------------------------- /geotriples-ontop/src/main/java/eu/linkedeodata/geotriples/BGPGroupGenerator.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | 6 | import org.openrdf.query.MalformedQueryException; 7 | import org.openrdf.query.algebra.StatementPattern; 8 | import org.openrdf.query.algebra.TupleExpr; 9 | import org.openrdf.query.algebra.helpers.StatementPatternCollector; 10 | import org.openrdf.query.parser.ParsedQuery; 11 | import org.openrdf.query.parser.sparql.SPARQLParser; 12 | /** 13 | * Generate basic graph patterns also called Disjunctive Normal Form (DNF) groups from a SPARQL query 14 | * @author Saleem 15 | * 16 | */ 17 | public class BGPGroupGenerator 18 | 19 | { 20 | /** 21 | * Generate BGP groups from a SPARQL query 22 | * @param parsedQuery TupleExpr of the SPARQL query 23 | * @return DNFGrps Map of DNF groups 24 | * @throws MalformedQueryException 25 | */ 26 | public static HashMap> generateBgpGroups(String strQuery) throws MalformedQueryException 27 | { 28 | HashMap> bgpGrps = new HashMap>(); 29 | int grpNo = 0; 30 | SPARQLParser parser = new SPARQLParser(); 31 | ParsedQuery parsedQuery = parser.parseQuery(strQuery, null); 32 | TupleExpr query = parsedQuery.getTupleExpr(); 33 | // collect all basic graph patterns 34 | 35 | for (TupleExpr bgp : BasicGraphPatternExtractor.process(query)) { 36 | //System.out.println(bgp); 37 | List patterns = StatementPatternCollector.process(bgp); 38 | bgpGrps.put(grpNo, patterns ); 39 | grpNo++; 40 | } 41 | 42 | return bgpGrps; 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /geotriples-ontop/src/main/java/eu/linkedeodata/geotriples/NullSesameDataset.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import org.openrdf.model.Resource; 4 | import org.openrdf.model.Statement; 5 | import org.openrdf.model.URI; 6 | import org.openrdf.model.Value; 7 | 8 | import net.antidot.semantic.rdf.model.impl.sesame.SesameDataSet; 9 | 10 | public class NullSesameDataset extends SesameDataSet{ 11 | @Override 12 | public void add(Resource s, URI p, Value o, Resource... contexts) { 13 | return; 14 | } 15 | @Override 16 | public void addStatement(Statement s) { 17 | return; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/Config.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.d2rq.db.schema.TableName; 6 | 7 | 8 | import eu.linkedeodata.geotriples.gui.ColumnReceipt; 9 | 10 | /** 11 | * here lie the default parameters of the application. For instance, which epsg code should be used if non is specified explicitly? 12 | */ 13 | public class Config { 14 | public static int EPSG_CODE = 4326; 15 | public static boolean GEOMETRY = false; 16 | public static String VOCABULARY = "GeoSPARQL"; 17 | public static boolean useDGALLibrary=false; 18 | /** 19 | * as given by the gui so that the mapping generator can decide which tables and columns to include/exclude and which predicates to assign per column 20 | */ 21 | public static java.util.Map> tablesAndColumns; 22 | 23 | /** 24 | * as given by the gui so that the mapping generator can decide which what class the instances of each table have 25 | */ 26 | public static java.util.Map tablesAndClasses; 27 | //public static HashMap variables=new HashMap<>(); 28 | public static void setGDAL() { 29 | useDGALLibrary=true; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/GMLLiteral.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import org.d2rq.db.types.DataType; 4 | 5 | public class GMLLiteral extends DataType { 6 | 7 | public GMLLiteral(String name) { 8 | super(name); 9 | // TODO Auto-generated constructor stub 10 | } 11 | 12 | @Override 13 | public String rdfType() { 14 | return "http://opengis.net/ont/geosparql#gmlLiteral"; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/GeneralCompatibleRelationGroup.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import org.d2rq.db.op.DatabaseOp; 9 | import org.d2rq.nodes.BindingMaker; 10 | 11 | public class GeneralCompatibleRelationGroup { 12 | 13 | public static Collection groupNodeRelations(List relations) { 14 | Collection result = new ArrayList(); 15 | for (GeneralNodeRelation relation: relations) { 16 | result.add(new GeneralCompatibleRelationGroup(relation)); 17 | } 18 | return result; 19 | } 20 | 21 | private final GeneralNodeRelation relation; 22 | 23 | public GeneralCompatibleRelationGroup(GeneralNodeRelation relation) { 24 | this.relation = relation; 25 | } 26 | 27 | public GeneralConnection getConnection() { 28 | return relation.getConnection(); 29 | } 30 | 31 | public DatabaseOp baseRelation() { 32 | return relation.getBaseTabular(); 33 | } 34 | 35 | public Collection bindingMakers() { 36 | return Collections.singleton(relation.getBindingMaker()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/GeneralCompiledMapping.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import java.util.Collection; 4 | import java.util.List; 5 | 6 | import org.d2rq.algebra.DownloadRelation; 7 | 8 | import com.hp.hpl.jena.graph.Graph; 9 | import com.hp.hpl.jena.graph.Node; 10 | import com.hp.hpl.jena.shared.PrefixMapping; 11 | import com.hp.hpl.jena.sparql.util.Context; 12 | 13 | /** 14 | * TODO: Rename to Mapping? 15 | * TODO: Write documentation 16 | * 17 | * @author Richard Cyganiak (richard@cyganiak.de) 18 | */ 19 | public interface GeneralCompiledMapping { 20 | 21 | // TODO: Probably unnecessary as we already had to connect in order to compile 22 | void connect(); 23 | 24 | void close(); 25 | 26 | PrefixMapping getPrefixes(); 27 | 28 | Collection getTripleRelations(); 29 | 30 | Collection getDownloadRelations(); 31 | 32 | Collection getConnections(); 33 | 34 | List getResourceCollectionNames(); 35 | 36 | List getResourceCollectionNames(Node resource); 37 | 38 | GeneralResourceCollection getResourceCollection(String name); 39 | 40 | Graph getAdditionalTriples(); 41 | 42 | Context getContext(); 43 | } 44 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/GeneralConnection.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import java.util.Collection; 4 | 5 | import org.d2rq.db.op.SQLOp; 6 | import org.d2rq.db.op.TableOp; 7 | import org.d2rq.db.schema.TableName; 8 | 9 | public interface GeneralConnection { 10 | 11 | public String getFileURL(); //TODO do the same for the parser 12 | 13 | public GeneralParser getParser(); 14 | 15 | public void setParser(GeneralParser parser); 16 | 17 | public Collection getTableNames() throws Exception; 18 | public Collection getTableNames(String searchInSchema) throws Exception; 19 | 20 | public boolean isTable(TableName table) throws Exception; 21 | 22 | public TableOp getTable(TableName table) throws Exception; 23 | 24 | public boolean isReferencedByForeignKey(TableName table); 25 | 26 | public int limit(); 27 | 28 | public void setLimit(int resultSizeLimit); 29 | 30 | public void setFetchSize(int fetchSize); 31 | 32 | public void setDefaultFetchSize(int value); 33 | 34 | public int fetchSize(); 35 | 36 | public int hashCode(); 37 | 38 | public SQLOp getSelectStatement(String sql); 39 | 40 | /** 41 | * @param querytable a table to search 42 | * @return a result set containing all rows from querytable 43 | * @throws Exception 44 | */ 45 | public GeneralResultSet getData(String querytable) throws Exception; 46 | 47 | /** 48 | * @param querytable a table to search 49 | * @param primaryke the primary key to limit result-rows 50 | * @return a result set containing the selected rows from querytable 51 | */ 52 | public GeneralResultSet getData(String querytable, int primarykey); 53 | 54 | public boolean isGuiConnection(); 55 | 56 | public String getCRS(); 57 | 58 | public enum ConnectionType{ 59 | SQL, 60 | SHAPEFILE, 61 | KML, 62 | RML 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/GeneralJoinOptimizer.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | 4 | public class GeneralJoinOptimizer { 5 | public static GeneralNodeRelation optimize(GeneralNodeRelation r) { return r; } 6 | } 7 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/GeneralParser.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import java.io.File; 4 | import java.util.List; 5 | 6 | import org.d2rq.db.schema.TableDef; 7 | 8 | public interface GeneralParser { 9 | 10 | public void setFile(File shapefile); 11 | 12 | public File getFile(); 13 | 14 | public List getData(String tablename) throws Exception; 15 | 16 | 17 | public List getTablesDefs() throws Exception ; 18 | public List getData(String tablename, int primkey); 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/GeneralResultRow.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.d2rq.db.ResultRow; 7 | import org.d2rq.db.op.ProjectionSpec; 8 | 9 | public class GeneralResultRow extends ResultRow{ 10 | 11 | Map result = new HashMap(); 12 | 13 | public GeneralResultRow() 14 | { 15 | super(null); 16 | } 17 | public void addPair(String column,Object data) 18 | { 19 | result.put(column, data); 20 | } 21 | public Object getData(String column) 22 | { 23 | return result.get(column); 24 | } 25 | @Override 26 | public String toString() 27 | { 28 | StringBuilder stb=new StringBuilder(); 29 | for(String key:result.keySet()) 30 | { 31 | stb.append(result.get(key)+"\n"); 32 | } 33 | stb.append("telos\n"); 34 | return stb.toString(); 35 | } 36 | @Override 37 | public String get(ProjectionSpec p) 38 | { 39 | return String.valueOf(result.get(p.getColumn().getColumn().getName())); 40 | } 41 | @Override 42 | public Object getObject(ProjectionSpec p) { 43 | return result.get(p.getColumn().getColumn().getName()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/GeneralResultSet.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import java.util.List; 4 | 5 | public class GeneralResultSet { 6 | private int current = -1; 7 | private List results; 8 | 9 | public GeneralResultSet(List results) { 10 | this.results = results; 11 | } 12 | 13 | public boolean next() { 14 | current++; 15 | if (current < results.size()) 16 | return true; 17 | else 18 | return false; 19 | } 20 | 21 | public GeneralResultRow getCurrent() { 22 | if (current >= results.size()) 23 | return null; 24 | return results.get(current); 25 | } 26 | 27 | public GeneralResultRow getCurrent(List columns) { 28 | if (current >= results.size()) 29 | return null; 30 | boolean isnull = false; 31 | for (String column : columns) { 32 | if (results.get(current).getData(column) == null) { 33 | isnull = true; 34 | break; 35 | } 36 | } 37 | while (isnull) { 38 | ++current; 39 | isnull = false; 40 | for (String column : columns) { 41 | if (results.get(current).getData(column) == null) { 42 | isnull = true; 43 | break; 44 | } 45 | } 46 | } 47 | 48 | if (current >= results.size()) 49 | return null; 50 | return results.get(current); 51 | } 52 | 53 | public Object getObject(String columnname) { 54 | return results.get(current).getData(columnname); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/GeneralSelectStatementBuilder.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import org.d2rq.db.SelectStatementBuilder; 4 | import org.d2rq.db.op.DatabaseOp; 5 | import org.d2rq.db.vendor.Vendor; 6 | 7 | /** 8 | * Turns a {@link DatabaseOp} into a SQL SELECT statement. 9 | * 10 | * Works by doing a depth-first traversal of the query tree, collecting 11 | * information in a SimpleQuery object. Such an object can contain 12 | * a non-nested SQL query. Once nesting is necessary, the current 13 | * SimpleQuery is put on a stack, a new one is allocated and 14 | * information collected in it, and then it is "flattened" by turning 15 | * it into a raw SQL string that becomes a FROM clause in the upper 16 | * instance. 17 | * 18 | * The list of SELECT clauses is not built while working the tree, but 19 | * computed in the end from the {@link DatabaseOp}'s column list. 20 | * 21 | * @author Richard Cyganiak (richard@cyganiak.de) 22 | */ 23 | public class GeneralSelectStatementBuilder extends SelectStatementBuilder { 24 | DatabaseOp input; 25 | public GeneralSelectStatementBuilder(DatabaseOp input, Vendor vendor) 26 | { 27 | super(input,vendor); 28 | this.input=input; 29 | } 30 | public String getTable() 31 | { 32 | return input.getTableName().toString(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/GeneralTripleQueryIter.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import org.d2rq.algebra.TripleRelation; 4 | 5 | import com.hp.hpl.jena.graph.Triple; 6 | import com.hp.hpl.jena.sparql.engine.binding.Binding; 7 | import com.hp.hpl.jena.sparql.engine.iterator.QueryIter; 8 | import com.hp.hpl.jena.util.iterator.ExtendedIterator; 9 | import com.hp.hpl.jena.util.iterator.NiceIterator; 10 | 11 | 12 | /** 13 | * Wraps a {@link QueryIter} over bindings with three s/p/o variables 14 | * (see {@link TripleRelation}) as an iterator over {@link Triple}s. 15 | * Also adds a {@link #cancel()} method that wouldn't usually be 16 | * available on Jena's triple iterators. 17 | * 18 | * @author Richard Cyganiak (richard@cyganiak.de) 19 | */ 20 | public class GeneralTripleQueryIter extends NiceIterator { 21 | 22 | public static ExtendedIterator create(QueryIter wrapped) { 23 | return new GeneralTripleQueryIter(wrapped); 24 | } 25 | 26 | private final QueryIter wrapped; 27 | 28 | private GeneralTripleQueryIter(QueryIter wrapped) { 29 | this.wrapped = wrapped; 30 | } 31 | 32 | public boolean hasNext() { 33 | return wrapped.hasNext(); 34 | } 35 | 36 | public Triple next() { 37 | Binding b = wrapped.next(); 38 | return new Triple( 39 | b.get(TripleRelation.SUBJECT), 40 | b.get(TripleRelation.PREDICATE), 41 | b.get(TripleRelation.OBJECT)); 42 | } 43 | 44 | public void close() { 45 | wrapped.close(); 46 | } 47 | 48 | /** 49 | * Cancels query execution. Can be called asynchronously. 50 | */ 51 | public void cancel() { 52 | wrapped.cancel(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/KeyGenerator.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import java.util.HashMap; 4 | /** 5 | * Generates a key to be used as private key for shape file table. 6 | * Generates either on the fly(Generate), or using a hash map of strings(GenerateFromMap) 7 | * @author Dimitrianos Savva NKUA (d.savva@di.uoa.gr) 8 | */ 9 | public class KeyGenerator { 10 | public enum Use{ 11 | USE_PREV, 12 | NEW_ONE, 13 | } 14 | private static int key=0; 15 | private HashMap memory; 16 | public KeyGenerator() 17 | { 18 | memory=new HashMap(); 19 | } 20 | 21 | public int GenerateFromMap(String somekey) 22 | { 23 | if(memory.containsKey(somekey)) 24 | { 25 | return memory.get(somekey); 26 | } 27 | else 28 | { 29 | memory.put(somekey, ++key); 30 | return key; 31 | } 32 | } 33 | 34 | public static int Generate(Use purpose) throws Exception 35 | { 36 | if(purpose.equals(Use.USE_PREV)) 37 | { 38 | return key; 39 | } 40 | else if(purpose.equals(Use.NEW_ONE)) 41 | { 42 | return ++key; 43 | } 44 | else 45 | { 46 | throw new Exception("Use purpose unsupported"); 47 | } 48 | } 49 | 50 | public static int Generate() throws Exception 51 | { 52 | return Generate(Use.NEW_ONE); 53 | } 54 | 55 | public static String Generate(String prefix,Use purpose) throws Exception 56 | { 57 | if(purpose.equals(Use.USE_PREV)) 58 | { 59 | return String.format("%s%d",prefix,key); 60 | } 61 | else if(purpose.equals(Use.NEW_ONE)) 62 | { 63 | return String.format("%s%d",prefix,++key); 64 | } 65 | else 66 | { 67 | throw new Exception("Use purpose unsupported"); 68 | } 69 | } 70 | public static String Generate(String prefix) throws Exception 71 | { 72 | return Generate(prefix,Use.NEW_ONE); 73 | } 74 | 75 | public static void reset() { 76 | key=0; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/WKTLiteral.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples; 2 | 3 | import org.d2rq.db.types.DataType; 4 | 5 | public class WKTLiteral extends DataType { 6 | 7 | public WKTLiteral(String name) { 8 | super(name); 9 | } 10 | 11 | @Override 12 | public String rdfType() { 13 | return "http://www.opengis.net/ont/geosparql#wktLiteral"; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/geotiff/GeoTiffResultRow.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.geotiff; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.d2rq.db.ResultRow; 7 | import org.d2rq.db.op.ProjectionSpec; 8 | 9 | public class GeoTiffResultRow extends ResultRow{ 10 | 11 | Map result = new HashMap(); 12 | 13 | public GeoTiffResultRow() 14 | { 15 | super(null); 16 | } 17 | public void addPair(String column,Object data) 18 | { 19 | result.put(column, data); 20 | } 21 | public Object getData(String column) 22 | { 23 | return result.get(column); 24 | } 25 | @Override 26 | public String toString() 27 | { 28 | StringBuilder stb=new StringBuilder(); 29 | for(String key:result.keySet()) 30 | { 31 | stb.append(result.get(key)+"\n"); 32 | } 33 | stb.append("telos\n"); 34 | return stb.toString(); 35 | } 36 | @Override 37 | public String get(ProjectionSpec p) 38 | { 39 | return String.valueOf(result.get(p.getColumn().getColumn().getName())); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/geotiff/KeyGenerator.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.geotiff; 2 | 3 | import java.util.HashMap; 4 | /** 5 | * Generates a key to be used as private key for shape file table. 6 | * Generates either on the fly(Generate), or using a hash map of strings(GenerateFromMap) 7 | * @author Dimitrianos Savva NKUA (d.savva@di.uoa.gr) 8 | */ 9 | public class KeyGenerator { 10 | public enum Use{ 11 | USE_PREV, 12 | NEW_ONE, 13 | } 14 | private static int key=0; 15 | private HashMap memory; 16 | public KeyGenerator() 17 | { 18 | memory=new HashMap(); 19 | } 20 | 21 | public int GenerateFromMap(String somekey) 22 | { 23 | if(memory.containsKey(somekey)) 24 | { 25 | return memory.get(somekey); 26 | } 27 | else 28 | { 29 | memory.put(somekey, ++key); 30 | return key; 31 | } 32 | } 33 | 34 | public static int Generate(Use purpose) throws Exception 35 | { 36 | if(purpose.equals(Use.USE_PREV)) 37 | { 38 | return key; 39 | } 40 | else if(purpose.equals(Use.NEW_ONE)) 41 | { 42 | return ++key; 43 | } 44 | else 45 | { 46 | throw new Exception("Use purpose unsupported"); 47 | } 48 | } 49 | 50 | public static int Generate() throws Exception 51 | { 52 | return Generate(Use.NEW_ONE); 53 | } 54 | 55 | public static String Generate(String prefix,Use purpose) throws Exception 56 | { 57 | if(purpose.equals(Use.USE_PREV)) 58 | { 59 | return String.format("%s%d",prefix,key); 60 | } 61 | else if(purpose.equals(Use.NEW_ONE)) 62 | { 63 | return String.format("%s%d",prefix,++key); 64 | } 65 | else 66 | { 67 | throw new Exception("Use purpose unsupported"); 68 | } 69 | } 70 | public static String Generate(String prefix) throws Exception 71 | { 72 | return Generate(prefix,Use.NEW_ONE); 73 | } 74 | 75 | public static void reset() { 76 | key=0; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/kml/KMLSystemLoader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Dimitrianos Savva National and Kapodistrian University of Athens 3 | * @author Giannis Vlachopoulos National and Kapodistrian University of Athens 4 | */ 5 | package eu.linkedeodata.geotriples.kml; 6 | 7 | import org.d2rq.D2RQException; 8 | 9 | import eu.linkedeodata.geotriples.GeneralConnection; 10 | import eu.linkedeodata.geotriples.GeneralSystemLoader; 11 | import eu.linkedeodata.geotriples.gui.RecipeMapping; 12 | 13 | public class KMLSystemLoader extends GeneralSystemLoader { 14 | 15 | public KMLSystemLoader() { 16 | super(); 17 | } 18 | 19 | public KMLSystemLoader(RecipeMapping receipt, String guimapping) { 20 | super(receipt, guimapping); 21 | } 22 | 23 | public GeneralConnection getConnection() { 24 | if (connection == null) { 25 | if (sourceURL == null) { 26 | throw new D2RQException("No kml file provided"); 27 | } 28 | connection = new KMLConnection(sourceURL); 29 | } 30 | return connection; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/shapefile/ShapefileSystemLoader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Dimitrianos Savva National and Kapodistrian University of Athens 3 | * @author Giannis Vlachopoulos National and Kapodistrian University of Athens 4 | */ 5 | package eu.linkedeodata.geotriples.shapefile; 6 | 7 | import org.d2rq.D2RQException; 8 | 9 | import eu.linkedeodata.geotriples.GeneralConnection; 10 | import eu.linkedeodata.geotriples.GeneralSystemLoader; 11 | import eu.linkedeodata.geotriples.gui.RecipeMapping; 12 | 13 | public class ShapefileSystemLoader extends GeneralSystemLoader { 14 | 15 | public ShapefileSystemLoader() { 16 | super(); 17 | } 18 | 19 | public ShapefileSystemLoader(RecipeMapping receipt, String guimapping) { 20 | super(receipt, guimapping); 21 | } 22 | 23 | public GeneralConnection getConnection() { 24 | if (connection == null) { 25 | if (sourceURL == null) { 26 | throw new D2RQException("No shape file provided"); 27 | } 28 | connection = new ShapefileConnection(sourceURL); 29 | } 30 | return connection; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/shapefile/TestGeneration.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.shapefile; 2 | 3 | import eu.linkedeodata.geotriples.KeyGenerator; 4 | import eu.linkedeodata.geotriples.KeyGenerator.Use; 5 | 6 | public class TestGeneration { 7 | 8 | /** 9 | * @param args 10 | * @throws Exception 11 | */ 12 | public static void main(String[] args) throws Exception { 13 | // TODO Auto-generated method stub 14 | System.out.println(KeyGenerator.Generate()); 15 | System.out.println(KeyGenerator.Generate(Use.NEW_ONE)); 16 | 17 | System.out.println(KeyGenerator.Generate()); 18 | 19 | System.out.println(KeyGenerator.Generate("dimis",Use.USE_PREV)); 20 | 21 | System.out.println(KeyGenerator.Generate(Use.USE_PREV)); 22 | System.out.println(KeyGenerator.Generate("dimis",Use.NEW_ONE)); 23 | System.out.println(KeyGenerator.Generate("dimis")); 24 | System.out.println(KeyGenerator.Generate()); 25 | 26 | KeyGenerator kg=new KeyGenerator(); 27 | System.out.println(kg.GenerateFromMap("dimis")); 28 | System.out.println(kg.GenerateFromMap("fff")); 29 | System.out.println(kg.GenerateFromMap("dimis")); 30 | System.out.println(kg.GenerateFromMap("dimis")); 31 | System.out.println(kg.GenerateFromMap("fff")); 32 | System.out.println(kg.GenerateFromMap("ppp")); 33 | 34 | 35 | 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/shapefile/TestShapefileParser.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.shapefile; 2 | 3 | import java.io.File; 4 | 5 | public class TestShapefileParser { 6 | 7 | /** 8 | * @param args 9 | * @throws Exception 10 | */ 11 | public static void main(String[] args) throws Exception { 12 | ShapeFileParser pp =new ShapeFileParser(new File("/Users/admin/Documents/teamkumbarakis/shapefiles/cyprus-latest.shp/buildings.shp")); 13 | pp.getData("buildings"); 14 | /*(for(ShapefileResultRow r:pp.getData("buildings")) 15 | { 16 | System.out.println(r); 17 | }*/ 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/utils/John_PairEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package eu.linkedeodata.geotriples.utils; 20 | 21 | class John_PairEntry implements java.util.Map.Entry { 22 | K a; 23 | V b; 24 | @Override 25 | public boolean equals(Object o) { 26 | if (o != null && (o instanceof John_PairEntry)) { 27 | John_PairEntry e = (John_PairEntry) o; 28 | return e.a.equals(a) && e.b.equals(b); 29 | } 30 | return false; 31 | 32 | } 33 | @Override 34 | public K getKey() { 35 | return a; 36 | } 37 | @Override 38 | public V getValue() { 39 | return b; 40 | } 41 | @Override 42 | public int hashCode() { 43 | return a.hashCode() ^ b.hashCode(); 44 | } 45 | @Override 46 | public V setValue(Object value) { 47 | throw new UnsupportedOperationException(); 48 | } 49 | John_PairEntry(K a, V b) { 50 | this.a = a; 51 | this.b = b; 52 | } 53 | } -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/utils/OntologyLoader.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.utils; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.FileNotFoundException; 5 | 6 | import com.hp.hpl.jena.ontology.DatatypeProperty; 7 | import com.hp.hpl.jena.ontology.OntClass; 8 | import com.hp.hpl.jena.ontology.OntModel; 9 | import com.hp.hpl.jena.rdf.model.ModelFactory; 10 | import com.hp.hpl.jena.util.iterator.ExtendedIterator; 11 | 12 | /** 13 | * 14 | * @author Ioannis Vlachopoulos 15 | * @author Dimitrianos Savva 16 | * 17 | * A simple API that reads an ontology and extracts its classes and properties 18 | */ 19 | public class OntologyLoader { 20 | 21 | /** 22 | * The file from which the ontology is loaded 23 | */ 24 | private String ontologyFilePath = null; 25 | 26 | /** 27 | * the ontology model as imported from the target ontology file 28 | */ 29 | private OntModel model; 30 | 31 | public OntologyLoader(String path) { 32 | this.setOntologyFilePath(path); 33 | } 34 | 35 | /** 36 | * load the ontology from the specified file 37 | */ 38 | public void load() { 39 | 40 | model = ModelFactory.createOntologyModel(); 41 | try { 42 | model.read(new FileInputStream(ontologyFilePath), "http://data.linkedeodata.eu/natura-2000-de/"); 43 | } catch (FileNotFoundException e) { 44 | // TODO Auto-generated catch block 45 | e.printStackTrace(); 46 | } 47 | } 48 | 49 | public String getOntologyFilePath() { 50 | return ontologyFilePath; 51 | } 52 | 53 | public void setOntologyFilePath(String ontologyFilePath) { 54 | this.ontologyFilePath = ontologyFilePath; 55 | } 56 | 57 | public ExtendedIterator getClasses() { 58 | return model.listClasses(); 59 | } 60 | 61 | public ExtendedIterator getProperties() { 62 | return model.listDatatypeProperties(); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/writers/WP2NTripleWriter.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.writers; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.Writer; 5 | 6 | import com.hp.hpl.jena.rdf.model.Model; 7 | import com.hp.hpl.jena.rdf.model.ModelFactory; 8 | import com.hp.hpl.jena.rdf.model.Statement; 9 | import com.hp.hpl.jena.rdf.model.StmtIterator; 10 | import com.hp.hpl.jena.rdf.model.impl.NTripleWriter; 11 | 12 | public class WP2NTripleWriter extends NTripleWriter { 13 | @Override 14 | public void write(Model baseModel, Writer writer, String base) 15 | { 16 | try { 17 | Model model = ModelFactory.withHiddenStatements(baseModel); 18 | PrintWriter pw; 19 | if (writer instanceof PrintWriter) { 20 | pw = (PrintWriter) writer; 21 | } else { 22 | pw = new PrintWriter(writer); 23 | } 24 | 25 | StmtIterator iter = model.listStatements(); 26 | Statement stmt = null; 27 | 28 | while (iter.hasNext()) { 29 | stmt = iter.nextStatement(); 30 | String objectstr=stmt.getObject().toString(); 31 | if(objectstr.startsWith("null")) 32 | { 33 | continue; 34 | } 35 | writeResource(stmt.getSubject(), pw); 36 | pw.print(" "); 37 | writeResource(stmt.getPredicate(), pw); 38 | pw.print(" "); 39 | writeNode(stmt.getObject(), pw); 40 | pw.println(" ."); 41 | } 42 | pw.flush(); 43 | } catch (Exception e) { 44 | System.out.println(e.getMessage()); 45 | e.printStackTrace(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/writers/dimis/WP2N3JenaWriterCommon.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.writers.dimis; 2 | 3 | import java.util.Map; 4 | 5 | import com.hp.hpl.jena.n3.N3JenaWriterCommon; 6 | 7 | public class WP2N3JenaWriterCommon extends N3JenaWriterCommon { 8 | static Map thiswellKnownPropsMap; 9 | public WP2N3JenaWriterCommon() 10 | { 11 | super(); 12 | } 13 | public WP2N3JenaWriterCommon(boolean allowTripleQuotedStrngs,Map wellKnownPropsMapTrtl) { 14 | super(); 15 | allowTripleQuotedStrings=allowTripleQuotedStrngs; 16 | wellKnownPropsMap = wellKnownPropsMapTrtl; 17 | thiswellKnownPropsMap=wellKnownPropsMap; 18 | } 19 | public static Map getWellKnownPropsMap() 20 | { 21 | return thiswellKnownPropsMap; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/writers/dimis/WP2N3JenaWriterTriples.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.writers.dimis; 2 | 3 | import java.util.Map; 4 | 5 | import com.hp.hpl.jena.n3.N3JenaWriterTriples; 6 | 7 | public class WP2N3JenaWriterTriples extends N3JenaWriterTriples { 8 | static Map thiswellKnownPropsMap; 9 | public WP2N3JenaWriterTriples() 10 | { 11 | super(); 12 | } 13 | public WP2N3JenaWriterTriples(boolean allowTripleQuotedStrngs,Map wellKnownPropsMapTrtl) { 14 | super(); 15 | allowTripleQuotedStrings=allowTripleQuotedStrngs; 16 | wellKnownPropsMap = wellKnownPropsMapTrtl; 17 | thiswellKnownPropsMap=wellKnownPropsMap; 18 | } 19 | public static Map getWellKnownPropsMap() 20 | { 21 | return thiswellKnownPropsMap; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/eu/linkedeodata/geotriples/writers/dimis/WP2N3TurtleJenaWriter.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.writers.dimis; 2 | 3 | 4 | public class WP2N3TurtleJenaWriter extends N3WP2Writer{ 5 | public WP2N3TurtleJenaWriter() { 6 | super(WP2N3JenaWriterPP.getWellKnownPropsMap(),true) ; 7 | // if ( writer.getPropValue("usePropertySymbols") == null ) 8 | // writer.useWellKnownPropertySymbols = false ; 9 | // Only allow "a" for rdf:type. 10 | //dimisremove//writer.wellKnownPropsMap = WP2N3JenaWriterPP.wellKnownPropsMapTurtle ; 11 | //dimisremove//writer.allowTripleQuotedStrings = true ; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/CompiledMapping.java: -------------------------------------------------------------------------------- 1 | package org.d2rq; 2 | 3 | import java.util.Collection; 4 | import java.util.List; 5 | 6 | import org.d2rq.algebra.DownloadRelation; 7 | import org.d2rq.algebra.TripleRelation; 8 | import org.d2rq.db.SQLConnection; 9 | 10 | import com.hp.hpl.jena.graph.Graph; 11 | import com.hp.hpl.jena.graph.Node; 12 | import com.hp.hpl.jena.shared.PrefixMapping; 13 | import com.hp.hpl.jena.sparql.util.Context; 14 | 15 | 16 | /** 17 | * TODO: Rename to Mapping? 18 | * TODO: Write documentation 19 | * 20 | * @author Richard Cyganiak (richard@cyganiak.de) 21 | */ 22 | public interface CompiledMapping { 23 | 24 | // TODO: Probably unnecessary as we already had to connect in order to compile 25 | void connect(); 26 | 27 | void close(); 28 | 29 | PrefixMapping getPrefixes(); 30 | 31 | Collection getTripleRelations(); 32 | 33 | Collection getDownloadRelations(); 34 | 35 | Collection getSQLConnections(); 36 | 37 | List getResourceCollectionNames(); 38 | 39 | List getResourceCollectionNames(Node resource); 40 | 41 | ResourceCollection getResourceCollection(String name); 42 | 43 | Graph getAdditionalTriples(); 44 | 45 | Context getContext(); 46 | } 47 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/D2RQOptions.java: -------------------------------------------------------------------------------- 1 | package org.d2rq; 2 | 3 | import com.hp.hpl.jena.query.ARQ; 4 | import com.hp.hpl.jena.sparql.util.Context; 5 | import com.hp.hpl.jena.sparql.util.Symbol; 6 | 7 | /** 8 | * Configuration options, mostly related to optional optimizations, 9 | * for use in an ARQ {@link Context} 10 | * 11 | * @author Richard Cyganiak (richard@cyganiak.de) 12 | */ 13 | public class D2RQOptions { 14 | public final static String NS = "http://d2rq.org/terms/opt.ttl#"; 15 | 16 | public final static Symbol MULTIPLEX_QUERIES = Symbol.create(NS + "multiplexQueries"); 17 | public final static Symbol SOFT_CONDITIONS = Symbol.create(NS + "softConditions"); 18 | public final static Symbol TRIM_JOINS = Symbol.create(NS + "trimJoins"); 19 | public final static Symbol AVOID_SELF_JOINS = Symbol.create(NS + "avoidSelfJoins"); 20 | public final static Symbol FILTER_TO_SQL = Symbol.create(NS + "filterToSQL"); 21 | 22 | public static Context getContext(boolean fastMode) { 23 | Context result = ARQ.getContext().copy(); 24 | String defaultValue = fastMode ? "true" : "false"; 25 | result.set(D2RQOptions.MULTIPLEX_QUERIES, defaultValue); 26 | result.set(D2RQOptions.FILTER_TO_SQL, defaultValue); 27 | return result; 28 | } 29 | 30 | // Cannot instantiate, static only 31 | private D2RQOptions() {} 32 | } 33 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/Log4jHelper.java: -------------------------------------------------------------------------------- 1 | package org.d2rq; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | /** 7 | * All Log4j-specific stuff is encapsulated here. 8 | * 9 | * Default configuration is in /etc/log4j.properties. We always 10 | * have to put that on the classpath so Log4j will find it. 11 | * 12 | * @author Richard Cyganiak (richard@cyganiak.de) 13 | */ 14 | public class Log4jHelper { 15 | 16 | // public static void turnLoggingOff() { 17 | // System.err.println("Logging is turned off!"); 18 | // LoggerFactory.getLogger("org.d2rq").setLevel(Level.OFF); 19 | // } 20 | // 21 | // public static void setVerboseLogging() { 22 | // // Adjust Log4j log level to show more stuff 23 | // LoggerFactory.getLogger("d2rq").setLevel(Level.INFO); 24 | // LoggerFactory.getLogger("org.d2rq").setLevel(Level.INFO); 25 | // LoggerFactory.getLogger("org.eclipse.jetty").setLevel(Level.INFO); 26 | // LoggerFactory.getLogger("org.joseki").setLevel(Level.INFO); 27 | // } 28 | // 29 | // public static void setDebugLogging() { 30 | // // Adjust Log4j log level to show MUCH more stuff 31 | // LoggerFactory.getLogger("d2rq").setLevel(Level.ALL); 32 | // LoggerFactory.getLogger("org.d2rq").setLevel(Level.ALL); 33 | // LoggerFactory.getLogger("org.eclipse.jetty").setLevel(Level.INFO); 34 | // LoggerFactory.getLogger("org.joseki").setLevel(Level.INFO); 35 | // } 36 | } 37 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/algebra/DownloadRelation.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.algebra; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashMap; 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | import org.d2rq.db.SQLConnection; 9 | import org.d2rq.db.op.DatabaseOp; 10 | import org.d2rq.db.schema.ColumnName; 11 | import org.d2rq.nodes.NodeMaker; 12 | import org.d2rq.nodes.TypedNodeMaker; 13 | import org.d2rq.values.ColumnValueMaker; 14 | import org.d2rq.values.ValueMaker; 15 | 16 | import com.hp.hpl.jena.sparql.core.Var; 17 | 18 | 19 | public class DownloadRelation extends NodeRelation { 20 | 21 | public final static Var RESOURCE = Var.alloc("resource"); 22 | public final static Var MEDIA_TYPE = Var.alloc("mediaType"); 23 | public final static Var CONTENT = Var.alloc("content"); 24 | 25 | public final static Set HEADER = new HashSet(Arrays.asList( 26 | new Var[]{RESOURCE, MEDIA_TYPE, CONTENT})); 27 | 28 | private final ColumnName contentDownloadColumn; 29 | 30 | public DownloadRelation( 31 | SQLConnection sqlConnection, 32 | DatabaseOp tabular, 33 | final NodeMaker nodeMaker, 34 | final ValueMaker mediaTypeMaker, 35 | final ColumnName contentDownloadColumn) { 36 | super(sqlConnection, tabular, new HashMap() {/** 37 | * 38 | */ 39 | private static final long serialVersionUID = 1L; 40 | 41 | { 42 | put(RESOURCE, nodeMaker); 43 | put(MEDIA_TYPE, new TypedNodeMaker(TypedNodeMaker.PLAIN_LITERAL, mediaTypeMaker)); 44 | put(CONTENT, new TypedNodeMaker(TypedNodeMaker.PLAIN_LITERAL, new ColumnValueMaker(contentDownloadColumn))); 45 | }}); 46 | this.contentDownloadColumn = contentDownloadColumn; 47 | } 48 | 49 | public ColumnName getContentDownloadColumn() { 50 | return contentDownloadColumn; 51 | } 52 | } -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/assembler/D2RQAssembler.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.assembler; 2 | 3 | import org.d2rq.D2RQException; 4 | import org.d2rq.jena.ModelD2RQ; 5 | import org.d2rq.vocab.D2RQ; 6 | 7 | import com.hp.hpl.jena.assembler.Assembler; 8 | import com.hp.hpl.jena.assembler.Mode; 9 | import com.hp.hpl.jena.assembler.assemblers.AssemblerBase; 10 | import com.hp.hpl.jena.rdf.model.Resource; 11 | import com.hp.hpl.jena.rdf.model.Statement; 12 | 13 | 14 | /** 15 | * A Jena assembler that builds ModelD2RQs. 16 | * 17 | * @author Richard Cyganiak (richard@cyganiak.de) 18 | */ 19 | public class D2RQAssembler extends AssemblerBase { 20 | 21 | public Object open(Assembler ignore, Resource description, Mode ignore2) { 22 | if (!description.hasProperty(D2RQ.mappingFile)) { 23 | throw new D2RQException("Error in assembler specification " + description + ": missing property d2rq:mappingFile"); 24 | } 25 | if (!description.getProperty(D2RQ.mappingFile).getObject().isURIResource()) { 26 | throw new D2RQException("Error in assembler specification " + description + ": value of d2rq:mappingFile must be a URI"); 27 | } 28 | String mappingFileURI = ((Resource) description.getProperty(D2RQ.mappingFile).getObject()).getURI(); 29 | String resourceBaseURI = null; 30 | Statement stmt = description.getProperty(D2RQ.resourceBaseURI); 31 | if (stmt != null) { 32 | if (!stmt.getObject().isURIResource()) { 33 | throw new D2RQException("Error in assembler specification " + description + ": value of d2rq:resourceBaseURI must be a URI"); 34 | } 35 | resourceBaseURI = ((Resource) stmt.getObject()).getURI(); 36 | } 37 | return new ModelD2RQ(mappingFileURI, resourceBaseURI); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/expr/Add.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.expr; 2 | 3 | import org.d2rq.db.renamer.Renamer; 4 | import org.d2rq.db.types.DataType.GenericType; 5 | 6 | 7 | 8 | public class Add extends BinaryOperator { 9 | 10 | public Add(Expression expr1, Expression expr2) { 11 | super(expr1, expr2, "+", true, GenericType.NUMERIC); 12 | } 13 | 14 | public Expression rename(Renamer columnRenamer) { 15 | return new Add(expr1.rename(columnRenamer), expr2.rename(columnRenamer)); 16 | } 17 | 18 | public boolean equals(Object other) { 19 | if (!(other instanceof Add)) { 20 | return false; 21 | } 22 | Add otherAdd = (Add) other; 23 | if (expr1.equals(otherAdd.expr1) && expr2.equals(otherAdd.expr2)) { 24 | return true; 25 | } 26 | if (expr1.equals(otherAdd.expr2) && expr2.equals(otherAdd.expr1)) { 27 | return true; 28 | } 29 | return false; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/expr/ColumnExpr.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.expr; 2 | 3 | import java.util.Collections; 4 | import java.util.Set; 5 | 6 | import org.d2rq.db.op.DatabaseOp; 7 | import org.d2rq.db.renamer.Renamer; 8 | import org.d2rq.db.schema.ColumnName; 9 | import org.d2rq.db.types.DataType; 10 | import org.d2rq.db.vendor.Vendor; 11 | 12 | 13 | public class ColumnExpr extends Expression { 14 | private final ColumnName column; 15 | 16 | public ColumnExpr(ColumnName column) { 17 | this.column = column; 18 | } 19 | 20 | public Set getColumns() { 21 | return Collections.singleton(column); 22 | } 23 | 24 | public boolean isFalse() { 25 | return false; 26 | } 27 | 28 | public boolean isTrue() { 29 | return false; 30 | } 31 | 32 | public boolean isConstant() { 33 | return false; 34 | } 35 | 36 | public boolean isConstantColumn(ColumnName column, boolean constIfTrue, 37 | boolean constIfFalse, boolean constIfConstantValue) { 38 | if (constIfConstantValue) { 39 | return this.column.equals(column); 40 | } 41 | // TODO: If it's a boolean column (and not some other column implicitly cast to boolean), then we can answer true 42 | return false; 43 | } 44 | 45 | public Expression rename(Renamer columnRenamer) { 46 | return new ColumnExpr(columnRenamer.applyTo(column)); 47 | } 48 | 49 | public String toSQL(DatabaseOp table, Vendor vendor) { 50 | return vendor.toString(column); 51 | } 52 | 53 | public DataType getDataType(DatabaseOp table, Vendor vendor) { 54 | return table.getColumnType(column); 55 | } 56 | 57 | public String toString() { 58 | return "ColumnExpr(" + column + ")"; 59 | } 60 | 61 | public boolean equals(Object other) { 62 | if (!(other instanceof ColumnExpr)) { 63 | return false; 64 | } 65 | return column.equals(((ColumnExpr) other).column); 66 | } 67 | 68 | public int hashCode() { 69 | return column.hashCode(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/expr/Divide.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.expr; 2 | 3 | import org.d2rq.db.renamer.Renamer; 4 | import org.d2rq.db.types.DataType.GenericType; 5 | 6 | 7 | 8 | public class Divide extends BinaryOperator { 9 | 10 | public Divide(Expression expr1, Expression expr2) { 11 | super(expr1, expr2, "/", false, GenericType.NUMERIC); 12 | } 13 | 14 | public Expression rename(Renamer columnRenamer) { 15 | return new Divide(expr1.rename(columnRenamer), expr2.rename(columnRenamer)); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/expr/GreaterThan.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.expr; 2 | 3 | import org.d2rq.db.renamer.Renamer; 4 | import org.d2rq.db.types.DataType.GenericType; 5 | 6 | 7 | 8 | public class GreaterThan extends BinaryOperator { 9 | 10 | public GreaterThan(Expression expr1, Expression expr2) { 11 | super(expr1, expr2, ">", false, GenericType.BOOLEAN); 12 | } 13 | 14 | public Expression rename(Renamer columnRenamer) { 15 | return new GreaterThan(expr1.rename(columnRenamer), expr2.rename(columnRenamer)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/expr/GreaterThanOrEqual.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.expr; 2 | 3 | import org.d2rq.db.renamer.Renamer; 4 | import org.d2rq.db.types.DataType.GenericType; 5 | 6 | 7 | 8 | public class GreaterThanOrEqual extends BinaryOperator { 9 | 10 | public GreaterThanOrEqual(Expression expr1, Expression expr2) { 11 | super(expr1, expr2, ">=", false, GenericType.BOOLEAN); 12 | } 13 | 14 | public Expression rename(Renamer columnRenamer) { 15 | return new GreaterThanOrEqual(expr1.rename(columnRenamer), expr2.rename(columnRenamer)); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/expr/LessThan.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.expr; 2 | 3 | import org.d2rq.db.renamer.Renamer; 4 | import org.d2rq.db.types.DataType.GenericType; 5 | 6 | 7 | 8 | public class LessThan extends BinaryOperator { 9 | 10 | public LessThan(Expression expr1, Expression expr2) { 11 | super(expr1, expr2, "<", false, GenericType.BOOLEAN); 12 | } 13 | 14 | public Expression rename(Renamer columnRenamer) { 15 | return new LessThan(expr1.rename(columnRenamer), expr2.rename(columnRenamer)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/expr/LessThanOrEqual.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.expr; 2 | 3 | import org.d2rq.db.renamer.Renamer; 4 | import org.d2rq.db.types.DataType.GenericType; 5 | 6 | 7 | 8 | public class LessThanOrEqual extends BinaryOperator { 9 | 10 | public LessThanOrEqual(Expression expr1, Expression expr2) { 11 | super(expr1, expr2, "<=", false, GenericType.BOOLEAN); 12 | } 13 | 14 | public Expression rename(Renamer columnRenamer) { 15 | return new LessThanOrEqual(expr1.rename(columnRenamer), expr2.rename(columnRenamer)); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/expr/Multiply.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.expr; 2 | 3 | import org.d2rq.db.renamer.Renamer; 4 | import org.d2rq.db.types.DataType.GenericType; 5 | 6 | 7 | 8 | public class Multiply extends BinaryOperator { 9 | 10 | public Multiply(Expression expr1, Expression expr2) { 11 | super(expr1, expr2, "*", true, GenericType.NUMERIC); 12 | } 13 | 14 | public Expression rename(Renamer columnRenamer) { 15 | return new Multiply(expr1.rename(columnRenamer), expr2.rename(columnRenamer)); 16 | } 17 | 18 | public boolean equals(Object other) { 19 | if (!(other instanceof Multiply)) { 20 | return false; 21 | } 22 | Multiply otherMultiply = (Multiply) other; 23 | if (expr1.equals(otherMultiply.expr1) && expr2.equals(otherMultiply.expr2)) { 24 | return true; 25 | } 26 | if (expr1.equals(otherMultiply.expr2) && expr2.equals(otherMultiply.expr1)) { 27 | return true; 28 | } 29 | return false; 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/expr/Negation.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.expr; 2 | 3 | import java.util.Set; 4 | 5 | import org.d2rq.db.op.DatabaseOp; 6 | import org.d2rq.db.renamer.Renamer; 7 | import org.d2rq.db.schema.ColumnName; 8 | import org.d2rq.db.types.DataType; 9 | import org.d2rq.db.vendor.Vendor; 10 | 11 | 12 | /** 13 | * An expression that negates an underlying expression 14 | * 15 | * @author Christian Becker 16 | */ 17 | public class Negation extends Expression { 18 | 19 | private Expression base; 20 | 21 | public Negation(Expression base) { 22 | this.base = base; 23 | } 24 | 25 | public Expression getBase() { 26 | return base; 27 | } 28 | 29 | public Set getColumns() { 30 | return base.getColumns(); 31 | } 32 | 33 | public boolean isFalse() { 34 | return base.isTrue(); 35 | } 36 | 37 | public boolean isTrue() { 38 | return base.isFalse(); 39 | } 40 | 41 | public boolean isConstant() { 42 | return base.isConstant(); 43 | } 44 | 45 | public boolean isConstantColumn(ColumnName column, boolean constIfTrue, 46 | boolean constIfFalse, boolean constIfConstantValue) { 47 | if (constIfTrue) { 48 | return base.isConstantColumn(column, false, true, false); 49 | } 50 | if (constIfFalse) { 51 | return base.isConstantColumn(column, true, false, false); 52 | } 53 | return base.isConstantColumn(column, false, false, true); 54 | } 55 | 56 | public Expression rename(Renamer columnRenamer) { 57 | return new Negation(base.rename(columnRenamer)); 58 | } 59 | 60 | public String toSQL(DatabaseOp table, Vendor vendor) { 61 | return "NOT (" + base.toSQL(table, vendor) + ")"; 62 | } 63 | 64 | public DataType getDataType(DatabaseOp table, Vendor vendor) { 65 | return base.getDataType(table, vendor); 66 | } 67 | 68 | public String toString() { 69 | return "Negation(" + base + ")"; 70 | } 71 | } -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/expr/Subtract.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.expr; 2 | 3 | import org.d2rq.db.renamer.Renamer; 4 | import org.d2rq.db.types.DataType.GenericType; 5 | 6 | 7 | 8 | public class Subtract extends BinaryOperator { 9 | 10 | public Subtract(Expression expr1, Expression expr2) { 11 | super(expr1, expr2, "-", false, GenericType.NUMERIC); 12 | } 13 | 14 | public Expression rename(Renamer columnRenamer) { 15 | return new Subtract(expr1.rename(columnRenamer), expr2.rename(columnRenamer)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/expr/UnaryMinus.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.expr; 2 | 3 | import java.util.Set; 4 | 5 | import org.d2rq.db.op.DatabaseOp; 6 | import org.d2rq.db.renamer.Renamer; 7 | import org.d2rq.db.schema.ColumnName; 8 | import org.d2rq.db.types.DataType; 9 | import org.d2rq.db.types.DataType.GenericType; 10 | import org.d2rq.db.vendor.Vendor; 11 | 12 | 13 | public class UnaryMinus extends Expression { 14 | 15 | private Expression base; 16 | 17 | public UnaryMinus(Expression base) { 18 | this.base = base; 19 | } 20 | 21 | public Expression getBase() { 22 | return base; 23 | } 24 | 25 | public Set getColumns() { 26 | return base.getColumns(); 27 | } 28 | 29 | public boolean isFalse() { 30 | return false; 31 | } 32 | 33 | public boolean isTrue() { 34 | return false; 35 | } 36 | 37 | public boolean isConstant() { 38 | return base.isConstant(); 39 | } 40 | 41 | public boolean isConstantColumn(ColumnName column, boolean constIfTrue, 42 | boolean constIfFalse, boolean constIfConstantValue) { 43 | if (constIfConstantValue) { 44 | return base.isConstantColumn(column, false, false, true); 45 | } 46 | return false; 47 | } 48 | 49 | public Expression rename(Renamer columnRenamer) { 50 | return new UnaryMinus(base.rename(columnRenamer)); 51 | } 52 | 53 | public String toSQL(DatabaseOp table, Vendor vendor) { 54 | return "- (" + base.toSQL(table, vendor) + ")"; 55 | } 56 | 57 | public DataType getDataType(DatabaseOp table, Vendor vendor) { 58 | return GenericType.NUMERIC.dataTypeFor(vendor); 59 | } 60 | 61 | public String toString() { 62 | return "- (" + base + ")"; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/op/AssertUniqueKeyOp.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.op; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | 6 | import org.d2rq.db.op.DatabaseOp.Wrapper; 7 | import org.d2rq.db.schema.Key; 8 | 9 | /** 10 | * Asserts that a certain combination of columns is unique in the 11 | * wrapped {@link DatabaseOp}, even if no unique key is present on it. 12 | * 13 | * TODO: Remove this class and handle this as a modification to the underlying base table(s)'s definition(s) in RelationBuilder 14 | */ 15 | public class AssertUniqueKeyOp extends Wrapper { 16 | private final Key key; 17 | private final Collection uniqueKeys = new ArrayList(); 18 | 19 | public AssertUniqueKeyOp(DatabaseOp wrapped, Key uniqueKey) { 20 | super(wrapped); 21 | uniqueKeys.addAll(wrapped.getUniqueKeys()); 22 | uniqueKeys.add(uniqueKey); 23 | key = uniqueKey; 24 | } 25 | 26 | public Key getKey() { 27 | return key; 28 | } 29 | 30 | @Override 31 | public Collection getUniqueKeys() { 32 | return uniqueKeys; 33 | } 34 | 35 | public void accept(OpVisitor visitor) { 36 | if (visitor.visitEnter(this)) { 37 | getWrapped().accept(visitor); 38 | } 39 | visitor.visitLeave(this); 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "UniqueKey(" + getWrapped() + "," + key + ")"; 45 | } 46 | 47 | @Override 48 | public int hashCode() { 49 | return getWrapped().hashCode() ^ key.hashCode() ^ 54; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | if (!(o instanceof AssertUniqueKeyOp)) return false; 55 | AssertUniqueKeyOp other = (AssertUniqueKeyOp) o; 56 | if (!getWrapped().equals(other.getWrapped())) return false; 57 | if (!getKey().equals(other.getKey())) return false; 58 | return true; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/op/DistinctOp.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.op; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | 6 | import org.d2rq.db.schema.Key; 7 | 8 | /** 9 | * Removes duplicates from the wrapped {@link DatabaseOp}. 10 | */ 11 | public class DistinctOp extends DatabaseOp.Wrapper { 12 | private final Collection uniqueKeys = new ArrayList(); 13 | 14 | public DistinctOp(DatabaseOp wrapped) { 15 | super(wrapped); 16 | uniqueKeys.addAll(wrapped.getUniqueKeys()); 17 | uniqueKeys.add(Key.createFromColumns(getColumns())); 18 | } 19 | 20 | @Override 21 | public Collection getUniqueKeys() { 22 | return uniqueKeys; 23 | } 24 | 25 | public void accept(OpVisitor visitor) { 26 | if (visitor.visitEnter(this)) { 27 | getWrapped().accept(visitor); 28 | } 29 | visitor.visitLeave(this); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "Distinct(" + getWrapped() + ")"; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return getWrapped().hashCode() ^ 53; 40 | } 41 | 42 | @Override 43 | public boolean equals(Object o) { 44 | if (!(o instanceof DistinctOp)) return false; 45 | DistinctOp other = (DistinctOp) o; 46 | if (!getWrapped().equals(other.getWrapped())) return false; 47 | return true; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/op/EmptyOp.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.op; 2 | 3 | import org.d2rq.db.op.util.OpUtil; 4 | import org.d2rq.db.schema.ColumnName; 5 | import org.d2rq.db.vendor.Vendor; 6 | 7 | 8 | /** 9 | * A {@link DatabaseOp} that is known to be empty (has zero rows). 10 | * Wraps another {@link DatabaseOp} that provides the column metadata 11 | * and {@link Vendor}. 12 | * 13 | * @author Richard Cyganiak (richard@cyganiak.de) 14 | */ 15 | public class EmptyOp extends DatabaseOp.Wrapper { 16 | 17 | public static final EmptyOp NO_COLUMNS = new EmptyOp(DatabaseOp.TRUE); 18 | 19 | public static DatabaseOp create(DatabaseOp original) { 20 | if (OpUtil.isEmpty(original)) return original; 21 | return new EmptyOp(original); 22 | } 23 | 24 | private EmptyOp(DatabaseOp original) { 25 | super(original); 26 | } 27 | 28 | /** 29 | * @return false as the table is known to be empty 30 | */ 31 | @Override 32 | public boolean isNullable(ColumnName column) { 33 | return false; 34 | } 35 | 36 | public void accept(OpVisitor visitor) { 37 | if (visitor.visitEnter(this)) { 38 | getWrapped().accept(visitor); 39 | } 40 | visitor.visitLeave(this); 41 | } 42 | 43 | @Override 44 | public boolean equals(Object o) { 45 | if (!(o instanceof EmptyOp)) return false; 46 | EmptyOp other = (EmptyOp) o; 47 | return getWrapped().equals(other.getWrapped()); 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | return getWrapped().hashCode() ^ 235; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "Empty(" + getWrapped() + ")"; 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/op/NamedOp.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.op; 2 | 3 | import org.d2rq.db.schema.ColumnName; 4 | import org.d2rq.db.schema.TableName; 5 | 6 | 7 | /** 8 | * A {@link DatabaseOp} that can be used directly in the FROM clause of a 9 | * SQL join. The class doesn't do anything particularly interesting; 10 | * it is simply used to enforce the rule that only certain kinds of 11 | * {@link DatabaseOp}s are allowed as children of an InnerJoin. 12 | * 13 | * @author Richard Cyganiak (richard@cyganiak.de) 14 | */ 15 | public abstract class NamedOp implements Comparable, DatabaseOp { 16 | private final TableName name; 17 | 18 | public NamedOp(TableName name) { 19 | this.name = name; 20 | } 21 | 22 | /** 23 | * @return Name in [[CATALOG.]SCHEMA.]TABLE notation 24 | */ 25 | public TableName getTableName() { 26 | return name; 27 | } 28 | 29 | public boolean hasColumn(ColumnName column) { 30 | if (column.isQualified() && !column.getQualifier().equals(getTableName())) { 31 | return false; 32 | } 33 | for (ColumnName ours: getColumns()) { 34 | if (ours.getColumn().equals(column.getColumn())) return true; 35 | } 36 | return false; 37 | } 38 | 39 | /** 40 | * Relations without schema are less than relations with schema. 41 | * Relations without schema are ordered by table name, those with 42 | * schema are ordered by schema name. 43 | */ 44 | public int compareTo(NamedOp other) { 45 | return name.compareTo(((NamedOp) other).name); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/op/SelectOp.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.op; 2 | 3 | import org.d2rq.db.expr.Expression; 4 | 5 | 6 | public class SelectOp extends DatabaseOp.Wrapper { 7 | 8 | public static DatabaseOp select(DatabaseOp original, Expression condition) { 9 | if (condition.isTrue()) { 10 | return original; 11 | } 12 | if (condition.isFalse()) { 13 | return original.getColumns().isEmpty() ? EmptyOp.NO_COLUMNS : EmptyOp.create(original); 14 | } 15 | return new SelectOp(condition, original); 16 | } 17 | 18 | private final Expression condition; 19 | 20 | private SelectOp(Expression condition, DatabaseOp wrapped) { 21 | super(wrapped); 22 | this.condition = condition; 23 | } 24 | 25 | public Expression getCondition() { 26 | return condition; 27 | } 28 | 29 | public void accept(OpVisitor visitor) { 30 | if (visitor.visitEnter(this)) { 31 | getWrapped().accept(visitor); 32 | } 33 | visitor.visitLeave(this); 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "Selection(" + condition + "," + getWrapped() + ")"; 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | return condition.hashCode() ^ getWrapped().hashCode() ^ 442; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object o) { 48 | if (!(o instanceof SelectOp)) return false; 49 | SelectOp other = (SelectOp) o; 50 | return condition.equals(other.condition) && 51 | getWrapped().equals(other.getWrapped()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/renamer/ColumnRenamer.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.renamer; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.Iterator; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import org.d2rq.db.op.NamedOp; 10 | import org.d2rq.db.schema.ColumnName; 11 | import org.d2rq.db.schema.TableName; 12 | 13 | 14 | 15 | 16 | /** 17 | * A {@link Renamer} based on a fixed map of 18 | * original and replacement columns. 19 | * 20 | * @author Richard Cyganiak (richard@cyganiak.de) 21 | */ 22 | public class ColumnRenamer extends Renamer { 23 | private final Map original2NewColumns; 24 | 25 | public ColumnRenamer(Map columns) { 26 | original2NewColumns = columns; 27 | } 28 | 29 | public ColumnName applyTo(ColumnName original) { 30 | return original2NewColumns.containsKey(original) ? 31 | original2NewColumns.get(original) : original; 32 | } 33 | 34 | public NamedOp applyTo(NamedOp table) { 35 | return table; 36 | } 37 | 38 | public TableName applyTo(TableName table) { 39 | return table; 40 | } 41 | 42 | public String toString() { 43 | StringBuffer result = new StringBuffer(); 44 | result.append("ColumnRenamerMap("); 45 | List columns = new ArrayList(original2NewColumns.keySet()); 46 | Collections.sort(columns); 47 | Iterator it = columns.iterator(); 48 | while (it.hasNext()) { 49 | ColumnName column = it.next(); 50 | result.append(column); 51 | result.append(" => "); 52 | result.append(original2NewColumns.get(column)); 53 | if (it.hasNext()) { 54 | result.append(", "); 55 | } 56 | } 57 | result.append(")"); 58 | return result.toString(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/renamer/TableRenamer.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.renamer; 2 | 3 | import java.util.Collections; 4 | import java.util.Map; 5 | 6 | import org.d2rq.db.schema.ColumnName; 7 | import org.d2rq.db.schema.TableName; 8 | 9 | 10 | 11 | /** 12 | * A {@link Renamer} that can be applied to various things in order to 13 | * substitute some tables for other tables, e.g., substitute a 14 | * base table by an alias. 15 | * 16 | * @author Richard Cyganiak (richard@cyganiak.de) 17 | */ 18 | public class TableRenamer extends Renamer { 19 | 20 | public static Renamer create(TableName old, TableName replacement) { 21 | return new TableRenamer(Collections.singletonMap(old, replacement)); 22 | } 23 | 24 | public static Renamer create(Map originalsToReplacements) { 25 | return new TableRenamer(originalsToReplacements); 26 | } 27 | 28 | private final Map fromTo; 29 | 30 | private TableRenamer(Map fromTo) { 31 | this.fromTo = fromTo; 32 | } 33 | 34 | @Override 35 | public ColumnName applyTo(ColumnName original) { 36 | if (!original.isQualified()) return original; 37 | if (!fromTo.containsKey(original.getQualifier())) return original; 38 | return ColumnName.create(fromTo.get(original.getQualifier()), original.getColumn()); 39 | } 40 | 41 | @Override 42 | public TableName applyTo(TableName original) { 43 | return fromTo.containsKey(original) ? fromTo.get(original) : original; 44 | } 45 | 46 | public String toString() { 47 | return "TableRenamer(" + fromTo + ")"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/schema/ColumnDef.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.schema; 2 | 3 | import org.d2rq.db.types.DataType; 4 | import org.d2rq.db.types.SQLGeometry; 5 | 6 | import eu.linkedeodata.geotriples.Config; 7 | 8 | 9 | 10 | public class ColumnDef { 11 | private final Identifier name; 12 | private DataType dataType; 13 | private final boolean isNullable; 14 | 15 | public ColumnDef(Identifier name, DataType dataType, boolean isNullable) { 16 | this.name = name; 17 | if (dataType == null) { 18 | if (Config.GEOMETRY) { 19 | dataType = new SQLGeometry("Geometry"); 20 | Config.GEOMETRY = false; 21 | } 22 | } 23 | this.dataType = dataType; 24 | this.isNullable = isNullable; 25 | } 26 | 27 | public Identifier getName() { 28 | return name; 29 | } 30 | 31 | public DataType getDataType() { 32 | return dataType; 33 | } 34 | 35 | public boolean isNullable() { 36 | return isNullable; 37 | } 38 | 39 | public boolean equals(Object o) { 40 | if (!(o instanceof ColumnDef)) return false; 41 | ColumnDef other = (ColumnDef) o; 42 | return name.equals(other.name) && dataType.equals(other.dataType) && isNullable == other.isNullable; 43 | } 44 | 45 | public int hashCode() { 46 | if (dataType == null) { 47 | dataType = new SQLGeometry("Geometry"); 48 | } 49 | return name.hashCode() ^ dataType.hashCode() ^ (isNullable ? 555 : 556); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/schema/ForeignKey.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.schema; 2 | 3 | /** 4 | * A SQL foreign key. States that the values of some list of local columns, 5 | * if non-null, must exist in some list of referenced columns, which may 6 | * be in the same or a different table. 7 | * 8 | * @author Richard Cyganiak (richard@cyganiak.de) 9 | */ 10 | public class ForeignKey { 11 | private final Key localKey; 12 | private final Key referencedKey; 13 | private final TableName referencedTable; 14 | 15 | public ForeignKey(Key localColumns, Key referencedColumns, TableName referencedTable) { 16 | this.localKey = localColumns; 17 | this.referencedKey = referencedColumns; 18 | this.referencedTable = referencedTable; 19 | } 20 | 21 | public Key getLocalColumns() { 22 | return localKey; 23 | } 24 | 25 | public Key getReferencedColumns() { 26 | return referencedKey; 27 | } 28 | 29 | public TableName getReferencedTable() { 30 | return referencedTable; 31 | } 32 | 33 | public String toString() { 34 | StringBuffer result = new StringBuffer("FK("); 35 | result.append(localKey.getColumns()); 36 | result.append("=>"); 37 | result.append(referencedTable); 38 | result.append(referencedKey.getColumns()); 39 | return result.toString(); 40 | } 41 | 42 | public int hashCode() { 43 | return localKey.hashCode() ^ referencedKey.hashCode() ^ referencedTable.hashCode() ^ 31; 44 | } 45 | 46 | public boolean equals(Object o) { 47 | if (!(o instanceof ForeignKey)) return false; 48 | ForeignKey other = (ForeignKey) o; 49 | return localKey.equals(other.localKey) && 50 | referencedKey.equals(other.referencedKey) && 51 | referencedTable.equals(other.referencedTable); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/types/SQLBit.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.types; 2 | 3 | import org.d2rq.db.vendor.Vendor; 4 | 5 | 6 | public class SQLBit extends DataType { 7 | public SQLBit(String name) { 8 | super(name); 9 | } 10 | @Override 11 | public boolean isIRISafe() { 12 | return true; 13 | } 14 | @Override 15 | public String toSQLLiteral(String value, Vendor vendor) { 16 | // In SQL-92, BIT is a bit string with a special literal form 17 | if (!value.matches("^[01]*$")) { 18 | log.warn("Unsupported BIT format: '" + value + "'; treating as NULL"); 19 | return "NULL"; 20 | } 21 | return "B" + vendor.quoteStringLiteral(value); 22 | } 23 | @Override 24 | public String valueRegex() { 25 | return "^[01]*$"; 26 | } 27 | } -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/types/SQLBoolean.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.types; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | 6 | import org.d2rq.db.vendor.Vendor; 7 | 8 | import com.hp.hpl.jena.vocabulary.XSD; 9 | 10 | 11 | public class SQLBoolean extends DataType { 12 | public SQLBoolean(String name) { 13 | super(name); 14 | } 15 | @Override 16 | public boolean isIRISafe() { 17 | return true; 18 | } 19 | @Override 20 | public String rdfType() { 21 | return XSD.xboolean.getURI(); 22 | } 23 | @Override 24 | public String value(ResultSet resultSet, int column) throws SQLException { 25 | boolean b = resultSet.getBoolean(column); 26 | if (resultSet.wasNull()) return null; 27 | return b ? "true" : "false"; 28 | } 29 | @Override 30 | public String toSQLLiteral(String value, Vendor vendor) { 31 | if ("true".equals(value) || "1".equals(value)) { 32 | return "TRUE"; 33 | } 34 | if ("false".equals(value) || "0".equals(value)) { 35 | return "FALSE"; 36 | } 37 | log.warn("Unsupported BOOLEAN format: '" + value + "'; treating as NULL"); 38 | return "NULL"; 39 | } 40 | } -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/types/SQLCharacterString.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.types; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | 6 | /** 7 | * Datatype for fixed-length character strings (e.g., CHAR but not VARCHAR). 8 | * It does not actually store the specific length. 9 | * 10 | * A difference in behaviour 11 | * from {@link SQLCharacterStringVarying} is that trailing spaces are not 12 | * reported in results. So, even if the database stores 'AAA ', the resulting 13 | * value will be 'AAA'. This seems closer to user expectations. Note that for 14 | * standard SQL and many vendors (but not all), 'AAA '='AAA', so 15 | * selecting still works. Vendors that do not compare strings in that way 16 | * should not use this class, or selecting will break. 17 | */ 18 | public class SQLCharacterString extends DataType { 19 | private final boolean supportsDistinct; 20 | 21 | public SQLCharacterString(String name, boolean supportsDistinct) { 22 | super(name); 23 | this.supportsDistinct = supportsDistinct; 24 | } 25 | 26 | @Override 27 | public boolean supportsDistinct() { 28 | return supportsDistinct; 29 | } 30 | 31 | @Override 32 | public String value(ResultSet resultSet, int column) throws SQLException { 33 | String value = super.value(resultSet, column); 34 | if (value == null) return null; 35 | // Strip trailing spaces 36 | int i = value.length() - 1; 37 | while (i >= 0 && value.charAt(i) == ' ') { 38 | i--; 39 | } 40 | return value.substring(0, i + 1); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/types/SQLCharacterStringVarying.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.types; 2 | 3 | 4 | 5 | public class SQLCharacterStringVarying extends DataType { 6 | private final boolean supportsDistinct; 7 | 8 | public SQLCharacterStringVarying(String name, boolean supportsDistinct) { 9 | super(name); 10 | this.supportsDistinct = supportsDistinct; 11 | } 12 | 13 | @Override 14 | public boolean supportsDistinct() { 15 | return supportsDistinct; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/types/SQLDate.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.types; 2 | 3 | import java.sql.Date; 4 | import java.sql.ResultSet; 5 | import java.sql.SQLException; 6 | import java.util.regex.Pattern; 7 | 8 | import org.d2rq.db.vendor.Vendor; 9 | 10 | import com.hp.hpl.jena.vocabulary.XSD; 11 | 12 | 13 | public class SQLDate extends DataType { 14 | private final static Pattern DATE_PATTERN = 15 | Pattern.compile("^\\d?\\d?\\d?\\d-\\d\\d-\\d\\d$"); 16 | public SQLDate(String name) { 17 | super(name); 18 | } 19 | @Override 20 | public boolean isIRISafe() { 21 | return true; 22 | } 23 | @Override 24 | public String rdfType() { 25 | return XSD.date.getURI(); 26 | } 27 | @Override 28 | public String value(ResultSet resultSet, int column) throws SQLException { 29 | Date date = resultSet.getDate(column); 30 | if (date == null || resultSet.wasNull()) return null; 31 | String s = date.toString(); 32 | // Need at least four digits in year; pad with 0 if necessary 33 | int yearDigits = s.indexOf('-'); 34 | for (int j = 0; j < 4 - yearDigits; j++) { 35 | s = '0' + s; 36 | } 37 | return s; 38 | } 39 | @Override 40 | public String toSQLLiteral(String value, Vendor vendor) { 41 | if (!DATE_PATTERN.matcher(value).matches()) { 42 | log.warn("Unsupported DATE format: '" + value + "'; treating as NULL"); 43 | return "NULL"; 44 | } 45 | return vendor.quoteDateLiteral(value); 46 | } 47 | } -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/types/SQLGeometry.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.types; 2 | 3 | public class SQLGeometry extends DataType { 4 | 5 | public SQLGeometry(String name) { 6 | super(name); 7 | // TODO Auto-generated constructor stub 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/types/SQLInterval.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.types; 2 | 3 | import org.d2rq.db.vendor.Vendor; 4 | 5 | 6 | public class SQLInterval extends DataType { 7 | public SQLInterval(String name) { 8 | super(name); 9 | } 10 | @Override 11 | public boolean isIRISafe() { 12 | return true; 13 | } 14 | @Override 15 | public String toSQLLiteral(String value, Vendor vendor) { 16 | // TODO: Generate appropriate INTERVAL literal 17 | return "NULL"; 18 | } 19 | } -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/types/StrdfWKT.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.types; 2 | 3 | public class StrdfWKT extends DataType { 4 | 5 | public StrdfWKT(String name) { 6 | super(name); 7 | } 8 | 9 | @Override 10 | public String rdfType() { 11 | return "http://strdf.di.uoa.gr/ontology#WKT"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/types/UnsupportedDataType.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.types; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | 6 | import org.d2rq.D2RQException; 7 | import org.d2rq.db.vendor.Vendor; 8 | 9 | 10 | 11 | public class UnsupportedDataType extends DataType { 12 | private final int jdbcType; 13 | public UnsupportedDataType(int jdbcType, String name) { 14 | super(name); 15 | this.jdbcType = jdbcType; 16 | } 17 | @Override 18 | public boolean isUnsupported() { 19 | return true; 20 | } 21 | @Override 22 | public String rdfType() { 23 | throw new D2RQException("Attempted to get rdfType() of a datatype that cannot be mapped to RDF", 24 | D2RQException.DATATYPE_UNMAPPABLE); 25 | } 26 | @Override 27 | public String toSQLLiteral(String value, Vendor vendor) { 28 | throw new D2RQException("Attempted toSQLLiteral('" + value + 29 | "') on a column of a datatype that cannot be mapped to RDF", 30 | D2RQException.DATATYPE_UNMAPPABLE); 31 | } 32 | @Override 33 | public String value(ResultSet resultSet, int column) throws SQLException { 34 | throw new D2RQException("Attempted to get value of a datatype that cannot be mapped to RDF", 35 | D2RQException.DATATYPE_UNMAPPABLE); 36 | } 37 | @Override 38 | public String toString() { 39 | return super.toString() + "{jdbcType:" + jdbcType + ",typeName:'" + name() + "'}"; 40 | } 41 | } -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/db/vendor/InterbaseOrFirebird.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.db.vendor; 2 | 3 | 4 | public class InterbaseOrFirebird extends SQL92 { 5 | 6 | public InterbaseOrFirebird() { 7 | super(false); 8 | } 9 | 10 | public String getTrueTable() { 11 | return "RDB$DATABASE"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/examples/AssemblerExample.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.examples; 2 | 3 | import com.hp.hpl.jena.assembler.Assembler; 4 | import com.hp.hpl.jena.rdf.model.Model; 5 | import com.hp.hpl.jena.rdf.model.Resource; 6 | import com.hp.hpl.jena.util.FileManager; 7 | 8 | public class AssemblerExample { 9 | 10 | public static void main(String[] args) { 11 | // Load assembler specification from file 12 | Model assemblerSpec = FileManager.get().loadModel("doc/example/assembler.ttl"); 13 | 14 | // Get the model resource 15 | Resource modelSpec = assemblerSpec.createResource(assemblerSpec.expandPrefix(":myModel")); 16 | 17 | // Assemble a model 18 | Model m = Assembler.general.openModel(modelSpec); 19 | 20 | // Write it to System.out 21 | m.write(System.out); 22 | 23 | m.close(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/examples/JenaGraphExample.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.examples; 2 | 3 | import java.util.Iterator; 4 | 5 | import org.d2rq.CompiledMapping; 6 | import org.d2rq.jena.GraphD2RQ; 7 | import org.d2rq.lang.D2RQReader; 8 | import org.d2rq.lang.Mapping; 9 | 10 | import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; 11 | import com.hp.hpl.jena.graph.Node; 12 | import com.hp.hpl.jena.graph.Triple; 13 | import com.hp.hpl.jena.rdf.model.Model; 14 | import com.hp.hpl.jena.util.FileManager; 15 | import com.hp.hpl.jena.vocabulary.DC; 16 | 17 | 18 | public class JenaGraphExample { 19 | 20 | public static void main(String[] args) { 21 | // Load mapping file 22 | Model mapModel = FileManager.get().loadModel("doc/example/mapping-iswc.ttl"); 23 | 24 | // Read mapping file 25 | D2RQReader reader = new D2RQReader(mapModel, "http://localhost:2020/"); 26 | Mapping mapping = reader.getMapping(); 27 | 28 | // Compile mapping for D2RQ engine 29 | CompiledMapping compiled = mapping.compile(); 30 | 31 | // Set up the GraphD2RQ 32 | GraphD2RQ g = new GraphD2RQ(compiled); 33 | 34 | // Create a find(spo) pattern 35 | Node subject = Node.ANY; 36 | Node predicate = DC.date.asNode(); 37 | Node object = Node.createLiteral("2003", null, XSDDatatype.XSDgYear); 38 | Triple pattern = new Triple(subject, predicate, object); 39 | 40 | // Query the graph 41 | Iterator it = g.find(pattern); 42 | 43 | // Output query results 44 | while (it.hasNext()) { 45 | Triple t = it.next(); 46 | System.out.println("Published in 2003: " + t.getSubject()); 47 | } 48 | g.close(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/examples/JenaModelExample.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.examples; 2 | 3 | import org.d2rq.jena.ModelD2RQ; 4 | import org.d2rq.vocab.ISWC; 5 | 6 | import com.hp.hpl.jena.rdf.model.Resource; 7 | import com.hp.hpl.jena.rdf.model.StmtIterator; 8 | import com.hp.hpl.jena.sparql.vocabulary.FOAF; 9 | import com.hp.hpl.jena.vocabulary.DC; 10 | import com.hp.hpl.jena.vocabulary.RDF; 11 | 12 | 13 | public class JenaModelExample { 14 | 15 | public static void main(String[] args) { 16 | // Set up the ModelD2RQ using a mapping file 17 | ModelD2RQ m = new ModelD2RQ("file:doc/example/mapping-iswc.ttl"); 18 | 19 | // Find anything with an rdf:type of iswc:InProceedings 20 | StmtIterator paperIt = m.listStatements(null, RDF.type, ISWC.InProceedings); 21 | 22 | // List found papers and print their titles 23 | while (paperIt.hasNext()) { 24 | Resource paper = paperIt.nextStatement().getSubject(); 25 | System.out.println("Paper: " + paper.getProperty(DC.title).getString()); 26 | 27 | // List authors of the paper and print their names 28 | StmtIterator authorIt = paper.listProperties(DC.creator); 29 | while (authorIt.hasNext()) { 30 | Resource author = authorIt.nextStatement().getResource(); 31 | System.out.println("Author: " + author.getProperty(FOAF.name).getString()); 32 | } 33 | System.out.println(); 34 | } 35 | m.close(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/examples/SPARQLExample.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.examples; 2 | 3 | import org.d2rq.jena.ModelD2RQ; 4 | 5 | import com.hp.hpl.jena.query.Query; 6 | import com.hp.hpl.jena.query.QueryExecutionFactory; 7 | import com.hp.hpl.jena.query.QueryFactory; 8 | import com.hp.hpl.jena.query.QuerySolution; 9 | import com.hp.hpl.jena.query.ResultSet; 10 | 11 | 12 | public class SPARQLExample { 13 | 14 | public static void main(String[] args) { 15 | ModelD2RQ m = new ModelD2RQ("file:doc/example/mapping-iswc.ttl"); 16 | String sparql = 17 | "PREFIX dc: " + 18 | "PREFIX foaf: " + 19 | "SELECT ?paperTitle ?authorName WHERE {" + 20 | " ?paper dc:title ?paperTitle . " + 21 | " ?paper dc:creator ?author ." + 22 | " ?author foaf:name ?authorName ." + 23 | "}"; 24 | Query q = QueryFactory.create(sparql); 25 | ResultSet rs = QueryExecutionFactory.create(q, m).execSelect(); 26 | while (rs.hasNext()) { 27 | QuerySolution row = rs.nextSolution(); 28 | System.out.println("Title: " + row.getLiteral("paperTitle").getString()); 29 | System.out.println("Author: " + row.getLiteral("authorName").getString()); 30 | } 31 | m.close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/find/TripleQueryIter.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.find; 2 | 3 | import org.d2rq.algebra.TripleRelation; 4 | 5 | import com.hp.hpl.jena.graph.Triple; 6 | import com.hp.hpl.jena.sparql.engine.binding.Binding; 7 | import com.hp.hpl.jena.sparql.engine.iterator.QueryIter; 8 | import com.hp.hpl.jena.util.iterator.ExtendedIterator; 9 | import com.hp.hpl.jena.util.iterator.NiceIterator; 10 | 11 | 12 | /** 13 | * Wraps a {@link QueryIter} over bindings with three s/p/o variables 14 | * (see {@link TripleRelation}) as an iterator over {@link Triple}s. 15 | * Also adds a {@link #cancel()} method that wouldn't usually be 16 | * available on Jena's triple iterators. 17 | * 18 | * @author Richard Cyganiak (richard@cyganiak.de) 19 | */ 20 | public class TripleQueryIter extends NiceIterator { 21 | 22 | public static ExtendedIterator create(QueryIter wrapped) { 23 | return new TripleQueryIter(wrapped); 24 | } 25 | 26 | private final QueryIter wrapped; 27 | 28 | private TripleQueryIter(QueryIter wrapped) { 29 | this.wrapped = wrapped; 30 | } 31 | 32 | public boolean hasNext() { 33 | return wrapped.hasNext(); 34 | } 35 | 36 | public Triple next() { 37 | Binding b = wrapped.next(); 38 | return new Triple( 39 | b.get(TripleRelation.SUBJECT), 40 | b.get(TripleRelation.PREDICATE), 41 | b.get(TripleRelation.OBJECT)); 42 | } 43 | 44 | public void close() { 45 | wrapped.close(); 46 | } 47 | 48 | /** 49 | * Cancels query execution. Can be called asynchronously. 50 | */ 51 | public void cancel() { 52 | wrapped.cancel(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/lang/AliasDeclaration.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.lang; 2 | 3 | import java.util.Collection; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.d2rq.db.renamer.Renamer; 8 | import org.d2rq.db.renamer.TableRenamer; 9 | import org.d2rq.db.schema.TableName; 10 | 11 | /** 12 | * A "foo AS bar" declaration that establishes an alias for a named table, 13 | * as used with d2rq:alias. 14 | * 15 | * @author Richard Cyganiak (richard@cyganiak.de) 16 | */ 17 | public class AliasDeclaration { 18 | 19 | public static Renamer getRenamer(Collection aliases) { 20 | Map old2new = new HashMap(); 21 | for (AliasDeclaration alias: aliases) { 22 | old2new.put(alias.getOriginal(), alias.getAlias()); 23 | } 24 | return TableRenamer.create(old2new); 25 | } 26 | 27 | private final TableName original; 28 | private final TableName alias; 29 | 30 | public AliasDeclaration(TableName original, TableName alias) { 31 | this.original = original; 32 | this.alias = alias; 33 | } 34 | 35 | public TableName getOriginal() { 36 | return original; 37 | } 38 | 39 | public TableName getAlias() { 40 | return alias; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return Microsyntax.toString(original) + " AS " + alias.getTable().getName(); 46 | } 47 | 48 | public int hashCode() { 49 | return original.hashCode() ^ alias.hashCode() ^ 974; 50 | } 51 | 52 | public boolean equals(Object o) { 53 | if (!(o instanceof AliasDeclaration)) return false; 54 | AliasDeclaration other = (AliasDeclaration) o; 55 | return other.original.equals(original) && other.alias.equals(alias); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/lang/Configuration.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.lang; 2 | 3 | import com.hp.hpl.jena.rdf.model.Resource; 4 | 5 | 6 | /** 7 | * Representation of a d2rq:Configuration from the mapping file. 8 | * 9 | * @author Christian Becker 10 | */ 11 | public class Configuration extends MapObject { 12 | public final static boolean DEFAULT_SERVE_VOCABULARY = true; 13 | public final static boolean DEFAULT_USE_ALL_OPTIMIZATIONS = false; 14 | 15 | private boolean serveVocabulary = DEFAULT_SERVE_VOCABULARY; 16 | private boolean useAllOptimizations = DEFAULT_USE_ALL_OPTIMIZATIONS; 17 | 18 | public Configuration() { 19 | this(null); 20 | } 21 | 22 | public Configuration(Resource resource) { 23 | super(resource); 24 | } 25 | 26 | public boolean getServeVocabulary() { 27 | return serveVocabulary; 28 | } 29 | 30 | public void setServeVocabulary(boolean serveVocabulary) { 31 | this.serveVocabulary = serveVocabulary; 32 | } 33 | 34 | public boolean getUseAllOptimizations() { 35 | return useAllOptimizations; 36 | } 37 | 38 | public void setUseAllOptimizations(boolean useAllOptimizations) { 39 | this.useAllOptimizations = useAllOptimizations; 40 | } 41 | 42 | public String toString() { 43 | return "d2rq:Configuration " + super.toString(); 44 | } 45 | 46 | public void accept(D2RQMappingVisitor visitor) { 47 | visitor.visit(this); 48 | } 49 | } -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/lang/D2RQMappingVisitor.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.lang; 2 | 3 | public interface D2RQMappingVisitor { 4 | boolean visitEnter(Mapping mapping); 5 | void visitLeave(Mapping mapping); 6 | void visit(Configuration configuration); 7 | void visit(Database database); 8 | void visit(TranslationTable translationTable); 9 | boolean visitEnter(ClassMap classMap); 10 | void visitLeave(ClassMap classMap); 11 | void visit(PropertyBridge propertyBridge); 12 | void visit(DownloadMap downloadMap); 13 | 14 | public static class Default implements D2RQMappingVisitor { 15 | public boolean visitEnter(Mapping mapping) { return true; } 16 | public void visitLeave(Mapping mapping) {} 17 | public void visit(Configuration configuration) {} 18 | public void visit(Database database) {} 19 | public void visit(TranslationTable translationTable) {} 20 | public boolean visitEnter(ClassMap classMap) { return true; } 21 | public void visitLeave(ClassMap classMap) {} 22 | public void visit(PropertyBridge propertyBridge) {} 23 | public void visit(DownloadMap downloadMap) {} 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/lang/MapObject.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.lang; 2 | 3 | import org.d2rq.D2RQException; 4 | import org.d2rq.pp.PrettyPrinter; 5 | 6 | import com.hp.hpl.jena.rdf.model.Property; 7 | import com.hp.hpl.jena.rdf.model.Resource; 8 | 9 | 10 | /** 11 | * Abstract base class for classes that represent things in 12 | * the mapping file. 13 | * 14 | * @author Richard Cyganiak (richard@cyganiak.de) 15 | */ 16 | public abstract class MapObject { 17 | private Resource resource; 18 | private String comment = null; 19 | 20 | public MapObject(Resource resource) { 21 | this.resource = resource; 22 | } 23 | 24 | public Resource resource() { 25 | return this.resource; 26 | } 27 | 28 | public String getComment() { 29 | return comment; 30 | } 31 | 32 | public void setComment(String comment) { 33 | this.comment = comment; 34 | } 35 | 36 | public abstract void accept(D2RQMappingVisitor visitor); 37 | 38 | public String toString() { 39 | return PrettyPrinter.toString(this.resource); 40 | } 41 | 42 | protected void assertNotYetDefined(Object object, Property property, int errorCode) { 43 | if (object == null) { 44 | return; 45 | } 46 | throw new D2RQException("Duplicate " + PrettyPrinter.toString(property) + 47 | " for " + this, errorCode); 48 | } 49 | 50 | protected void assertArgumentNotNull(Object object, Property property, int errorCode) { 51 | if (object != null) { 52 | return; 53 | } 54 | throw new D2RQException("Object for " + PrettyPrinter.toString(property) + 55 | " not found at " + this, errorCode); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/mapgen/FilterIncludeExclude.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.mapgen; 2 | 3 | public class FilterIncludeExclude extends Filter { 4 | private final Filter include; 5 | private final Filter exclude; 6 | 7 | public FilterIncludeExclude(Filter include, Filter exclude) { 8 | this.include = include; 9 | this.exclude = exclude; 10 | } 11 | 12 | public boolean matchesSchema(String schema) { 13 | return include.matchesSchema(schema) && !exclude.matchesSchema(schema); 14 | } 15 | 16 | public boolean matchesTable(String schema, String table) { 17 | return include.matchesTable(schema, table) && !exclude.matchesTable(schema, table); 18 | } 19 | 20 | public boolean matchesColumn(String schema, String table, String column) { 21 | return include.matchesColumn(schema, table, column) && !exclude.matchesColumn(schema, table, column); 22 | } 23 | 24 | public String getSingleSchema() { 25 | return include.getSingleSchema(); 26 | } 27 | 28 | public String toString() { 29 | String in = (include == Filter.ALL) ? null : "include(" + include + ")"; 30 | String ex = (exclude == Filter.NOTHING) ? null : "exclude(" + exclude + ")"; 31 | if (in != null) { 32 | if (ex == null) { 33 | return in; 34 | } 35 | return in + "+" + ex; 36 | } 37 | if (ex != null) { 38 | return ex; 39 | } 40 | return "include(all)"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/mapgen/FilterMatchColumn.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.mapgen; 2 | 3 | 4 | public class FilterMatchColumn extends Filter { 5 | private final IdentifierMatcher schema; 6 | private final IdentifierMatcher table; 7 | private final IdentifierMatcher column; 8 | private boolean matchParents; 9 | 10 | public FilterMatchColumn(IdentifierMatcher schema, IdentifierMatcher table, IdentifierMatcher column, boolean matchParents) { 11 | this.schema = schema; 12 | this.table = table; 13 | this.column = column; 14 | this.matchParents = matchParents; 15 | } 16 | 17 | public boolean matchesSchema(String schema) { 18 | if (!matchParents) return false; 19 | return this.schema.matches(schema); 20 | } 21 | 22 | public boolean matchesTable(String schema, String table) { 23 | if (!matchParents) return false; 24 | return this.schema.matches(schema) && this.table.matches(table); 25 | } 26 | 27 | public boolean matchesColumn(String schema, String table, String column) { 28 | return this.schema.matches(schema) && this.table.matches(table) 29 | && this.column.matches(column); 30 | } 31 | 32 | public String getSingleSchema() { return schema.getSingleString(); } 33 | 34 | public String toString() { 35 | StringBuffer result = new StringBuffer("column("); 36 | if (schema != Filter.NULL_MATCHER) { 37 | result.append(schema + "."); 38 | } 39 | if (table != Filter.NULL_MATCHER) { 40 | result.append(table + "."); 41 | } 42 | result.append(column); 43 | result.append(")"); 44 | return result.toString(); 45 | } 46 | } -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/mapgen/FilterMatchSchema.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.mapgen; 2 | 3 | 4 | public class FilterMatchSchema extends Filter { 5 | private final IdentifierMatcher schema; 6 | 7 | public FilterMatchSchema(IdentifierMatcher schema) { 8 | this.schema = schema; 9 | } 10 | 11 | public boolean matchesSchema(String schema) { 12 | return this.schema.matches(schema); 13 | } 14 | 15 | public boolean matchesTable(String schema, String table) { 16 | return matchesSchema(schema); 17 | } 18 | 19 | public boolean matchesColumn(String schema, String table, String column) { 20 | return matchesSchema(schema); 21 | } 22 | 23 | public String getSingleSchema() { return schema.getSingleString(); } 24 | 25 | public String toString() { 26 | StringBuffer result = new StringBuffer("schema("); 27 | result.append(schema); 28 | result.append(")"); 29 | return result.toString(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/mapgen/FilterMatchTable.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.mapgen; 2 | 3 | 4 | public class FilterMatchTable extends Filter { 5 | private final IdentifierMatcher schema; 6 | private final IdentifierMatcher table; 7 | private final boolean matchParents; 8 | 9 | public FilterMatchTable(IdentifierMatcher schema, IdentifierMatcher table, boolean matchParents) { 10 | this.schema = schema; 11 | this.table = table; 12 | this.matchParents = matchParents; 13 | } 14 | 15 | public boolean matchesSchema(String schema) { 16 | if (!matchParents) return false; 17 | return this.schema.matches(schema); 18 | } 19 | 20 | public boolean matchesTable(String schema, String table) { 21 | return this.schema.matches(schema) && this.table.matches(table); 22 | } 23 | 24 | public boolean matchesColumn(String schema, String table, String column) { 25 | return matchesTable(schema, table); 26 | } 27 | 28 | public String getSingleSchema() { return schema.getSingleString(); } 29 | 30 | public String toString() { 31 | StringBuffer result = new StringBuffer("table("); 32 | if (schema != Filter.NULL_MATCHER) { 33 | result.append(schema + "."); 34 | } 35 | result.append(table); 36 | result.append(")"); 37 | return result.toString(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/nodes/FixedNodeMaker.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.nodes; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import java.util.Set; 6 | 7 | import org.d2rq.db.ResultRow; 8 | import org.d2rq.db.op.OrderOp.OrderSpec; 9 | import org.d2rq.db.op.ProjectionSpec; 10 | import org.d2rq.pp.PrettyPrinter; 11 | import org.d2rq.values.ValueMaker; 12 | 13 | import com.hp.hpl.jena.graph.Node; 14 | 15 | 16 | public class FixedNodeMaker implements NodeMaker { 17 | private Node node; 18 | 19 | public FixedNodeMaker(Node node) { 20 | this.node = node; 21 | } 22 | 23 | public Node getFixedNode() { 24 | return node; 25 | } 26 | 27 | public Node makeNode(ResultRow tuple) { 28 | return this.node; 29 | } 30 | 31 | public void describeSelf(NodeSetFilter c) { 32 | c.limitTo(this.node); 33 | } 34 | 35 | public Set projectionSpecs() { 36 | return Collections.emptySet(); 37 | } 38 | 39 | public String toString() { 40 | return "Fixed(" + PrettyPrinter.toString(this.node) + ")"; 41 | } 42 | 43 | public List orderSpecs(boolean ascending) { 44 | return OrderSpec.NONE; 45 | } 46 | 47 | public void accept(NodeMakerVisitor visitor) { 48 | visitor.visit(this); 49 | } 50 | 51 | @Override 52 | public ValueMaker getValueMaker() { 53 | return null; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/nodes/NodeMaker.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.nodes; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import java.util.Set; 6 | 7 | import org.d2rq.db.ResultRow; 8 | import org.d2rq.db.op.OrderOp.OrderSpec; 9 | import org.d2rq.db.op.ProjectionSpec; 10 | import org.d2rq.values.ValueMaker; 11 | 12 | import com.hp.hpl.jena.graph.Node; 13 | 14 | 15 | 16 | /** 17 | * A specification for creating RDF nodes out of a database relation. 18 | * 19 | * @author Richard Cyganiak (richard@cyganiak.de) 20 | */ 21 | public interface NodeMaker { 22 | 23 | public static NodeMaker EMPTY = new EmptyNodeMaker(); 24 | 25 | Set projectionSpecs(); 26 | 27 | void describeSelf(NodeSetFilter c); 28 | 29 | Node makeNode(ResultRow tuple); 30 | ValueMaker getValueMaker(); 31 | /** 32 | * Returns expressions (with possible ASC/DESC marker) that re necessary 33 | * for ordering a relation by the nodes in this NodeMaker. Uses SPARQL 34 | * semantics for ordering. 35 | */ 36 | List orderSpecs(boolean ascending); 37 | 38 | void accept(NodeMakerVisitor visitor); 39 | 40 | public static class EmptyNodeMaker implements NodeMaker { 41 | /** Use {@link NodeMaker#EMPTY} instead */ 42 | private EmptyNodeMaker() {} 43 | public Node makeNode(ResultRow tuple) { return null; } 44 | public void describeSelf(NodeSetFilter c) { c.limitToEmptySet(); } 45 | public Set projectionSpecs() { return Collections.emptySet(); } 46 | public List orderSpecs(boolean ascending) { return Collections.emptyList(); } 47 | public void accept(NodeMakerVisitor visitor) { visitor.visit(this); } 48 | public ValueMaker getValueMaker() { 49 | return null; 50 | } 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/nodes/NodeMakerVisitor.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.nodes; 2 | 3 | import org.d2rq.nodes.NodeMaker.EmptyNodeMaker; 4 | 5 | public interface NodeMakerVisitor { 6 | 7 | void visit(EmptyNodeMaker nodeMaker); 8 | 9 | void visit(FixedNodeMaker nodeMaker); 10 | 11 | void visit(TypedNodeMaker nodeMaker); 12 | } 13 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/nodes/TypedNodeTransformationMakerList.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.nodes; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.d2rq.db.ResultRow; 7 | import org.d2rq.nodes.TypedNodeMaker.NodeType; 8 | import org.d2rq.r2rml.ConstantIRI; 9 | import org.d2rq.values.ValueMaker; 10 | import org.d2rq.vocab.GEOMETRY_FUNCTIONS; 11 | import org.d2rq.vocab.STRING_FUNCTIONS; 12 | 13 | import com.hp.hpl.jena.graph.Node; 14 | import org.locationtech.jts.geom.Geometry; 15 | 16 | import eu.linkedeodata.geotriples.GTransormationFunctions; 17 | import eu.linkedeodata.geotriples.GeneralConnection; 18 | 19 | 20 | /** 21 | * A {@link NodeMaker} that produces nodes from an underlying 22 | * {@link ValueMaker} according to a {@link NodeType}. 23 | * 24 | * TODO: isUnique() should probably not be stored here, but derived from unique key information in the underlying table(s). d2rq:containsDuplicates should be treated as asserting a unique key. 25 | * 26 | * @author Dimitrianos Savva (dimis@di.uoa.gr) 27 | */ 28 | public class TypedNodeTransformationMakerList extends TypedNodeMaker { 29 | 30 | public TypedNodeTransformationMakerList(NodeType nodeType, ValueMaker valueMaker) { 31 | super(nodeType, valueMaker); 32 | } 33 | @Override 34 | public Node makeNode(ResultRow tuple) { 35 | String value = this.valueMaker.makeValue(tuple); 36 | if (value == null) { 37 | return null; 38 | } 39 | return this.nodeType.makeNode(value); 40 | } 41 | 42 | @Override 43 | public void accept(NodeMakerVisitor visitor) { 44 | super.accept(visitor); 45 | //visitor.visit(this); //DIMIS FIX ME NOW!!!!!!! 46 | System.out.print("visit?"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/r2rml/ConflictChecker.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.r2rml; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.d2rq.validation.Report; 7 | import org.d2rq.validation.Message.Problem; 8 | 9 | import com.hp.hpl.jena.rdf.model.Property; 10 | import com.hp.hpl.jena.rdf.model.Resource; 11 | 12 | 13 | public class ConflictChecker { 14 | private final Report report; 15 | private final Map properties = new HashMap(); 16 | 17 | public ConflictChecker(Report report) { 18 | this.report = report; 19 | } 20 | 21 | public void add(Resource resource, Property property) { 22 | if (properties.get(resource) == null) { 23 | properties.put(resource, property); 24 | } 25 | if (!properties.get(resource).equals(property)) { 26 | report.report(Problem.CONFLICTING_PROPERTIES, 27 | resource, new Property[]{properties.get(resource), property}); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/r2rml/ConstantShortcut.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.r2rml; 2 | 3 | import org.d2rq.r2rml.TermMap.ConstantValuedTermMap; 4 | import org.d2rq.r2rml.TermMap.Position; 5 | 6 | import com.hp.hpl.jena.rdf.model.RDFNode; 7 | 8 | 9 | public class ConstantShortcut extends MappingTerm { 10 | 11 | /** 12 | * Always succeeds. Check {@link #isValid()} to see if syntax is ok. 13 | * @return null if arg is null 14 | */ 15 | public static ConstantShortcut create(RDFNode constant) { 16 | return constant == null ? null : new ConstantShortcut(constant); 17 | } 18 | 19 | private final RDFNode constant; 20 | private final ConstantValuedTermMap termMap; 21 | 22 | private ConstantShortcut(RDFNode constant) { 23 | this.constant = constant; 24 | termMap = new ConstantValuedTermMap(); 25 | termMap.setConstant(constant); 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return constant.toString(); 31 | } 32 | 33 | public ConstantValuedTermMap asTermMap() { 34 | return termMap; 35 | } 36 | 37 | public RDFNode asRDFNode() { 38 | return constant; 39 | } 40 | 41 | @Override 42 | public void accept(MappingVisitor visitor) { 43 | acceptAs(visitor, null); 44 | } 45 | 46 | public void acceptAs(MappingVisitor visitor, Position position) { 47 | visitor.visitTerm(this, position); 48 | } 49 | 50 | @Override 51 | public boolean equals(Object other) { 52 | if (!(other instanceof ConstantShortcut)) return false; 53 | return constant.equals(((ConstantShortcut) other).constant); 54 | } 55 | 56 | @Override 57 | public int hashCode() { 58 | return constant.hashCode() ^ 22; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/r2rml/Join.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.r2rml; 2 | 3 | import org.d2rq.vocab.RR; 4 | 5 | 6 | 7 | public class Join extends MappingComponent { 8 | private ColumnNameR2RML child = null; 9 | private ColumnNameR2RML parent = null; 10 | 11 | public ComponentType getType() { 12 | return ComponentType.JOIN; 13 | } 14 | 15 | public void setChild(ColumnNameR2RML child) { 16 | this.child = child; 17 | } 18 | 19 | public ColumnNameR2RML getChild() { 20 | return child; 21 | } 22 | 23 | public void setParent(ColumnNameR2RML parent) { 24 | this.parent = parent; 25 | } 26 | 27 | public ColumnNameR2RML getParent() { 28 | return parent; 29 | } 30 | 31 | @Override 32 | public void accept(MappingVisitor visitor) { 33 | visitor.visitComponent(this); 34 | visitor.visitTermProperty(RR.child, child); 35 | visitor.visitTermProperty(RR.parent, parent); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/r2rml/LanguageTag.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.r2rml; 2 | 3 | 4 | public class LanguageTag extends MappingTerm { 5 | 6 | /** 7 | * Always succeeds. Check {@link #isValid()} to see if syntax is ok. 8 | * @return null if arg is null 9 | */ 10 | public static LanguageTag create(String tag) { 11 | return tag == null ? null : new LanguageTag(tag); 12 | } 13 | 14 | private final String tag; 15 | 16 | private LanguageTag(String tag) { 17 | this.tag = tag.toLowerCase(); 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return tag; 23 | } 24 | 25 | @Override 26 | public void accept(MappingVisitor visitor) { 27 | visitor.visitTerm(this); 28 | } 29 | 30 | public boolean equals(Object other) { 31 | if (!(other instanceof LanguageTag)) return false; 32 | return tag.equals(((LanguageTag) other).tag); 33 | } 34 | 35 | public int hashCode() { 36 | return tag.hashCode() ^ 29673; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/r2rml/MappingTerm.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.r2rml; 2 | 3 | import org.d2rq.db.SQLConnection; 4 | 5 | public abstract class MappingTerm { 6 | 7 | public abstract void accept(MappingVisitor visitor); 8 | 9 | /** 10 | * Determines validity. For components that require a SQL connection, 11 | * this is a best-effort attempt that may not catch certain kinds of errors. 12 | */ 13 | public boolean isValid() { 14 | return isValid(null); 15 | } 16 | 17 | /** 18 | * Determines validity. 19 | */ 20 | public boolean isValid(SQLConnection connection) { 21 | MappingValidator validator = new MappingValidator(null, connection); 22 | accept(validator); 23 | return !validator.getReport().hasError(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/r2rml/RDFComparator.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.r2rml; 2 | 3 | import java.util.Comparator; 4 | 5 | import com.hp.hpl.jena.rdf.model.RDFNode; 6 | 7 | public class RDFComparator { 8 | 9 | public static Comparator getRDFNodeComparator() { 10 | return RDF_NODE; 11 | } 12 | 13 | private final static Comparator RDF_NODE = new Comparator() { 14 | public int compare(RDFNode n1, RDFNode n2) { 15 | if (n1.isURIResource()) { 16 | if (!n2.isURIResource()) return -1; 17 | return n1.asResource().getURI().compareTo(n2.asResource().getURI()); 18 | } 19 | if (n1.isAnon()) { 20 | if (n2.isURIResource()) return 1; 21 | if (n2.isLiteral()) return -1; 22 | return n1.asResource().getId().getLabelString().compareTo(n2.asResource().getId().getLabelString()); 23 | } 24 | if (!n2.isLiteral()) return 1; 25 | int cmpLex = n1.asLiteral().getLexicalForm().compareTo(n2.asLiteral().getLexicalForm()); 26 | if (cmpLex != 0) return cmpLex; 27 | if (n1.asLiteral().getDatatypeURI() == null) { 28 | if (n2.asLiteral().getDatatypeURI() != null) return -1; 29 | return n1.asLiteral().getLanguage().compareTo(n2.asLiteral().getLanguage()); 30 | } 31 | if (n2.asLiteral().getDatatypeURI() == null) return 1; 32 | return n1.asLiteral().getDatatypeURI().compareTo(n2.asLiteral().getDatatypeURI()); 33 | } 34 | }; 35 | } -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/r2rml/ReferencingGeometryAttributes.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.r2rml; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import org.d2rq.vocab.RRX; 7 | 8 | import com.hp.hpl.jena.rdf.model.Resource; 9 | 10 | public class ReferencingGeometryAttributes extends ReferencingObjectMap { 11 | private Resource parentTriplesMap = null; 12 | private Set joinConditions = new HashSet(); 13 | 14 | private Set geometryFunctions= new HashSet();; 15 | 16 | public ComponentType getType() { 17 | return ComponentType.REF_OBJECT_MAP; 18 | } 19 | 20 | public void setParentTriplesMap(Resource parentTriplesMap) { 21 | this.parentTriplesMap = parentTriplesMap; 22 | } 23 | 24 | public Resource getParentTriplesMap() { 25 | return parentTriplesMap; 26 | } 27 | 28 | public Set getJoinConditions() { 29 | return joinConditions; 30 | } 31 | 32 | @Override 33 | public void accept(MappingVisitor visitor) { 34 | super.accept(visitor); 35 | for (Resource function: geometryFunctions) { 36 | //visitor.visitComponentProperty(RRX.transformation, function, ComponentType.FUNCTION); 37 | visitor.visitComponentProperty(RRX.transformation, function, ComponentType.FUNCTION); 38 | } 39 | } 40 | 41 | public Set getGeometryFunctions() { 42 | return geometryFunctions; 43 | } 44 | 45 | public void setGeometryFunctions(Set geometryFunctions) { 46 | this.geometryFunctions = geometryFunctions; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/r2rml/ReferencingGeometryObjectMap.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.r2rml; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import org.d2rq.vocab.RR; 7 | import org.d2rq.vocab.RRX; 8 | 9 | import com.hp.hpl.jena.rdf.model.Resource; 10 | 11 | public class ReferencingGeometryObjectMap extends ReferencingObjectMap { 12 | 13 | 14 | private Set geometryFunctions= new HashSet();; 15 | private ConstantIRI datatype = null; 16 | public ConstantIRI getDatatype() { 17 | return datatype; 18 | } 19 | 20 | public void setDatatype(ConstantIRI datatype) { 21 | this.datatype = datatype; 22 | } 23 | 24 | public ComponentType getType() { 25 | return ComponentType.REF_OBJECT_MAP; 26 | } 27 | 28 | @Override 29 | public void accept(MappingVisitor visitor) { 30 | super.accept(visitor); 31 | visitor.visitTermProperty(RR.datatype, datatype); //04/06/2014 32 | for (Resource function: geometryFunctions) { 33 | //visitor.visitComponentProperty(RRX.transformation, function, ComponentType.FUNCTION); 34 | visitor.visitComponentProperty(RRX.transformation, function, ComponentType.FUNCTION); 35 | } 36 | 37 | } 38 | 39 | public Set getGeometryFunctions() { 40 | return geometryFunctions; 41 | } 42 | 43 | public void setGeometryFunctions(Set geometryFunctions) { 44 | this.geometryFunctions = geometryFunctions; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/r2rml/ReferencingObjectMap.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.r2rml; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import org.d2rq.vocab.RR; 7 | 8 | import com.hp.hpl.jena.rdf.model.Resource; 9 | 10 | 11 | 12 | public class ReferencingObjectMap extends MappingComponent { 13 | private Resource parentTriplesMap = null; 14 | private Set joinConditions = new HashSet(); 15 | 16 | public ComponentType getType() { 17 | return ComponentType.REF_OBJECT_MAP; 18 | } 19 | 20 | public void setParentTriplesMap(Resource parentTriplesMap) { 21 | this.parentTriplesMap = parentTriplesMap; 22 | } 23 | 24 | public Resource getParentTriplesMap() { 25 | return parentTriplesMap; 26 | } 27 | 28 | public Set getJoinConditions() { 29 | return joinConditions; 30 | } 31 | 32 | @Override 33 | public void accept(MappingVisitor visitor) { 34 | visitor.visitComponent(this); 35 | visitor.visitComponentProperty(RR.parentTriplesMap, parentTriplesMap, ComponentType.TRIPLES_MAP); 36 | for (Resource join: joinConditions) { 37 | visitor.visitComponentProperty(RR.joinCondition, join, ComponentType.JOIN); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/server/D2RQDatasetDesc.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.server; 2 | 3 | import org.joseki.DatasetDesc; 4 | import org.joseki.Request; 5 | import org.joseki.Response; 6 | 7 | import com.hp.hpl.jena.query.Dataset; 8 | 9 | /** 10 | * A Joseki dataset description that returns a dataset 11 | * consisting only of the one ModelD2RQ passed in. We need 12 | * this because regular Joseki dataset descriptions are 13 | * initialized from a configuration Model, and we want 14 | * to initialize programmatically. 15 | * 16 | * @author Richard Cyganiak (richard@cyganiak.de) 17 | */ 18 | public class D2RQDatasetDesc extends DatasetDesc { 19 | private AutoReloadableDataset dataset; 20 | 21 | public D2RQDatasetDesc(AutoReloadableDataset dataset) { 22 | super(null); 23 | this.dataset = dataset; 24 | } 25 | 26 | @Override 27 | public Dataset acquireDataset(Request request, Response response) { 28 | dataset.checkMappingFileChanged(); 29 | return this.dataset; 30 | } 31 | 32 | @Override 33 | public void returnDataset(Dataset ds) { 34 | // do nothing 35 | } 36 | 37 | public String toString() { 38 | return "D2RQDatasetDesc(" + this.dataset + ")"; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/server/NamespaceServlet.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.server; 2 | 3 | import java.io.IOException; 4 | import java.util.Iterator; 5 | import java.util.Map.Entry; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.ServletOutputStream; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | public class NamespaceServlet extends HttpServlet { 14 | 15 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 16 | throws ServletException, IOException { 17 | D2RServer d2r = D2RServer.fromServletContext(getServletContext()); 18 | d2r.checkMappingFileChanged(); 19 | response.setContentType("text/javascript"); 20 | ServletOutputStream out = response.getOutputStream(); 21 | d2r.getPrefixes().getNsPrefixMap(); 22 | out.println("// Generated dynamically from the mapping file"); 23 | out.println("var D2R_namespacePrefixes = {"); 24 | Iterator> it = d2r.getPrefixes().getNsPrefixMap().entrySet().iterator(); 25 | while (it.hasNext()) { 26 | Entry entry = it.next(); 27 | out.print("\t\"" + entry.getKey() + "\": \"" + entry.getValue() + "\""); 28 | if (it.hasNext()) { 29 | out.print(","); 30 | } 31 | out.println(); 32 | } 33 | out.println("};"); 34 | } 35 | 36 | private static final long serialVersionUID = -1172261621574174019L; 37 | } 38 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/server/RootServlet.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.server; 2 | 3 | import java.io.IOException; 4 | import java.util.Map; 5 | import java.util.TreeMap; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import org.apache.velocity.context.Context; 13 | 14 | public class RootServlet extends HttpServlet { 15 | 16 | public void doGet(HttpServletRequest request, 17 | HttpServletResponse response) throws IOException, ServletException { 18 | D2RServer server = D2RServer.fromServletContext(getServletContext()); 19 | server.checkMappingFileChanged(); 20 | Map classMapLinks = new TreeMap(); 21 | for (String name: server.getMapping().getResourceCollectionNames()) { 22 | classMapLinks.put(name, server.baseURI() + "directory/" + name); 23 | } 24 | VelocityWrapper velocity = new VelocityWrapper(this, request, response); 25 | Context context = velocity.getContext(); 26 | context.put("rdf_link", server.baseURI() + "all"); 27 | context.put("classmap_links", classMapLinks); 28 | velocity.mergeTemplateXHTML("root_page.vm"); 29 | } 30 | 31 | private static final long serialVersionUID = 8398973058486421941L; 32 | } 33 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/tmp/CompatibleRelationGroup.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.tmp; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import org.d2rq.algebra.NodeRelation; 9 | import org.d2rq.db.SQLConnection; 10 | import org.d2rq.db.op.DatabaseOp; 11 | import org.d2rq.nodes.BindingMaker; 12 | 13 | public class CompatibleRelationGroup { 14 | 15 | public static Collection groupNodeRelations(List relations) { 16 | Collection result = new ArrayList(); 17 | for (NodeRelation relation: relations) { 18 | result.add(new CompatibleRelationGroup(relation)); 19 | } 20 | return result; 21 | } 22 | 23 | private final NodeRelation relation; 24 | 25 | public CompatibleRelationGroup(NodeRelation relation) { 26 | this.relation = relation; 27 | } 28 | 29 | public SQLConnection getSQLConnection() { 30 | return relation.getSQLConnection(); 31 | } 32 | 33 | public DatabaseOp baseRelation() { 34 | return relation.getBaseTabular(); 35 | } 36 | 37 | public Collection bindingMakers() { 38 | return Collections.singleton(relation.getBindingMaker()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/tmp/JoinOptimizer.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.tmp; 2 | 3 | import org.d2rq.algebra.NodeRelation; 4 | 5 | public class JoinOptimizer { 6 | public static NodeRelation optimize(NodeRelation r) { return r; } 7 | } 8 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/tmp/QueryEngineD2RQ.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.tmp; 2 | 3 | import com.hp.hpl.jena.sparql.engine.QueryEngineFactory; 4 | import com.hp.hpl.jena.sparql.engine.main.QueryEngineMain; 5 | 6 | public class QueryEngineD2RQ { 7 | public static void register() {} 8 | public static QueryEngineFactory getFactory() { 9 | return QueryEngineMain.getFactory(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/validation/ValidatingRDFParser.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.validation; 2 | 3 | import org.d2rq.validation.Message.Problem; 4 | import org.openjena.riot.RiotException; 5 | 6 | import com.hp.hpl.jena.rdf.model.Model; 7 | import com.hp.hpl.jena.shared.JenaException; 8 | import com.hp.hpl.jena.util.FileManager; 9 | 10 | 11 | public class ValidatingRDFParser { 12 | private final String file; 13 | private final Report report; 14 | 15 | public ValidatingRDFParser(String file, Report report) { 16 | this.file = file; 17 | this.report = report; 18 | } 19 | 20 | public Model parse() { 21 | try { 22 | return FileManager.get().loadModel(file); 23 | } catch (JenaException ex) { 24 | Throwable cause = ex.getCause(); 25 | if (cause instanceof RiotException) { 26 | report.report(Problem.SYNTAX_ERROR, cause.getMessage()); 27 | } else { 28 | report.report(Problem.IO_ERROR, ex.getMessage()); 29 | } 30 | return null; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/values/ColumnValueTransformationMaker.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.values; 2 | 3 | import org.d2rq.db.schema.ColumnName; 4 | 5 | 6 | /** 7 | * A {@link ValueMaker} that takes its values from a transformation of a single 8 | * column. 9 | * 10 | * @author Dimitrianos Savva (dimis@di.uoa.gr) 11 | * 12 | * WE DO NOT NEED THIS ANYMORE 13 | */ 14 | public class ColumnValueTransformationMaker extends ColumnValueMaker { 15 | 16 | public ColumnValueTransformationMaker(ColumnName column) { 17 | super(column); 18 | // TODO Auto-generated constructor stub 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/vocab/JDBC.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.vocab; 2 | import com.hp.hpl.jena.rdf.model.Model; 3 | import com.hp.hpl.jena.rdf.model.ModelFactory; 4 | import com.hp.hpl.jena.rdf.model.Property; 5 | import com.hp.hpl.jena.rdf.model.Resource; 6 | 7 | /** 8 | * Open namespace for JDBC connection properties. A JDBC connection 9 | * property named foo is modelled as an RDF property with 10 | * URI http://d2rq.org/terms/jdbc/foo. Values are plain string 11 | * literals. 12 | * 13 | * @author Richard Cyganiak 14 | */ 15 | public class JDBC { 16 | 17 | /** 18 | * The RDF model that holds the vocabulary terms. 19 | */ 20 | private static Model model = ModelFactory.createDefaultModel(); 21 | 22 | /** 23 | * The namespace of the vocabulary as a string. 24 | */ 25 | public static final String NS = "http://d2rq.org/terms/jdbc/"; 26 | 27 | /** 28 | * The namespace of the vocabulary as a string. 29 | * @see #NS 30 | */ 31 | public static String getURI() { 32 | return NS; 33 | } 34 | 35 | /** 36 | * The namespace of the vocabulary as a resource. 37 | */ 38 | public static final Resource NAMESPACE = model.createResource(NS); 39 | 40 | public static Property getProperty(String key) { 41 | return model.createProperty(NS, key); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/vocab/META.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.vocab; 2 | /** 3 | * Specifies the template variable prefix URI for the metadata extension 4 | * 5 | * @author Hannes Muehleisen (hannes@muehleisen.org) 6 | */ 7 | 8 | public class META { 9 | 10 | public static final String NS = "http://www4.wiwiss.fu-berlin.de/bizer/d2r-server/metadata#"; 11 | } 12 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/vocab/RRExtra.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.vocab; 2 | 3 | import com.hp.hpl.jena.rdf.model.Resource; 4 | 5 | 6 | /** 7 | * Extra terms that should be in the R2RML vocabulary but aren't. 8 | * 9 | * @author Richard Cyganiak (richard@cyganiak.de) 10 | */ 11 | public class RRExtra { 12 | 13 | public static Resource Mapping = 14 | RR.SubjectMap.getModel().createResource(RR.getURI() + "Mapping"); 15 | public static Resource TermMap = 16 | RR.SubjectMap.getModel().createResource(RR.getURI() + "TermMap"); 17 | public static Resource ConstantValuedTermMap = 18 | RR.SubjectMap.getModel().createResource(RR.getURI() + "ConstantValuedTermMap"); 19 | public static Resource ColumnValuedTermMap = 20 | RR.SubjectMap.getModel().createResource(RR.getURI() + "ColumnValuedTermMap"); 21 | public static Resource TemplateValuedTermMap = 22 | RR.SubjectMap.getModel().createResource(RR.getURI() + "TemplateValuedTermMap"); 23 | public static Resource TransformationValuedTermMap = 24 | RR.SubjectMap.getModel().createResource(RR.getURI() + "TransformationValuedTermMap"); 25 | 26 | public static Resource SQL2008 = 27 | RR.SubjectMap.getModel().createResource(RR.getURI() + "SQL2008"); 28 | } 29 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/vocab/RRX.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.vocab; 2 | 3 | import com.hp.hpl.jena.rdf.model.Model; 4 | import com.hp.hpl.jena.rdf.model.ModelFactory; 5 | import com.hp.hpl.jena.rdf.model.Property; 6 | import com.hp.hpl.jena.rdf.model.Resource; 7 | 8 | /** SEE WP2 deliverable 1*/ 9 | public class RRX { 10 | /**

The RDF model that holds the vocabulary terms

*/ 11 | private static Model m_model = ModelFactory.createDefaultModel(); 12 | 13 | /**

The namespace of the vocabulary as a string

*/ 14 | private static final String NSXfunctions = "http://www.w3.org/ns/r2rml-ext/functions/def/"; 15 | private static final String NSX = "http://www.w3.org/ns/r2rml-ext#"; 16 | 17 | public static String getURI() { return NSX; } 18 | public static String getFunctionsURI() { return NSXfunctions; } 19 | /**

Represents a logical geometry table.

*/ 20 | 21 | public static final Resource LogicalGeometryTable = m_model.createResource( "http://www.w3.org/ns/r2rml#LogicalGeometryTable" ); 22 | 23 | public static final Resource TransformationMap = m_model.createResource( "http://www.w3.org/ns/r2rml-ext#TransformationMap" ); 24 | 25 | public static final Resource ArgumentMap = m_model.createResource( "http://www.w3.org/ns/r2rml-ext#ArgumentMap" ); 26 | 27 | public static final Resource Function = m_model.createResource( "http://www.w3.org/ns/r2rml-ext#Function" ); 28 | 29 | public static final Property function = m_model.createProperty( "http://www.w3.org/ns/r2rml-ext#function"); 30 | 31 | public static final Property argumentMap = m_model.createProperty( "http://www.w3.org/ns/r2rml-ext#argumentMap"); 32 | 33 | public static final Property transformation = m_model.createProperty( "http://www.w3.org/ns/r2rml-ext#transformation"); 34 | } 35 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/vocab/SD.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.vocab; 2 | 3 | import com.hp.hpl.jena.rdf.model.Model; 4 | import com.hp.hpl.jena.rdf.model.ModelFactory; 5 | import com.hp.hpl.jena.rdf.model.Property; 6 | import com.hp.hpl.jena.rdf.model.Resource; 7 | 8 | public class SD { 9 | private static Model vocabModel = ModelFactory.createDefaultModel(); 10 | 11 | public static final String NS = "http://www.w3.org/ns/sparql-service-description#"; 12 | 13 | public static final Resource NAMESPACE = vocabModel.createResource(NS); 14 | 15 | public static final Resource Service = vocabModel.createResource(NS 16 | + "Service"); 17 | 18 | public static final Resource Dataset = vocabModel.createResource(NS 19 | + "Dataset"); 20 | 21 | public static final Resource Graph = vocabModel.createResource(NS 22 | + "Graph"); 23 | 24 | public static final Property url = vocabModel 25 | .createProperty(NS + "url"); 26 | 27 | public static final Property defaultDatasetDescription = vocabModel 28 | .createProperty(NS + "defaultDatasetDescription"); 29 | 30 | public static final Property defaultGraph = vocabModel 31 | .createProperty(NS + "defaultGraph"); 32 | 33 | public static final Property resultFormat = vocabModel 34 | .createProperty(NS + "resultFormat"); 35 | 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/vocab/STRING_FUNCTIONS.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.vocab; 2 | 3 | import java.sql.Types; 4 | 5 | import org.d2rq.db.types.DataType; 6 | import org.d2rq.db.types.SQLBoolean; 7 | import org.d2rq.db.types.SQLExactNumeric; 8 | import org.d2rq.r2rml.ConstantIRI; 9 | 10 | import com.hp.hpl.jena.rdf.model.Model; 11 | import com.hp.hpl.jena.rdf.model.ModelFactory; 12 | 13 | import eu.linkedeodata.geotriples.GMLLiteral; 14 | import eu.linkedeodata.geotriples.WKTLiteral; 15 | 16 | /** SEE WP2 deliverable 1 */ 17 | public class STRING_FUNCTIONS { 18 | 19 | 20 | /** 21 | *

22 | * The RDF model that holds the vocabulary terms 23 | *

24 | */ 25 | @SuppressWarnings("unused") 26 | private static Model m_model = ModelFactory.createDefaultModel(); 27 | 28 | /** 29 | *

30 | * Represents the geometry function dimension. 31 | *

32 | */ 33 | public static final ConstantIRI asCAPITAL = ConstantIRI.create(RRX 34 | .getFunctionsURI() + "asCAPITAL"); 35 | public static final ConstantIRI asLOWER = ConstantIRI.create(RRX 36 | .getFunctionsURI() + "asLOWER"); 37 | public static final ConstantIRI SubString = ConstantIRI.create(RRX 38 | .getFunctionsURI() + "SubString"); 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/vocab/VoID.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.vocab; 2 | 3 | import com.hp.hpl.jena.rdf.model.Model; 4 | import com.hp.hpl.jena.rdf.model.ModelFactory; 5 | import com.hp.hpl.jena.rdf.model.Property; 6 | import com.hp.hpl.jena.rdf.model.Resource; 7 | 8 | public class VoID { 9 | private static Model vocabModel = ModelFactory.createDefaultModel(); 10 | 11 | public static final String NS = "http://rdfs.org/ns/void#"; 12 | 13 | public static final Resource NAMESPACE = vocabModel.createResource(NS); 14 | 15 | public static final Resource Dataset = vocabModel.createResource(NS 16 | + "Dataset"); 17 | 18 | public static final Property homepage = vocabModel 19 | .createProperty("http://xmlns.com/foaf/0.1/homepage"); 20 | 21 | public static final Property feature = vocabModel 22 | .createProperty(NS + "feature"); 23 | 24 | public static final Property rootResource = vocabModel 25 | .createProperty(NS + "rootResource"); 26 | 27 | public static final Property uriSpace = vocabModel 28 | .createProperty(NS + "uriSpace"); 29 | 30 | public static final Property class_ = vocabModel 31 | .createProperty(NS + "class"); 32 | 33 | public static final Property property = vocabModel 34 | .createProperty(NS + "property"); 35 | 36 | public static final Property vocabulary = vocabModel 37 | .createProperty(NS + "vocabulary"); 38 | 39 | public static final Property classPartition = vocabModel 40 | .createProperty(NS + "classPartition"); 41 | 42 | public static final Property propertyPartition = vocabModel 43 | .createProperty(NS + "propertyPartition"); 44 | 45 | public static final Property sparqlEndpoint = vocabModel 46 | .createProperty(NS + "sparqlEndpoint"); 47 | 48 | public static final Property inDataset = vocabModel 49 | .createProperty(NS + "inDataset"); 50 | } 51 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-r2rml/src/main/java/org/d2rq/writer/MappingWriter.java: -------------------------------------------------------------------------------- 1 | package org.d2rq.writer; 2 | 3 | import java.io.OutputStream; 4 | import java.io.Writer; 5 | import java.util.List; 6 | 7 | import org.d2rq.r2rml.TermMap; 8 | 9 | import com.hp.hpl.jena.rdf.model.Property; 10 | 11 | public interface MappingWriter { 12 | 13 | void write(OutputStream outStream); 14 | 15 | void write(Writer outWriter); 16 | 17 | void visitTermProperty(Property property, List termMaps); 18 | 19 | } -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/core/ArgumentPosition.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.core; 2 | 3 | public class ArgumentPosition { 4 | public ArgumentPosition(int argumentList, int actualPosition) { 5 | super(); 6 | this.argumentList = argumentList; 7 | this.actualPosition = actualPosition; 8 | } 9 | public int getArgumentList() { 10 | return argumentList; 11 | } 12 | public void setArgumentList(int argumentList) { 13 | this.argumentList = argumentList; 14 | } 15 | public int getActualPosition() { 16 | return actualPosition; 17 | } 18 | public void setActualPosition(int actualPosition) { 19 | this.actualPosition = actualPosition; 20 | } 21 | private int argumentList; 22 | private int actualPosition; 23 | } 24 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/core/Config.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.core; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * here lie the default parameters of the application. For instance, which epsg code should be used if non is specified explicitly? 7 | */ 8 | public class Config { 9 | public static final String GEOTRIPLES_AUTO_ID = "GeoTriplesID"; 10 | public static int EPSG_CODE = 4326; 11 | public static boolean GEOMETRY = false; 12 | public static String VOCABULARY = "GeoSPARQL"; 13 | 14 | 15 | public static HashMap variables=new HashMap<>(); 16 | } 17 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/core/KeyGenerator.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.core; 2 | 3 | import java.util.HashMap; 4 | /** 5 | * Generates a key to be used as private key for shape file table. 6 | * Generates either on the fly(Generate), or using a hash map of strings(GenerateFromMap) 7 | * @author Dimitrianos Savva (dimis@di.uoa.gr) 8 | */ 9 | public class KeyGenerator { 10 | public enum Use{ 11 | USE_PREV, 12 | NEW_ONE, 13 | } 14 | private int key=0; 15 | private HashMap memory; 16 | public KeyGenerator() 17 | { 18 | memory=new HashMap(); 19 | } 20 | 21 | public int GenerateFromMap(String somekey) 22 | { 23 | if(memory.containsKey(somekey)) 24 | { 25 | return memory.get(somekey); 26 | } 27 | else 28 | { 29 | memory.put(somekey, ++key); 30 | return key; 31 | } 32 | } 33 | 34 | public int Generate(Use purpose) throws Exception 35 | { 36 | if(purpose.equals(Use.USE_PREV)) 37 | { 38 | return key; 39 | } 40 | else if(purpose.equals(Use.NEW_ONE)) 41 | { 42 | return ++key; 43 | } 44 | else 45 | { 46 | throw new Exception("Use purpose unsupported"); 47 | } 48 | } 49 | 50 | public int Generate() throws Exception 51 | { 52 | return Generate(Use.NEW_ONE); 53 | } 54 | 55 | public String Generate(String prefix,Use purpose) throws Exception 56 | { 57 | if(purpose.equals(Use.USE_PREV)) 58 | { 59 | return String.format("%s%d",prefix,key); 60 | } 61 | else if(purpose.equals(Use.NEW_ONE)) 62 | { 63 | return String.format("%s%d",prefix,++key); 64 | } 65 | else 66 | { 67 | throw new Exception("Use purpose unsupported"); 68 | } 69 | } 70 | public String Generate(String prefix) throws Exception 71 | { 72 | return Generate(prefix,Use.NEW_ONE); 73 | } 74 | 75 | public void reset() { 76 | key=0; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/core/MalformedGeometryException.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.core; 2 | 3 | public class MalformedGeometryException extends Exception { 4 | 5 | 6 | public MalformedGeometryException(String message) { 7 | super(message); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/core/RMLPerformer.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.core; 2 | 3 | import net.antidot.semantic.rdf.model.impl.sesame.SesameDataSet; 4 | 5 | import java.util.Collection; 6 | 7 | import org.openrdf.model.Resource; 8 | import org.openrdf.model.Statement; 9 | 10 | import be.ugent.mmlab.rml.model.TriplesMap; 11 | 12 | /** 13 | * 14 | * Interface for executing context-dependent operations like a regular object map, or a join 15 | * 16 | * @author mielvandersande 17 | */ 18 | public interface RMLPerformer { 19 | /** 20 | * Perform the action 21 | * 22 | * @param node current object in the iteration 23 | * @param dataset dataset for endresult 24 | * @param map current triple map that is being processed 25 | */ 26 | public Collection perform(Object node, SesameDataSet dataset, TriplesMap map); 27 | 28 | public Collection perform(Object node, SesameDataSet dataset, TriplesMap map, Resource subject); 29 | 30 | public Object getCurrentNode(); 31 | } 32 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/dataset/StatementCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package be.ugent.mmlab.rml.dataset; 6 | 7 | import org.openrdf.model.Statement; 8 | import org.openrdf.rio.helpers.RDFHandlerBase; 9 | 10 | /** 11 | * 12 | * @author mielvandersande 13 | */ 14 | class StatementCounter extends RDFHandlerBase { 15 | 16 | private int countedStatements = 0; 17 | 18 | @Override 19 | public void handleStatement(Statement st) { 20 | countedStatements++; 21 | } 22 | 23 | public int getCountedStatements() { 24 | return countedStatements; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/dataset/TupleMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package be.ugent.mmlab.rml.dataset; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Collection; 9 | import java.util.Iterator; 10 | import java.util.List; 11 | import java.util.ListIterator; 12 | import org.openrdf.model.Resource; 13 | import org.openrdf.model.Statement; 14 | import org.openrdf.model.URI; 15 | import org.openrdf.model.Value; 16 | import org.openrdf.rio.helpers.RDFHandlerBase; 17 | 18 | /** 19 | * 20 | * @author mielvandersande 21 | */ 22 | class TupleMatcher extends RDFHandlerBase { 23 | 24 | private List statements = new ArrayList<>(); 25 | private Resource s; 26 | private URI p; 27 | private Value o; 28 | 29 | public TupleMatcher(Resource s, URI p, Value o, Resource... contexts) { 30 | this.s = s; 31 | this.p = p; 32 | this.o = o; 33 | } 34 | 35 | public List getStatements() { 36 | return statements; 37 | } 38 | 39 | @Override 40 | public void handleStatement(Statement st) { 41 | if ((this.s == null || this.s.equals(st.getSubject())) && (this.p == null || this.p.equals(st.getPredicate())) && (this.o == null || this.o.equals(st.getObject()))) { 42 | statements.add(st); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/Config.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.util.HashMap; 4 | 5 | /*************************************************************************** 6 | * 7 | * @author: dimis (dimis@di.uoa.gr) 8 | * 9 | ****************************************************************************/ 10 | public class Config { 11 | public static String EPSG_CODE = "4326"; 12 | public static boolean useGML3=true; 13 | public static boolean useGML2=false; 14 | public static boolean useKML_22=false; 15 | public static boolean useDGALLibrary=false; 16 | public static boolean useOldDBProcessor=false; 17 | public static final HashMap user_namespaces=new HashMap(); 18 | public static final String GEOTRIPLES_AUTO_ID = "GeoTriplesID"; 19 | public static void setGML3() { 20 | useGML3=true; 21 | useGML2=false; 22 | useKML_22=false; 23 | } 24 | public static void setGML2() { 25 | useGML3=false; 26 | useGML2=true; 27 | useKML_22=false; 28 | } 29 | public static void setKML() { 30 | useGML3=false; 31 | useGML2=false; 32 | useKML_22=true; 33 | } 34 | public static void setGDAL() { 35 | useDGALLibrary=true; 36 | } 37 | public static void setOldDBProcessor() { 38 | useOldDBProcessor=true; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/Function.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.util.List; 4 | 5 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 6 | 7 | public interface Function { 8 | 9 | public List execute(List list,List qlterms) throws Exception; 10 | 11 | public Object execute(Object obj, QLTerm qlterm) throws Exception; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionAdd.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 13 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 14 | 15 | 16 | public class FunctionAdd extends AbstractFunction implements Function { 17 | @Override 18 | public List execute( 19 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException { 20 | List valueList = new ArrayList<>(); 21 | valueList.add( 22 | String.valueOf(Double.valueOf(arguments.get(0).toString())+Double.valueOf(arguments.get(1).toString()))); 23 | 24 | return valueList; 25 | } 26 | 27 | @Override 28 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException { 29 | return null; 30 | 31 | } 32 | } 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionAlreadyExists.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | public class FunctionAlreadyExists extends Exception { 4 | /** 5 | * 6 | */ 7 | private static final long serialVersionUID = 2643810499378545795L; 8 | public FunctionAlreadyExists() { 9 | super(); 10 | } 11 | public FunctionAlreadyExists(String message) { 12 | super(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionArea.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import org.locationtech.jts.geom.Geometry; 13 | import org.locationtech.jts.io.ParseException; 14 | 15 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 16 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 17 | 18 | 19 | public class FunctionArea extends GeometryFunction implements Function { 20 | 21 | @Override 22 | public List execute( 23 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 24 | List valueList = new ArrayList<>(); 25 | 26 | Geometry geometry = computeGeometry(arguments.get(0), qlterms.get(0)); 27 | valueList.add(GTransormationFunctions.area( 28 | (Geometry) geometry)); 29 | return valueList; 30 | } 31 | 32 | 33 | @Override 34 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 35 | 36 | Geometry geometry = computeGeometry(argument, qlterm); 37 | return GTransormationFunctions.area((Geometry) geometry); 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionCentroidX.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import org.locationtech.jts.geom.Geometry; 13 | import org.locationtech.jts.io.ParseException; 14 | 15 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 16 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 17 | 18 | 19 | public class FunctionCentroidX extends GeometryFunction implements Function { 20 | 21 | @Override 22 | public List execute( 23 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 24 | List valueList = new ArrayList<>(); 25 | 26 | Geometry geometry = computeGeometry(arguments.get(0), qlterms.get(0)); 27 | valueList.add(GTransormationFunctions.centroidx( 28 | (Geometry) geometry)); 29 | return valueList; 30 | } 31 | 32 | 33 | @Override 34 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 35 | Geometry geometry = computeGeometry(argument, qlterm); 36 | return GTransormationFunctions.centroidx((Geometry) geometry); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionCentroidY.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import org.locationtech.jts.geom.Geometry; 13 | import org.locationtech.jts.io.ParseException; 14 | 15 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 16 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 17 | 18 | 19 | public class FunctionCentroidY extends GeometryFunction implements Function { 20 | 21 | @Override 22 | public List execute( 23 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 24 | List valueList = new ArrayList<>(); 25 | 26 | Geometry geometry = computeGeometry(arguments.get(0), qlterms.get(0)); 27 | valueList.add(GTransormationFunctions.centroidy( 28 | (Geometry) geometry)); 29 | return valueList; 30 | } 31 | 32 | 33 | @Override 34 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 35 | 36 | Geometry geometry = computeGeometry(argument, qlterm); 37 | return GTransormationFunctions.centroidy( 38 | (Geometry) geometry); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionContains.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import org.locationtech.jts.geom.Geometry; 13 | import org.locationtech.jts.io.ParseException; 14 | 15 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 16 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 17 | 18 | 19 | public class FunctionContains extends GeometryFunction implements Function { 20 | 21 | @Override 22 | public List execute( 23 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 24 | List valueList = new ArrayList<>(); 25 | 26 | Geometry geometry1 = computeGeometry(arguments.get(0), qlterms.get(0)); 27 | Geometry geometry2 = computeGeometry(arguments.get(1), qlterms.get(1)); 28 | valueList.add(GTransormationFunctions.contains(geometry1, geometry2)); 29 | return valueList; 30 | } 31 | 32 | 33 | @Override 34 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 35 | 36 | return null; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionCrosses.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import org.locationtech.jts.geom.Geometry; 13 | import org.locationtech.jts.io.ParseException; 14 | 15 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 16 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 17 | 18 | 19 | public class FunctionCrosses extends GeometryFunction implements Function { 20 | 21 | @Override 22 | public List execute( 23 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 24 | List valueList = new ArrayList<>(); 25 | 26 | Geometry geometry1 = computeGeometry(arguments.get(0), qlterms.get(0)); 27 | Geometry geometry2 = computeGeometry(arguments.get(1), qlterms.get(1)); 28 | valueList.add(GTransormationFunctions.crosses(geometry1, geometry2)); 29 | return valueList; 30 | } 31 | 32 | @Override 33 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 34 | 35 | return null; 36 | 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionDisjoint.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import org.locationtech.jts.geom.Geometry; 13 | import org.locationtech.jts.io.ParseException; 14 | 15 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 16 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 17 | 18 | 19 | public class FunctionDisjoint extends GeometryFunction implements Function { 20 | 21 | @Override 22 | public List execute( 23 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 24 | List valueList = new ArrayList<>(); 25 | 26 | Geometry geometry1 = computeGeometry(arguments.get(0), qlterms.get(0)); 27 | Geometry geometry2 = computeGeometry(arguments.get(1), qlterms.get(1)); 28 | valueList.add(GTransormationFunctions.disjoint(geometry1, geometry2)); 29 | return valueList; 30 | } 31 | 32 | @Override 33 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 34 | 35 | return null; 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionDistance.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import org.locationtech.jts.geom.Geometry; 13 | import org.locationtech.jts.io.ParseException; 14 | 15 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 16 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 17 | 18 | 19 | public class FunctionDistance extends GeometryFunction implements Function { 20 | 21 | @Override 22 | public List execute( 23 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 24 | List valueList = new ArrayList<>(); 25 | 26 | Geometry geometry1 = computeGeometry(arguments.get(0), qlterms.get(0)); 27 | Geometry geometry2 = computeGeometry(arguments.get(1), qlterms.get(1)); 28 | //System.out.println(geometry1); 29 | //System.out.println(geometry2); 30 | valueList.add(GTransormationFunctions.distance(geometry1, geometry2)); 31 | //System.out.println(valueList.get(0)); 32 | return valueList; 33 | } 34 | 35 | 36 | @Override 37 | public Object execute( 38 | Object argument,QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 39 | 40 | return null; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionEQUI.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 13 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 14 | 15 | 16 | public class FunctionEQUI extends AbstractFunction implements Function { 17 | 18 | @Override 19 | public List execute( 20 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException { 21 | List valueList = new ArrayList<>(); 22 | 23 | valueList.add(((Boolean)( 24 | arguments.get(0).equals(arguments.get(1)))).toString()); 25 | return valueList; 26 | } 27 | 28 | @Override 29 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException { 30 | 31 | return null; 32 | } 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionEquals.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import org.locationtech.jts.geom.Geometry; 13 | import org.locationtech.jts.io.ParseException; 14 | 15 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 16 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 17 | 18 | 19 | public class FunctionEquals extends GeometryFunction implements Function { 20 | 21 | @Override 22 | public List execute( 23 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 24 | List valueList = new ArrayList<>(); 25 | 26 | Geometry geometry1 = computeGeometry(arguments.get(0), qlterms.get(0)); 27 | Geometry geometry2 = computeGeometry(arguments.get(1), qlterms.get(1)); 28 | valueList.add(GTransormationFunctions.equals(geometry1, geometry2)); 29 | return valueList; 30 | } 31 | 32 | 33 | @Override 34 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 35 | return null; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionFactory.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.openrdf.model.URI; 6 | 7 | public class FunctionFactory { 8 | public static HashMap availableFunctions=new HashMap<>(); 9 | public static void registerFunction(URI functionURI,Function function) throws FunctionAlreadyExists { 10 | if(availableFunctions.containsKey(functionURI)){ 11 | throw new FunctionAlreadyExists("Function "+functionURI + " has been already registered."); 12 | } 13 | availableFunctions.put(functionURI, function); 14 | } 15 | public static void registerFunction(URI functionURI,Class function) throws FunctionAlreadyExists, InstantiationException, IllegalAccessException { 16 | if(availableFunctions.containsKey(functionURI)){ 17 | throw new FunctionAlreadyExists("Function "+functionURI + " has been already registered."); 18 | } 19 | availableFunctions.put(functionURI, function.newInstance()); 20 | } 21 | public static Function get(URI function) throws FunctionNotDefined { 22 | if(!availableFunctions.containsKey(function)) 23 | { 24 | throw new FunctionNotDefined(function); 25 | } 26 | return availableFunctions.get(function); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionGreaterThan.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 13 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 14 | 15 | 16 | public class FunctionGreaterThan extends AbstractFunction implements Function { 17 | 18 | @Override 19 | public List execute( 20 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException { 21 | List valueList = new ArrayList<>(); 22 | // System.out.println(arguments.get(0)); 23 | // System.out.println(arguments.get(1)); 24 | // System.out.println("result "); 25 | valueList.add(GTransormationFunctions.greaterThan( 26 | Double.valueOf(arguments.get(0).toString()),Double.valueOf(arguments.get(1).toString()))); 27 | // System.out.println("GreaterThan("+ arguments.get(0) +","+arguments.get(1)+") ="+valueList.get(0)); 28 | return valueList; 29 | } 30 | 31 | 32 | @Override 33 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException { 34 | return null; 35 | } 36 | 37 | 38 | } 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionIntersects.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import org.locationtech.jts.geom.Geometry; 13 | import org.locationtech.jts.io.ParseException; 14 | 15 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 16 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 17 | 18 | 19 | public class FunctionIntersects extends GeometryFunction implements Function { 20 | 21 | @Override 22 | public List execute( 23 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 24 | List valueList = new ArrayList<>(); 25 | 26 | Geometry geometry1 = computeGeometry(arguments.get(0), qlterms.get(0)); 27 | Geometry geometry2 = computeGeometry(arguments.get(1), qlterms.get(1)); 28 | valueList.add(GTransormationFunctions.intersects( 29 | geometry1,geometry2)); 30 | return valueList; 31 | } 32 | 33 | 34 | @Override 35 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 36 | return null; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionLength.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import org.locationtech.jts.geom.Geometry; 13 | import org.locationtech.jts.io.ParseException; 14 | 15 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 16 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 17 | 18 | 19 | public class FunctionLength extends GeometryFunction implements Function { 20 | 21 | @Override 22 | public List execute( 23 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 24 | List valueList = new ArrayList<>(); 25 | 26 | Geometry geometry = computeGeometry(arguments.get(0), qlterms.get(0)); 27 | valueList.add(GTransormationFunctions.length( 28 | (Geometry) geometry)); 29 | return valueList; 30 | } 31 | 32 | 33 | @Override 34 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 35 | 36 | Geometry geometry = computeGeometry(argument, qlterm); 37 | return GTransormationFunctions.length((Geometry) geometry); 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionNotDefined.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import org.openrdf.model.URI; 4 | 5 | public class FunctionNotDefined extends Exception { 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = -3034963235618628380L; 10 | 11 | public FunctionNotDefined(URI function) { 12 | super("Function " + function + "is not registered to GeoTriples. Use FactionFactory.registerFunction to register custom functions"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionOverlaps.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.opengis.referencing.FactoryException; 10 | import org.xml.sax.SAXException; 11 | 12 | import org.locationtech.jts.geom.Geometry; 13 | import org.locationtech.jts.io.ParseException; 14 | 15 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 16 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 17 | 18 | 19 | public class FunctionOverlaps extends GeometryFunction implements Function { 20 | 21 | @Override 22 | public List execute( 23 | List arguments,List qlterms) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 24 | List valueList = new ArrayList<>(); 25 | 26 | Geometry geometry1 = computeGeometry(arguments.get(0), qlterms.get(0)); 27 | Geometry geometry2 = computeGeometry(arguments.get(1), qlterms.get(1)); 28 | valueList.add(GTransormationFunctions.overlaps(geometry1, geometry2)); 29 | return valueList; 30 | } 31 | 32 | 33 | @Override 34 | public Object execute(Object argument, QLTerm qlterm) throws SAXException, IOException, ParserConfigurationException, FactoryException, MalformedGeometryException, ParseException { 35 | 36 | return null; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/FunctionSubtract.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.xml.parsers.ParserConfigurationException; 8 | 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.opengis.referencing.FactoryException; 12 | import org.xml.sax.SAXException; 13 | 14 | import be.ugent.mmlab.rml.core.MalformedGeometryException; 15 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 16 | 17 | public class FunctionSubtract extends AbstractFunction implements Function { 18 | private final static Logger log = LoggerFactory.getLogger(FunctionSubtract.class); 19 | 20 | @Override 21 | public List execute(List arguments, List qlterms) 22 | throws SAXException, IOException, ParserConfigurationException, FactoryException, 23 | MalformedGeometryException { 24 | List valueList = new ArrayList<>(); 25 | log.debug("Executing FunctionSubtract..."); 26 | 27 | if (log.isTraceEnabled()) { 28 | log.trace("FunctionSubtract: value0: " + arguments.get(0)); 29 | log.trace("FunctionSubtract: value1: " + arguments.get(1)); 30 | } 31 | String result = String 32 | .valueOf(Double.valueOf(arguments.get(0).toString()) - Double.valueOf(arguments.get(1).toString())); 33 | valueList.add(result); 34 | log.trace("FunctionSubtract: Result: " + result); 35 | 36 | return valueList; 37 | } 38 | 39 | 40 | @Override 41 | public Object execute(Object argument, QLTerm qlterm) 42 | throws SAXException, IOException, ParserConfigurationException, FactoryException,MalformedGeometryException { 43 | 44 | return null; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/function/GeometryFunction.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.function; 2 | 3 | import be.ugent.mmlab.rml.model.TermMap.TermMapType; 4 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 5 | 6 | public class GeometryFunction extends AbstractFunction { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/mapgen/RMLMappingGenerator.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.mapgen; 2 | 3 | import java.io.File; 4 | 5 | public abstract class RMLMappingGenerator { 6 | protected String baseURI = "http://linkedeodata.eu/"; 7 | protected File outputfile; 8 | public RMLMappingGenerator(String baseiri,String outputfile) { 9 | if (baseiri != null) { 10 | this.baseURI = baseiri; 11 | if (!this.baseURI.endsWith("/")) { 12 | this.baseURI += "/"; 13 | } 14 | } 15 | this.outputfile = outputfile==null?null:new File(outputfile); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/model/GraphMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Antidot opensource@antidot.net 3 | * https://github.com/antidot/db2triples 4 | * 5 | * DB2Triples is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation; either version 2 of 8 | * the License, or (at your option) any later version. 9 | * 10 | * DB2Triples is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | /*************************************************************************** 19 | * 20 | * R2RML Model : GraphtMap Interface 21 | * 22 | * Any subject map or predicate-object map may have one 23 | * or more associated graph maps. Graph maps are 24 | * themselves term maps. When RDF triples are generated, 25 | * the set of target graphs is determined by taking into 26 | * account any graph maps associated with the subject map 27 | * or predicate-object map. 28 | * 29 | ****************************************************************************/ 30 | package be.ugent.mmlab.rml.model; 31 | 32 | import java.io.Serializable; 33 | 34 | public interface GraphMap extends TermMap,Serializable { 35 | 36 | /** 37 | * A graph map is associated with a graph URI. 38 | */ 39 | //public URI getGraph(); 40 | } 41 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/model/InvalidRMLStructureException.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.model; 2 | 3 | /** 4 | * 5 | * @author mielvandersande 6 | */ 7 | class InvalidRMLStructureException extends Exception { 8 | 9 | public InvalidRMLStructureException(String message) { 10 | super(message); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/model/LogicalSource.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.model; 2 | 3 | import java.io.Serializable; 4 | 5 | import be.ugent.mmlab.rml.vocabulary.Vocab; 6 | 7 | /** 8 | * 9 | * @author mielvandersande 10 | */ 11 | public interface LogicalSource extends Serializable { 12 | 13 | /** 14 | * Every logical source has an expression resulting in a list of iterating 15 | * values. 16 | */ 17 | public String getReference(); 18 | 19 | /** 20 | * Every logical source has an identifier, which is a schema-qualified name 21 | * pointing at a source. 22 | */ 23 | public String getIdentifier(); 24 | 25 | /** 26 | * Every logical source can indicate how its expression should be 27 | * interpreted 28 | */ 29 | public Vocab.QLTerm getReferenceFormulation(); 30 | } 31 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/model/ObjectMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Antidot opensource@antidot.net 3 | * https://github.com/antidot/db2triples 4 | * 5 | * DB2Triples is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation; either version 2 of 8 | * the License, or (at your option) any later version. 9 | * 10 | * DB2Triples is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | /*************************************************************************** 19 | * 20 | * R2RML Model : Standard ObjectMap Interface 21 | * 22 | * An object map is a specific term map used for 23 | * representing RDF object. 24 | * 25 | ****************************************************************************/ 26 | package be.ugent.mmlab.rml.model; 27 | 28 | import java.io.Serializable; 29 | 30 | public interface ObjectMap extends TermMap,Serializable { 31 | 32 | /** 33 | * A object map knows in own Predicate Object container. 34 | */ 35 | public PredicateObjectMap getPredicateObjectMap(); 36 | public void setPredicateObjectMap(PredicateObjectMap predicateObjectMap); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/model/PredicateMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Antidot opensource@antidot.net 3 | * https://github.com/antidot/db2triples 4 | * 5 | * DB2Triples is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation; either version 2 of 8 | * the License, or (at your option) any later version. 9 | * 10 | * DB2Triples is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | /*************************************************************************** 19 | * 20 | * R2RML Model : Standard PredicateMap Interface 21 | * 22 | * A predicate map is a specific term map used for 23 | * representing RDF predicate. 24 | * 25 | ****************************************************************************/ 26 | package be.ugent.mmlab.rml.model; 27 | 28 | import java.io.Serializable; 29 | 30 | public interface PredicateMap extends TermMap,Serializable { 31 | 32 | /** 33 | * A Predicate Map knows in own Predicate Object container. 34 | */ 35 | public PredicateObjectMap getPredicateObjectMap(); 36 | public void setPredicateObjectMap(PredicateObjectMap predicateObjectMap); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/model/RMLMapping.java: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * 3 | * RMLModel : RML Mapping class 4 | * 5 | * Represents a set of TriplesMap objects which can compare 6 | * with a mapping of a all tables of a database and files in different sources. 7 | * 8 | * based on R2RMLMapping class in https://github.com/antidot/db2triples 9 | * 10 | ****************************************************************************/ 11 | package be.ugent.mmlab.rml.model; 12 | 13 | import java.util.Collection; 14 | import java.util.HashSet; 15 | 16 | 17 | public class RMLMapping { 18 | 19 | private Collection triplesMaps; 20 | 21 | public RMLMapping(Collection triplesMaps) { 22 | super(); 23 | this.triplesMaps = new HashSet(); 24 | this.triplesMaps.addAll(triplesMaps); 25 | } 26 | 27 | /** 28 | * @return 29 | */ 30 | public Collection getTriplesMaps() { 31 | return triplesMaps; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/model/StdLogicalSource.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.model; 2 | 3 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 4 | 5 | /** 6 | * Concrete implementation of a Logical Source 7 | * 8 | * @author mielvandersande, andimou 9 | */ 10 | public class StdLogicalSource implements LogicalSource { 11 | 12 | private String reference; 13 | private QLTerm referenceFormulation = QLTerm.SQL_CLASS; 14 | private String identifier; 15 | 16 | public StdLogicalSource(String reference, String identifier) { 17 | this.reference = reference; 18 | this.identifier = identifier; 19 | } 20 | 21 | public StdLogicalSource(String reference) { 22 | this.reference = reference; 23 | } 24 | 25 | public StdLogicalSource(String reference, String identifier, QLTerm queryLanguage) { 26 | this.reference = reference; 27 | this.identifier = identifier; 28 | this.referenceFormulation = queryLanguage; 29 | } 30 | 31 | @Override 32 | public String getReference() { 33 | return reference; 34 | } 35 | 36 | @Override 37 | public QLTerm getReferenceFormulation() { 38 | return referenceFormulation; 39 | } 40 | 41 | @Override 42 | public String getIdentifier() { 43 | return identifier; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "[StdLogicalSource : reference = " + reference 49 | + "; identifier" + identifier + "; referenceFormulation = " + referenceFormulation + "]"; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/model/reference/ReferenceIdentifier.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.model.reference; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 7 | * This interface offers a method for replacing a template with the expression it holds 8 | * 9 | * @author mielvandersande 10 | */ 11 | public interface ReferenceIdentifier extends Serializable{ 12 | 13 | /** Made a replaceAll on the input String to replace all occurrence of 14 | * the "{parameter}" in. 15 | * @param input The input String 16 | * @return 17 | */ 18 | public String replaceAll(String input, String replaceValue); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/model/reference/ReferenceIdentifierImpl.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.model.reference; 2 | 3 | /** 4 | * 5 | * This class holds an expression that refers to a certain value. 6 | * It has lost most of its use, maybe replace it? 7 | * 8 | * @author mielvandersande 9 | */ 10 | public class ReferenceIdentifierImpl implements ReferenceIdentifier { 11 | 12 | private String reference = null; 13 | 14 | private ReferenceIdentifierImpl(String reference) { 15 | this.reference = reference; 16 | } 17 | 18 | /** 19 | * Build a Reference Identifier from a RML config file. 20 | * 21 | * @param referenceName The reference. 22 | * @return 23 | */ 24 | public static ReferenceIdentifierImpl buildFromR2RMLConfigFile(String reference) { 25 | if (reference == null) { 26 | return null; 27 | } 28 | 29 | // Be optimist... 30 | return new ReferenceIdentifierImpl(reference); 31 | } 32 | 33 | public String replaceAll(String input, String replaceValue) { 34 | // Try simple replace... 35 | String localResult = input.replaceAll("\\{" + reference + "\\}", 36 | replaceValue); 37 | // Must have replaced something 38 | assert !localResult.equals(input) : ("Impossible to replace " 39 | + reference + " in " + input); 40 | return localResult; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return reference; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/processor/RMLProcessorFactory.java: -------------------------------------------------------------------------------- 1 | 2 | package be.ugent.mmlab.rml.processor; 3 | 4 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 5 | 6 | /** 7 | * Interface for creating processors 8 | * @author mielvandersande 9 | */ 10 | public interface RMLProcessorFactory { 11 | 12 | public RMLProcessor create(QLTerm term); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/processor/concrete/ConcreteRMLProcessorFactory.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.processor.concrete; 2 | 3 | import be.ugent.mmlab.rml.function.Config; 4 | import be.ugent.mmlab.rml.processor.RMLProcessor; 5 | import be.ugent.mmlab.rml.processor.RMLProcessorFactory; 6 | import be.ugent.mmlab.rml.vocabulary.Vocab.QLTerm; 7 | 8 | /** 9 | * This factory class creates language-dependent processors processors 10 | * 11 | * @author mielvandersande 12 | */ 13 | public class ConcreteRMLProcessorFactory implements RMLProcessorFactory { 14 | 15 | /** 16 | * Create the language-dependent processor based on the given language 17 | * 18 | * @param term 19 | * Expression language 20 | * @return processor able to process the specified language 21 | */ 22 | @Override 23 | public RMLProcessor create(QLTerm term) { 24 | switch (term) { 25 | case XPATH_CLASS: 26 | return new XPathProcessor(); 27 | case CSV_CLASS: 28 | return new CSVProcessor(); 29 | case TSV_CLASS: 30 | return new TSVProcessor(); 31 | case JSONPATH_CLASS: 32 | return new JSONPathProcessor(); 33 | case SHP_CLASS: 34 | if (Config.useDGALLibrary) 35 | return new ShapefileProcessorGDAL(); 36 | else 37 | return new ShapefileProcessor(); 38 | case ROW_CLASS: 39 | return new RowProcessor(); 40 | // case SQL_CLASS: 41 | // if (Config.useOldDBProcessor)//this old processor asks only one query, the new one ask multiple queries and projects one column at a time 42 | // return new DatabaseProcessor(); 43 | // else 44 | // return new DatabaseProcessorWithManyQueries(); 45 | } 46 | return null; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/processor/concrete/TSVProcessor.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.processor.concrete; 2 | 3 | /** 4 | * 5 | * @author dimis 6 | */ 7 | public class TSVProcessor extends CSVProcessor { 8 | @Override 9 | protected char getDelimiter() { 10 | return '\t'; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/tools/CacheFifo.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.tools; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | public class CacheFifo extends LinkedHashMap { 7 | /** 8 | * 9 | */ 10 | private static final long serialVersionUID = 1L; 11 | private int cacheSize; 12 | public CacheFifo(int cacheSize) { 13 | super(16, 0.75f, true); 14 | this.cacheSize = cacheSize; 15 | } 16 | 17 | @Override 18 | public V put(K key, V value) { 19 | V result = super.put(key, value); 20 | return result; 21 | } 22 | 23 | 24 | @Override 25 | public V get(Object key) { 26 | V result = super.get(key); 27 | return result; 28 | } 29 | 30 | @Override 31 | public boolean containsKey(Object key) { 32 | boolean result=super.containsKey(key); 33 | return result; 34 | } 35 | 36 | @Override 37 | protected boolean removeEldestEntry(Map.Entry eldest) { 38 | return size() >= cacheSize; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/tools/CriticalSection.java: -------------------------------------------------------------------------------- 1 | package be.ugent.mmlab.rml.tools; 2 | 3 | public class CriticalSection { 4 | int readers; 5 | 6 | public CriticalSection() { 7 | readers = 0; 8 | } 9 | 10 | public synchronized void enter_read() throws InterruptedException { 11 | while (readers == -1) 12 | wait(); 13 | readers++; 14 | } 15 | 16 | public synchronized void exit_read() { 17 | readers--; 18 | if (readers == 0) 19 | notify(); 20 | } 21 | 22 | public synchronized void enter_write() throws InterruptedException { 23 | while (readers != 0) 24 | wait(); 25 | readers = -1; 26 | } 27 | 28 | public synchronized void exit_write() { 29 | readers = 0; 30 | notifyAll(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/tools/CustomRDFDataValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package be.ugent.mmlab.rml.tools; 6 | 7 | import net.antidot.semantic.rdf.model.tools.RDFDataValidator; 8 | 9 | /** 10 | * 11 | * This class customizes the implementation by db2triples 12 | * 13 | * @author mielvandersande 14 | */ 15 | public class CustomRDFDataValidator extends RDFDataValidator{ 16 | /** 17 | * The set of validatable RDF datatypes includes all datatypes 18 | * in the RDF datatype column of the table of natural datatype 19 | * mappings, as defined in [XMLSCHEMA2]. 20 | * @param string 21 | * @return 22 | */ 23 | public static boolean isValidDatatype(String datatype) { 24 | boolean isValid = true; 25 | if (!isValidURI(datatype)) return false; 26 | 27 | //MVS: Removed constraint since it prevents using types other than XSD 28 | /* try { 29 | XSDType.toXSDType(datatype); 30 | } catch (IllegalArgumentException e) { 31 | isValid = false; 32 | }*/ 33 | return isValid; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /geotriples-processors/geotriples-rml/src/main/java/be/ugent/mmlab/rml/vocabulary/VocabTrans.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * ************************************************************************* 4 | * 5 | * RML, R2RML & QL Vocabulary 6 | * 7 | * The R2RML vocabulary is the set of IRIs defined in this specification that 8 | * start with the rr: namespace IRI: http://www.w3.org/ns/r2rml# 9 | * 10 | *************************************************************************** 11 | */ 12 | package be.ugent.mmlab.rml.vocabulary; 13 | /*************************************************************************** 14 | * 15 | * @author: dimis (dimis@di.uoa.gr) 16 | * 17 | ****************************************************************************/ 18 | public class VocabTrans extends Vocab{ 19 | 20 | public static String RRX_NAMESPACE = "http://www.w3.org/ns/r2rml-ext#"; 21 | public static String RRXF_NAMESPACE ="http://www.w3.org/ns/r2rml-ext/functions/def/"; 22 | 23 | public enum RRXTerm { 24 | // CLASSES 25 | 26 | 27 | 28 | 29 | TRANSFORMATION("transformation"), 30 | FUNCTION("function"), 31 | ARGUMENTMAP("argumentMap"), 32 | TRIPLES_MAP("triplesMap"); 33 | ; 34 | 35 | private String displayName; 36 | 37 | private RRXTerm(String displayName) { 38 | this.displayName = displayName; 39 | } 40 | 41 | public String toString() { 42 | return displayName; 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /geotriples-spark/src/main/java/eu/linkedeodata/geotriples/utils/Coordinates2WKT.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.utils; 2 | 3 | 4 | import scala.collection.mutable.WrappedArray; 5 | 6 | import java.io.Serializable; 7 | import java.util.function.BiFunction; 8 | import java.util.function.Function; 9 | 10 | /** 11 | * Functions that convert GeoJSON Geometries into WKT. 12 | */ 13 | public class Coordinates2WKT implements Serializable { 14 | 15 | static final Function coords2String = ar_coords -> { 16 | StringBuilder sb_wkt_coords = new StringBuilder(); 17 | boolean was_array = false; 18 | scala.collection.Iterator coords_iter = ar_coords.toIterable().toIterator(); 19 | while(coords_iter.hasNext()) { 20 | Object o = coords_iter.next(); 21 | if( o instanceof Double) 22 | sb_wkt_coords.append(o).append(" "); 23 | else{ 24 | was_array = true; 25 | if(coords_iter.hasNext()) 26 | sb_wkt_coords.append(Coordinates2WKT.coords2String.apply((WrappedArray) o)).append(","); 27 | else 28 | sb_wkt_coords.append(Coordinates2WKT.coords2String.apply((WrappedArray) o)); 29 | } 30 | } 31 | if(was_array) sb_wkt_coords.insert(0, "(").append(")"); 32 | return sb_wkt_coords; 33 | }; 34 | 35 | 36 | static final BiFunction convert = (type, coords) -> { 37 | StringBuilder sb_wkt_coords = coords2String.apply(coords); 38 | if(type.equals("Point")){ 39 | sb_wkt_coords.insert(0, type.toUpperCase() + " (" ).append(")"); 40 | return sb_wkt_coords.toString(); 41 | } 42 | else{ 43 | sb_wkt_coords.insert(0, type.toUpperCase() ); 44 | return sb_wkt_coords.toString(); 45 | } 46 | }; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /geotriples-spark/src/main/java/eu/linkedeodata/geotriples/utils/NTriplesUtilNoEscape.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.utils; 2 | 3 | import java.io.IOException; 4 | import org.openrdf.model.Literal; 5 | import org.openrdf.model.Resource; 6 | import org.openrdf.model.Value; 7 | import org.openrdf.rio.ntriples.NTriplesUtil; 8 | 9 | 10 | 11 | public class NTriplesUtilNoEscape { 12 | public static void append(Value value, Appendable appendable) 13 | throws IOException 14 | { 15 | 16 | // WARNING if you want to produce blank nodes replace all the .append("<").append(X).append(">"); 17 | // with NTriplesUtil.append(st.getSubject(), sb); 18 | if (value instanceof Resource) { 19 | appendable.append("<").append(value.stringValue()).append(">"); 20 | } 21 | else if (value instanceof Literal) { 22 | append((Literal)value, appendable); 23 | } 24 | else { 25 | throw new IllegalArgumentException("Unknown value type: " + value.getClass()); 26 | } 27 | } 28 | 29 | 30 | public static void append(Literal lit, Appendable appendable) 31 | throws IOException 32 | { 33 | // Do some character escaping on the label: 34 | appendable.append("\""); 35 | appendable.append(lit.getLabel()); 36 | appendable.append("\""); 37 | 38 | if (lit.getDatatype() != null) { 39 | // Append the literal's datatype 40 | appendable.append("^^"); 41 | appendable.append("<").append(lit.getDatatype().stringValue()).append(">"); 42 | } 43 | else if (lit.getLanguage() != null) { 44 | // Append the literal's language 45 | appendable.append("@"); 46 | appendable.append(lit.getLanguage()); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /geotriples-spark/src/main/java/eu/linkedeodata/geotriples/utils/NullDataSet.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.utils; 2 | 3 | import net.antidot.semantic.rdf.model.impl.sesame.SesameDataSet; 4 | import org.openrdf.model.Resource; 5 | import org.openrdf.model.Statement; 6 | import org.openrdf.model.URI; 7 | import org.openrdf.model.Value; 8 | 9 | 10 | public class NullDataSet extends SesameDataSet { 11 | 12 | public NullDataSet() { 13 | } 14 | 15 | @Override 16 | public void add(Resource s, URI p, Value o, Resource... contexts) { 17 | return; 18 | } 19 | 20 | @Override 21 | public void addStatement(Statement s) { 22 | return; 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /geotriples-spark/src/main/java/eu/linkedeodata/geotriples/utils/SerializedLogger.java: -------------------------------------------------------------------------------- 1 | package eu.linkedeodata.geotriples.utils; 2 | 3 | import org.apache.log4j.Level; 4 | import org.apache.log4j.Logger; 5 | 6 | import java.io.Serializable; 7 | 8 | public class SerializedLogger implements Serializable { 9 | public Logger log; 10 | 11 | public SerializedLogger(String name, Level level){ 12 | log = Logger.getLogger(name); 13 | log.setLevel(level); 14 | } 15 | 16 | public void info(String msg){ 17 | log.info(msg); 18 | } 19 | 20 | public void warn(String msg){ 21 | log.warn(msg); 22 | } 23 | 24 | public void error(String msg){ 25 | log.error(msg); 26 | } 27 | } 28 | --------------------------------------------------------------------------------