diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d40f213350..80c98045f1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,21 +2,39 @@ name: build on: push: - branches-ignore: - - master-forge + branches: - master - - parent-pom - - gh-pages + - develop + pull_request: + types: [ opened, synchronize, reopened ] jobs: - build_and_test: + build: + name: Build runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Cache SonarQube packages + uses: actions/cache@v1 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Maven packages + uses: actions/cache@v1 with: - java-version: '11' - distribution: 'temurin' - - name: Build and validate project - run: mvn -B package --file pom.xml \ No newline at end of file + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=gephi_semanticwebimport \ No newline at end of file diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000000..ec46322c36 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,78 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "master" ] + schedule: + - cron: '27 6 * * 1' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'java', 'python' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Use only 'java' to analyze code written in Java, Kotlin or both + # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + + # Does not work. + #- name: Autobuild + # uses: github/codeql-action/autobuild@v2 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + - run: | + echo "Run, Build Application using script" + mvn clean package + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/.gitignore b/.gitignore index 6eb5d997c2..983922c087 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .DS_Store **/target/** +/target/ +/nb-configuration.xml # Created by https://www.gitignore.io/api/maven,eclipse,netbeans,intellij # Edit at https://www.gitignore.io/?templates=maven,eclipse,netbeans,intellij @@ -178,4 +180,6 @@ nbdist/ # End of https://www.gitignore.io/api/maven,eclipse,netbeans,intellij -.java-version \ No newline at end of file +.java-version +>>>>>>> gephi-plugins/master +/log.txt diff --git a/README-plugin.md b/README-plugin.md new file mode 100644 index 0000000000..61734cf8de --- /dev/null +++ b/README-plugin.md @@ -0,0 +1,214 @@ +# Licensing + +This plugin is developped inside [Inria](http://www.inria.fr), by the [Wimmics](http://wimmics.inria.fr) research team, with the support of the [Dream](http://www-sop.inria.fr/dream) team. + +This plugin is made available through the [CeCILL-B licence](http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html). + +# Installation + +**Follow the procedure described at https://github.com/Wimmics/update-semanticwebimport** + +# Versions + +- SemanticWebImport: 1.4.0 +- Embedded Corese: 4.4.0 + +# Main Repositories + +- Source code: https://github.com/Wimmics/gephi-semantic-web-import. +- The update center repository: https://github.com/Wimmics/update-semanticwebimport + +# Installation + +The installation is done through a custom "update center". See [installation](https://github.com/Wimmics/update-semanticwebimport). + +# Disclaimer + +All the description below requires a complete update and is provided only as is, since some informations could still be +useful. + +# Videos + +The main page for the following videos can found at [SemanticWebImport Plugin Videos](http://wimmics.inria.fr/node/35). + +* [Installation of the plugin](http://www-sop.inria.fr/teams/edelweiss/media/installation.swf) +* [Overview of the parts of the plugin](http://www-sop.inria.fr/teams/edelweiss/media/parts_overview.swf) +* [Access to local RDF data](http://www-sop.inria.fr/teams/edelweiss/media/first_example_local.swf) + +# Description + +The SemanticWebImport plugin is intended to allow the import of semantic data into Gephi. The imported data are obtained by processing a SPARQL request on the semantic data. The data can be accessed following three manners: + +1. by accessing local rdf, rdfs, rul files and using the embedded Corese engine to apply the SPARQL request; +2. by accessing a remote REST SPARQL endpoint. In that case, the SPARQL request is applied remotely and the graph is built locally by analyzing the result sent by the REST endpoint; +3. by accessing a remote SOAP SPARQL endpoint. As for the REST endpoint, the resulting graph is built from the result returned by the endpoint. + +We begin by showing how to make run the preset examples which come with the plugin. Then we detail the three drivers allowing to import semantic data. + +**In all the following cases, it is required there is a currently opened project, otherwise the graph can not be built.** + +# General Description of the GUI + +The plugin consist of fourth tabs: + +## How to access the data + +![First tab of the plugin](https://cloud.githubusercontent.com/assets/197285/13900370/d67a6006-ee04-11e5-8ed2-0bc788e252a2.png) + +First tab of the plugin + +This tab allows to select among the available SPARQL drivers how the semantic data can be accessed. Currently, the choice can be made between (i) access to local data through the Corese engine; (ii) access to a remote REST SPARQL endpoint; (iii) access to a remote SOAP SPARQL enpoint. + +## Write the SPARQL query + +![Second tab of the plugin](https://cloud.githubusercontent.com/assets/197285/13900373/d84b21c2-ee04-11e5-99c5-6ffa80919f34.png) + +Second tab of the plugin + +The SPARQL editor to enter a SPARQL request that extract the data used to build the graph. **It is mandatory to be a construct request.** + +## Execution log + +![Third tab of the plugin](https://cloud.githubusercontent.com/assets/197285/13900374/d8aa9526-ee04-11e5-967e-5dabc30c66e7.png) + +Third tab of the plugin + +This tab contains the log, i.e. the outputs of the plugin. + +## Configurations management + +![Fourth tab of the plugin](https://cloud.githubusercontent.com/assets/197285/13900375/d97158c8-ee04-11e5-856b-8c3a71c96fbb.png) + +Fourth tab of the plugin + +This tab allows to manage the configurations. I.e. it contains: (i) the selector for preset examples and the load button to activate them. + +## Launch the query + +Note that to launch the query, the Run button is set at the bottom of the window. + +# Use + +To use the plugin, follow these steps: + +1. choose in tab 1 a driver between the three available; +2. parameterize the driver (tab 1, and see the following sections for more details); +3. enter the SPARQL request, making sure it is a construct SPARQL request. All the relations "?x ?r ?y" in the construct part are creating nodes ?x and ?y and an edge to connect both; +4. In tab 4, choose: + 1. Wether the workspace has to be reset; + 2. If blank nodes muste be ignored; + 3. Which level of follow your nose recursion you want. + 4. The Python pre and post processing scripts can be used, using the python scripting plugin (see https://github.com/gephi/gephi/wiki/Scripting-Plugin for more details). The /fr/inria/edelweiss/examples/autolayout.py comes as a example of script. +5. The processing of the query can be launched by clicking on the Run button (at bottom). + +# BBC Preset Examples + +To obtain the BBC example, foolow the following steps: + +1. Create a new empty project; +2. Select in the Load Examples/Configurations (i.e. the part 4 in previous image) the "BBC" example; +3. Click on load. The GUI should be similar to ![View of the SemanticWebPlugin after loading the BBC example](https://cloud.githubusercontent.com/assets/197285/13900376/da5a36d8-ee04-11e5-8ba1-3f2a9142a562.png) (View of the SemanticWebPlugin after loading the BBC example) +4. Launch the SPARQL driver by clicking on the start button (part 5). The BBC example connects to a SOAP SPARQL endpoint, and the SPARQL request is processed remotely, then the result is returned to the plugin. The graph obtained should be similar to ![View of the SemanticWebPlugin after processing the BBC example](https://cloud.githubusercontent.com/assets/197285/13900377/daf7547c-ee04-11e5-9930-2e5798509721.png) (View of the SemanticWebPlugin after processing the BBC example) + +# Using Local Files + +The Corese driver allows to process locally a SPARQL request on RDF files. The RDF files can be provided as: + +1. local files. +2. internet files, i.e. beginning with http://. For example, http://dbpedia.org/data/The_Beatles.rdf can be added and used as an input. +3. resource files (i.e. RDF files coming from a jar file run by gephi). The file must begin with /. Three such files are coming embedded inside the plugin, /fr/inria/edelweis/examples/human_2007_09_11.rdf, /fr/inria/edelweis/examples/human_2007_09_11.rdfs, /fr/inria/edelweis/examples/human_2007_09_11.rul. + +![CoreseDriver Panel](https://cloud.githubusercontent.com/assets/197285/13900378/dba7609c-ee04-11e5-8aaa-9cf8196b2210.png) + +CoreseDriver Panel + +The CoreseDriver is made of three parts: + +1. buttons allowing to add a local file (+) or remove a resource (-); +2. the list of resources; +3. a text field and a button to add external resources, i.e. rdf files on the internet. + +# Access with REST + +The REST SPARQL driver allows to make process a SPARQL request on a remote SPARQL endpoint with REST interface. + +![Rest Driver Panel](https://cloud.githubusercontent.com/assets/197285/13900379/dc4c2596-ee04-11e5-8bee-cfeb7f856c23.png) + +Rest Driver Panel + +The Rest panel is made of the following parts: + +1. the URL for the endpoint; +2. the name given to the query tag. Most often it is "query"; some endpoints use "q". +3. some parameters to be added the request. For example "debug=on" can be provided by: + 1. Writing "debug" instead of "REST name" in the part 3. + 2. Writing "on" instead of "REST value" in the part 3. + 3. Clicking on +. + +## Access with SOAP + +The SOAP SPARQL driver has a single parameter, the URL of the endpoint. + +![Soap Driver Panel](https://cloud.githubusercontent.com/assets/197285/13900380/dd0a4fe4-ee04-11e5-92a8-2c84e3565695.png) + +Soap Driver Panel + +# Gephi: extensions in the SPARQL query + +When building a query, some special keywords can be used to customize the results in gephi. http://gephi.org/ is used as the namespace for this extension. It is counselled to add the line "namespace gephi: " at the beginning of the query. + +* ?node **gephi:label** ?node_label fill the label of the node with the content of ?node_label; +* ?node **gephi:size** ?value sets the size of the node to the content of ?value; +* ?node **gephi:color** ?color_name sets the color of the node according to the content of ? color_name. The known names are those defined in http://docs.oracle.com/javase/6/docs/api/java/awt/Color.html. +* ?node **gephi:color_r** ?value sets the red part of the color of the node with ?value. ?value must be set between 0 and 255, inclusives, +* ?node **gephi:color_g** ?value sets the green part of the color of the node with ?value. ?value must be set between 0 and 255, inclusives, +* ?node **gephi:color_b** ?value sets the blue part of the color of the node with ?value. ?value must be set between 0 and 255, inclusives, +* ?node **gephi:AttributeName** ?anyValue creates a new attribute called "AttributeName" for all the nodes of the graph, and set the attribute for the current node with the content of ?anyValue. + +# Pre and post processing using python + +As previously stated, the import of data can be pre or post processed with a script plugin. + +```python +import org.openide.util.Lookup as Lookup +import org.gephi.ranking.api.RankingController +import org.gephi.ranking.api.Ranking as Ranking +import org.gephi.ranking.api.Transformer as Transformer +import java.awt.Color as Color + + +rankingController = Lookup.getDefault().lookup(org.gephi.ranking.api.RankingController) + +# Set the color in function of the degree. +degreeRanking = rankingController.getModel().getRanking(Ranking.NODE_ELEMENT, Ranking.DEGREE_RANKING); +colorTransformer = rankingController.getModel().getTransformer(Ranking.NODE_ELEMENT, Transformer.RENDERABLE_COLOR) +colorTransformer.setColors([Color.BLUE, Color.YELLOW]) + +rankingController.transform(degreeRanking, colorTransformer) + +# Set the size in function of the degree of the nodes. +sizeTransformer = rankingController.getModel().getTransformer(Ranking.NODE_ELEMENT, Transformer.RENDERABLE_SIZE) +sizeTransformer.setMinSize(3) +sizeTransformer.setMaxSize(40) +rankingController.transform(degreeRanking, sizeTransformer) + + +### Layout of the graph +# Construction of a layout object +import org.gephi.layout.plugin.forceAtlas2.ForceAtlas2Builder as ForceAtlas2Builder +import org.gephi.layout.plugin.forceAtlas2.ForceAtlas2 as ForceAtlas2 +fa2builder = ForceAtlas2Builder() +fa2 = ForceAtlas2(fa2builder) + +# Setting the layout object +import org.gephi.graph.api.GraphController as GraphController +graphModel = Lookup.getDefault().lookup(GraphController).getModel() +fa2.setGraphModel(graphModel) +fa2.setAdjustSizes(True) # To prevent overlap + +print("executing layout") +# Run the layout. +fa2.initAlgo() +for i in range(5000): + fa2.goAlgo() +``` diff --git a/README.md b/README.md index 4b2a7a0e02..a9d71f8904 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +For documentation specific to this plugin, see [README-plugin.md](README-plugin.md). + +What follows is the general-purpose documentation of the gephi-plugins, which can be found in [https://github.com/gephi/gephi-plugins/blob/master/README.md](README.md). + # Gephi Plugins This repository is an out-of-the-box development environment for Gephi plugins. Gephi plugins are implemented in Java and can extend [Gephi](https://gephi.org) in many different ways, adding or improving features. Getting started is easy with this repository but also checkout the [Bootcamp](https://github.com/gephi/gephi-plugins-bootcamp) for examples of plugins you can create. diff --git a/modules/SemanticWebImport/CHANGELOG.md b/modules/SemanticWebImport/CHANGELOG.md new file mode 100644 index 0000000000..1581b370e9 --- /dev/null +++ b/modules/SemanticWebImport/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +## 1.3.0 - +- solves bug #1. + +## 1.2.0 - 04/04/2023 "Easter resurrection" +- update to [java 11](https://docs.oracle.com/en/java/javase/11/); +- update to [Gephi 0.10.1](https://gephi.wordpress.com/2023/01/09/gephi-0-10-released/); +- update to [corese 4.4.0](https://github.com/Wimmics/corese/releases/tag/release-4.4.0) diff --git a/modules/SemanticWebImport/Licence_CeCILL-C_V1-en.txt b/modules/SemanticWebImport/Licence_CeCILL-C_V1-en.txt new file mode 100644 index 0000000000..39f752e888 Binary files /dev/null and b/modules/SemanticWebImport/Licence_CeCILL-C_V1-en.txt differ diff --git a/modules/SemanticWebImport/README.md b/modules/SemanticWebImport/README.md new file mode 100644 index 0000000000..9f0fa0cd38 --- /dev/null +++ b/modules/SemanticWebImport/README.md @@ -0,0 +1,4 @@ +## SemanticWebImport + +This README supports Markdown, see [syntax](https://help.github.com/articles/markdown-basics/) + diff --git a/modules/SemanticWebImport/pom.xml b/modules/SemanticWebImport/pom.xml new file mode 100644 index 0000000000..a2a62341b3 --- /dev/null +++ b/modules/SemanticWebImport/pom.xml @@ -0,0 +1,132 @@ + + + 4.0.0 + + gephi-plugin-parent + org.gephi + 0.10.0 + + + fr.inria.corese + semantic + 1.5.0 + nbm + + SemanticWebImport + + + + org.netbeans.api + org-openide-awt + + + org.netbeans.api + org-openide-windows + + + org.netbeans.api + org-openide-filesystems + + + org.gephi + graph-api + + + org.gephi + io-exporter-api + + + org.gephi + io-importer-api + + + org.gephi + project-api + + + org.gephi + statistics-api + + + + + + + org.gephi + io-importer-plugin + + + org.gephi + filters-api + + + org.netbeans.api + org-netbeans-modules-settings + + + org.netbeans.api + org-openide-util-lookup + + + org.gephi + layout-api + + + org.gephi + utils-longtask + + + fr.inria.corese + corese-core + 4.5.0 + + + fr.inria.corese + corese-gui + 4.5.0 + jar + + + com.hp.hpl.jena + jena + 2.6.4 + + + commons-httpclient + commons-httpclient + 3.1 + + + org.slf4j + slf4j-log4j12 + 1.7.13 + + + org.netbeans.api + org-openide-util-ui + + + org.netbeans.api + org-openide-util + + + + + + org.apache.netbeans.utilities + nbm-maven-plugin + + Licence_CeCILL-C_V1-en + Licence_CeCILL-C_V1-en.txt + Erwan Demairy + + https://wiki.gephi.org/index.php/SemanticWebImport + + + + skip + + + + + diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/LayoutExampleAbstractPostProcessor.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/LayoutExampleAbstractPostProcessor.java new file mode 100644 index 0000000000..ac354df330 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/LayoutExampleAbstractPostProcessor.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic; + +import fr.inria.edelweiss.semantic.analyzer.AbstractPostProcessor; + +import java.util.Collection; +import java.util.Optional; +import java.util.logging.Logger; + +import org.gephi.layout.spi.Layout; +import org.gephi.layout.spi.LayoutBuilder; +import org.gephi.statistics.spi.Statistics; +import org.gephi.statistics.spi.StatisticsBuilder; +import org.openide.util.Lookup; + +/** + * + * @author edemairy + */ +public class LayoutExampleAbstractPostProcessor extends AbstractPostProcessor { + + private static final Logger logger = Logger.getLogger(LayoutExampleAbstractPostProcessor.class.getName()); + + @Override + public void run() { + applyLayoutAlgorithm("ForceAtlas 2"); + resizeNodes(); + + } + + private void applyLayoutAlgorithm(final String layoutName) { + final Lookup lookup = Lookup.getDefault(); + final Collection layoutBuilders = lookup.lookupAll(LayoutBuilder.class); + + Optional searchBuilder = Optional.empty(); + for (LayoutBuilder layoutBuilder : layoutBuilders) { + logger.info(layoutBuilder.getName()); + if (layoutBuilder.getName().equals(layoutName)) { + searchBuilder = Optional.of(layoutBuilder); + break; + } + } + + LayoutBuilder foundBuilder = searchBuilder.orElseThrow(IllegalStateException::new); + Layout layout = foundBuilder.buildLayout(); + layout.setGraphModel(getModel()); + layout.initAlgo(); + int nbIterations = 0; + while (layout.canAlgo() && (nbIterations < 10_000)) { + layout.goAlgo(); + nbIterations++; + } + layout.endAlgo(); + } + + private void resizeNodes() { + } + + private void computeStatistic(final String statisticName) { + final Lookup lookup = Lookup.getDefault(); + final Collection statisticsBuilders = lookup.lookupAll(StatisticsBuilder.class); + + Optional searchBuilder = Optional.empty(); + for (StatisticsBuilder statisticsBuilder : statisticsBuilders) { + logger.info(statisticsBuilder.getName()); + if (statisticsBuilder.getName().equals(statisticName)) { + searchBuilder = Optional.of(statisticsBuilder); + break; + } + } + StatisticsBuilder foundBuilder = searchBuilder.orElseThrow(); + Statistics statistics = foundBuilder.getStatistics(); + statistics.execute(getModel()); + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/PluginProperties.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/PluginProperties.java new file mode 100644 index 0000000000..b4fa943dc0 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/PluginProperties.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic; + +/** + * + * @author edemairy + */ +public enum PluginProperties { + RESET_WORKSPACE("semanticwebimport.reset_workspace"), + POST_PROCESSING("semanticwebimport.post_processing"), + IGNORE_BLANK_PROPERTIES("semanticwebimport.ignore_blank_properties"), + SAVE_SPARQL_RESULT("semanticwebimport.save_sparql_result"), + FYN_LEVEL("semanticwebimport.fyn_level"); + + PluginProperties(String value) { + this.value = value; + } + + public String getValue() { + return this.value; + } + + private final String value; + + public String toString() { + return this.value; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/SemanticWebImportMainWindowTopComponent.form b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/SemanticWebImportMainWindowTopComponent.form new file mode 100644 index 0000000000..2ee611e8b4 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/SemanticWebImportMainWindowTopComponent.form @@ -0,0 +1,699 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/SemanticWebImportMainWindowTopComponent.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/SemanticWebImportMainWindowTopComponent.java new file mode 100644 index 0000000000..bee922fbaa --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/SemanticWebImportMainWindowTopComponent.java @@ -0,0 +1,1082 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic; + +import org.gephi.utils.longtask.api.LongTaskListener; +import org.gephi.utils.longtask.spi.LongTask; +import org.netbeans.api.settings.ConvertAsProperties; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.util.Exceptions; +import org.openide.util.ImageUtilities; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; +import org.openide.util.lookup.ServiceProvider; +import org.openide.windows.TopComponent; +import org.openide.windows.WindowManager; + +import java.awt.Image; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import java.util.logging.SimpleFormatter; + +import javax.swing.Icon; +import javax.swing.JFileChooser; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import fr.inria.edelweiss.semantic.configurationmanager.ConfigurationManager; +import fr.inria.edelweiss.semantic.importer.SemanticWebImportParser; +import fr.inria.edelweiss.semantic.utils.FilesUtils; +import fr.inria.edelweiss.semantic.utils.StopWatch; +import fr.inria.edelweiss.sparql.DriverParametersPanel; +import fr.inria.edelweiss.sparql.SparqlDriver; +import fr.inria.edelweiss.sparql.SparqlDriverFactory; +import fr.inria.edelweiss.sparql.SparqlDriverParameters; +import fr.inria.edelweiss.sparql.SparqlRequester; +import fr.inria.edelweiss.sparql.corese.CoreseDriver; + +import static fr.inria.edelweiss.semantic.PluginProperties.*; +//import org.gephi.scripting.api.ScriptingController; +//import org.python.util.PythonInterpreter; + +/** + * Top component responsible for the main window of SemanticWebImport. + */ +@ConvertAsProperties(dtd = "-//fr.inria.edelweiss.semantic//SemanticWebImportMainWindow//EN", autostore = false) +@TopComponent.Description(preferredID = "SemanticWebImportMainWindowTopComponent", + iconBase = "fr/inria/edelweiss/resources/semantic_web_icon_16.png", + persistenceType = TopComponent.PERSISTENCE_ALWAYS) +@ActionID(category = "Window", id = "fr.inria.edelweiss.SemanticWebImportMainWindowTopComponent") +@ActionReference(path = "Menu/Window") +@TopComponent.OpenActionRegistration(displayName = "#CTL_SemanticWebImportMainWindowAction", + preferredID = "SemanticWebImportMainWindowTopComponent") +@ServiceProvider(service = SparqlRequester.class) +@TopComponent.Registration(mode = "editor", openAtStartup = true, roles = {"overview"}) +public final class SemanticWebImportMainWindowTopComponent extends TopComponent implements SparqlRequester, LongTaskListener { + + public final static String DEFAULT_CONFIGURATION = "Humans"; + private static final Logger logger = Logger.getLogger(SemanticWebImportMainWindowTopComponent.class.getName()); + private static final String PREFERRED_ID = "SemanticWebImportMainWindowTopComponent"; + private final static String ICON_PATH = "fr/inria/edelweiss/resources/semantic_web_icon_16.png"; + private static final String DEFAULT_SPARQL_REQUEST = "construct {?x ?r ?y}\nwhere {?x ?r ?y}\nlimit 100"; + static File lastLoadConfigurationDirectory = new File(getHome()); + private static SemanticWebImportMainWindowTopComponent instance; + private static SemanticWebImportParser rdfParser; + private final ConfigurationManager configurationManager = new ConfigurationManager(this); + private boolean sparqlDriverSelectorInitialized; + private final ArrayList driverHandlers = new ArrayList(); + private SparqlDriver sparqlDriver; + private StopWatch watch; + private String lastPythonUsedDirectory; + // This method is called whenever the user or program changes the selected item. + // Note: The new item may be the same as the previous item. + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox autoLayout; + private javax.swing.JPanel configurationPanel; + private javax.swing.JComboBox configurationSelector; + private javax.swing.JPanel confiugrationManagementPanel; + private javax.swing.JPanel driverSelectorPanel; + private javax.swing.JLabel fynLabel; + private javax.swing.JSpinner fynSpinner; + private javax.swing.JTabbedPane graphBuilderTab; + private javax.swing.JCheckBox ignoreBlankNode; + + /* + * + */ + private javax.swing.JPanel jPanel1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JSeparator jSeparator1; + private javax.swing.JSeparator jSeparator2; + private javax.swing.JButton loadConfiguration; + private javax.swing.JPanel logPanel; + private javax.swing.JTextArea logWindow; + private javax.swing.JPanel parametersPanel; + private javax.swing.JPanel pythonPanel; + private javax.swing.JTextField pythonPostProcessingFileName; + private javax.swing.JLabel pythonPostProcessingLabel; + private javax.swing.JTextField pythonPreProcessingFileName; + private javax.swing.JLabel pythonPreProcessingLabel; + private javax.swing.JCheckBox resetWorkspace; + private javax.swing.JButton saveConfiguration; + private javax.swing.JTextField saveConfigurationNameTextField; + private javax.swing.JButton setConfiguration; + private javax.swing.JButton setPythonPostProcessingFileName; + private javax.swing.JButton setPythonPreProcessingFileName; + private javax.swing.JLabel sparqlDriverLabel; + private javax.swing.JComboBox sparqlDriverSelector; + private javax.swing.JPanel sparqlEditorPanel; + private javax.swing.JButton sparqlQueryResultButton; + private javax.swing.JTextField sparqlQueryResultFileName; + private javax.swing.JLabel sparqlQueryResultLabel; + private fr.inria.corese.gui.query.SparqlQueryEditor sparqlRequestEditor; + private javax.swing.JLabel sparqlRequestLabel; + private javax.swing.JButton start; + public SemanticWebImportMainWindowTopComponent() throws IOException { + initComponents(); + setName( + NbBundle.getMessage( + SemanticWebImportMainWindowTopComponent.class, + "CTL_SemanticWebImportMainWindowTopComponent")); + setToolTipText( + NbBundle.getMessage( + SemanticWebImportMainWindowTopComponent.class, + "HINT_SemanticWebImportMainWindowTopComponent")); + + initConfigurations(); + Logger.getLogger("").addHandler(new LogWindowHandler()); + + configurationManager.setCurrentProperties(DEFAULT_CONFIGURATION); + + sparqlRequestEditor.setQueryText(DEFAULT_SPARQL_REQUEST); + + setIcon(ImageUtilities.icon2Image(loadIcon())); + + fillSparqlDriverSelector(); + refreshActiveSparqlDriver(); + + } + + /** + * Gets default instance. Do not use directly: reserved for *.settings + * files only, i.e. deserialization routines; otherwise you could get a + * non-deserialized instance. To obtain the singleton instance, use + * {@link #findInstance}. + */ + public static synchronized SemanticWebImportMainWindowTopComponent getDefault() throws IOException { + if (instance == null) { + instance = new SemanticWebImportMainWindowTopComponent(); + } + return instance; + } + + /** + * Obtain the SemanticWebImportMainWindowTopComponent instance. Never + * call {@link #getDefault} directly! + */ + public static synchronized SemanticWebImportMainWindowTopComponent findInstance() throws IOException { + TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); + + if (win == null) { + Logger.getLogger(SemanticWebImportMainWindowTopComponent.class.getName()).warning( + "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system."); + return getDefault(); + } + if (win instanceof SemanticWebImportMainWindowTopComponent) { + return (SemanticWebImportMainWindowTopComponent) win; + + } + Logger.getLogger(SemanticWebImportMainWindowTopComponent.class.getName()).warning( + "There seem to be multiple components with the '" + PREFERRED_ID + + "' ID. That is a potential source of errors and unexpected behavior."); + return getDefault(); + } + + public static Icon loadIcon() { + Image image = ImageUtilities.loadImage(ICON_PATH, true); + return ImageUtilities.image2Icon(image); + } + + public static SparqlRequester getSparqlRequester() { + return SemanticWebImportMainWindowTopComponent.instance; + } + + private static String getHome() { + String result = System.getProperty("user.home"); + if (result == null) { + logger.severe("user.home was not defined."); + result = "."; + } + return result; + } + + private void initConfigurations() throws IOException { + resetConfigurations(); + addConfigurations(configurationManager.loadResourceConfigurations("/fr/inria/edelweiss/semantic/default_configuration/")); + addConfigurations(loadFileConfigurations(getHome() + "/.semanticwebimport/")); + refreshConfigurationSelector(); + } + + private void resetConfigurations() { + resetConfigurationSelector(); + configurationManager.setListProperties(new HashMap()); + } + + private void resetConfigurationSelector() { + configurationSelector.removeAllItems(); + } + + private void refreshConfigurationSelector() { + for (String nameConfiguration : configurationManager.getListProperties().keySet()) { + configurationSelector.addItem(nameConfiguration); + } + } + + public void setConfigurationAction(String configurationName) { + configurationManager.setCurrentProperties(configurationName); + Properties currentProperties = configurationManager.getCurrentProperties(); + if ((configurationName != null) && !configurationName.isEmpty()) { + logger.log(Level.INFO, "Loading configuration \"{0}\"", configurationName); + // Obtain the driver name and set it. + String driverName = currentProperties.getProperty(ConfigurationManager.DRIVER_NAME); + int driverIndex = findDriver(driverName); + if (driverIndex != -1) { + logger.log(Level.INFO, "Selecting the driver \"{0}\"", driverName); + sparqlDriverSelector.setSelectedIndex(driverIndex); + } else { + logger.log(Level.INFO, "No SPARQL driver found with name: \"{0}\"", driverName); + } + sparqlDriver.getParameters().readProperties(currentProperties); + refreshActiveSparqlDriver(); + + // Set the sparql request. + String sparqlRequest = configurationManager.getCurrentProperties().getProperty(ConfigurationManager.SPARQL_REQUEST); + sparqlRequestEditor.setQueryText(sparqlRequest); + } else { + logger.info("No configuration to load."); + } + } + + private Set loadFileConfigurations(final String directoryPath) throws IOException { + Set result = new HashSet(); + File fileProperties = new File(directoryPath); + if (fileProperties.exists()) { + if (fileProperties.isFile()) { + Properties newProperties = new Properties(); + newProperties.loadFromXML(new FileInputStream(fileProperties)); + result.add(newProperties); + } else if (fileProperties.isDirectory()) { + File[] files = fileProperties.listFiles(); + for (File file : files) { + try { + Properties newProperties = new Properties(); + FileInputStream is = new FileInputStream(file); + newProperties.loadFromXML(is); + is.close(); + result.add(newProperties); + } catch (Exception ex) { + logger.log(Level.SEVERE, "An exception occured when trying to parse the file {0}: {1}", new Object[]{file.getName(), ex.getMessage()}); + } + } + } + } + return result; + } + + private void fillSparqlDriverSelector() { + Collection sparqlDriverList = Lookup.getDefault().lookupAll(SparqlDriver.class); + sparqlDriverSelector.removeAllItems(); + for (SparqlDriver driver : sparqlDriverList) { + addDriver(driver); + } + sparqlDriverSelectorInitialized = true; + } + + private void addDriver(final SparqlDriver driver) { + sparqlDriverSelector.addItem(driver.getDisplayName()); + driverHandlers.add(driver); + } + + private int findDriver(final String className) { + for (int i = 0; i < driverHandlers.size(); ++i) { + if (driverHandlers.get(i).getClass().getName().equals(className)) { + return i; + } + } + return -1; + } + + /** + * This method is called from within the constructor to initialize the + * form. WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + graphBuilderTab = new javax.swing.JTabbedPane(); + driverSelectorPanel = new javax.swing.JPanel(); + sparqlDriverSelector = new javax.swing.JComboBox(); + sparqlDriverLabel = new javax.swing.JLabel(); + parametersPanel = new javax.swing.JPanel(); + sparqlEditorPanel = new javax.swing.JPanel(); + sparqlRequestLabel = new javax.swing.JLabel(); + sparqlRequestEditor = new fr.inria.corese.gui.query.SparqlQueryEditor(); + logPanel = new javax.swing.JPanel(); + jScrollPane2 = new javax.swing.JScrollPane(); + logWindow = new javax.swing.JTextArea(); + configurationPanel = new javax.swing.JPanel(); + jSeparator1 = new javax.swing.JSeparator(); + jSeparator2 = new javax.swing.JSeparator(); + pythonPanel = new javax.swing.JPanel(); + pythonPostProcessingFileName = new javax.swing.JTextField(); + pythonPostProcessingLabel = new javax.swing.JLabel(); + setPythonPostProcessingFileName = new javax.swing.JButton(); + pythonPreProcessingLabel = new javax.swing.JLabel(); + pythonPreProcessingFileName = new javax.swing.JTextField(); + setPythonPreProcessingFileName = new javax.swing.JButton(); + confiugrationManagementPanel = new javax.swing.JPanel(); + loadConfiguration = new javax.swing.JButton(); + saveConfiguration = new javax.swing.JButton(); + configurationSelector = new javax.swing.JComboBox(); + saveConfigurationNameTextField = new javax.swing.JTextField(); + setConfiguration = new javax.swing.JButton(); + jPanel1 = new javax.swing.JPanel(); + ignoreBlankNode = new javax.swing.JCheckBox(); + sparqlQueryResultButton = new javax.swing.JButton(); + fynSpinner = new javax.swing.JSpinner(); + sparqlQueryResultLabel = new javax.swing.JLabel(); + autoLayout = new javax.swing.JCheckBox(); + sparqlQueryResultFileName = new javax.swing.JTextField(); + fynLabel = new javax.swing.JLabel(); + resetWorkspace = new javax.swing.JCheckBox(); + start = new javax.swing.JButton(); + + setPreferredSize(new java.awt.Dimension(640, 480)); + setLayout(new java.awt.BorderLayout()); + + jScrollPane1.setPreferredSize(new java.awt.Dimension(600, 460)); + + graphBuilderTab.setBackground(new java.awt.Color(240, 242, 240)); + graphBuilderTab.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT); + graphBuilderTab.setToolTipText(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.graphBuilderTab.toolTipText")); // NOI18N + graphBuilderTab.setPreferredSize(new java.awt.Dimension(600, 450)); + + driverSelectorPanel.setPreferredSize(new java.awt.Dimension(600, 400)); + + sparqlDriverSelector.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"})); + sparqlDriverSelector.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + sparqlDriverSelectorActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(sparqlDriverLabel, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.sparqlDriverLabel.text")); // NOI18N + + parametersPanel.setBackground(new java.awt.Color(237, 235, 236)); + parametersPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("")); + parametersPanel.setForeground(new java.awt.Color(255, 0, 0)); + parametersPanel.setLayout(new java.awt.BorderLayout()); + + javax.swing.GroupLayout driverSelectorPanelLayout = new javax.swing.GroupLayout(driverSelectorPanel); + driverSelectorPanel.setLayout(driverSelectorPanelLayout); + driverSelectorPanelLayout.setHorizontalGroup( + driverSelectorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(driverSelectorPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(driverSelectorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(parametersPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 617, Short.MAX_VALUE) + .addGroup(driverSelectorPanelLayout.createSequentialGroup() + .addComponent(sparqlDriverSelector, 0, 499, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(sparqlDriverLabel))) + .addContainerGap()) + ); + driverSelectorPanelLayout.setVerticalGroup( + driverSelectorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(driverSelectorPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(driverSelectorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(sparqlDriverLabel) + .addComponent(sparqlDriverSelector, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(parametersPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 365, Short.MAX_VALUE) + .addContainerGap()) + ); + + graphBuilderTab.addTab(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.driverSelectorPanel.TabConstraints.tabTitle"), driverSelectorPanel); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(sparqlRequestLabel, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.sparqlRequestLabel.text")); // NOI18N + + javax.swing.GroupLayout sparqlEditorPanelLayout = new javax.swing.GroupLayout(sparqlEditorPanel); + sparqlEditorPanel.setLayout(sparqlEditorPanelLayout); + sparqlEditorPanelLayout.setHorizontalGroup( + sparqlEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(sparqlEditorPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(sparqlEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(sparqlRequestEditor, javax.swing.GroupLayout.DEFAULT_SIZE, 617, Short.MAX_VALUE) + .addComponent(sparqlRequestLabel)) + .addContainerGap()) + ); + sparqlEditorPanelLayout.setVerticalGroup( + sparqlEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(sparqlEditorPanelLayout.createSequentialGroup() + .addComponent(sparqlRequestLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(sparqlRequestEditor, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE) + .addContainerGap()) + ); + + graphBuilderTab.addTab(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.sparqlEditorPanel.TabConstraints.tabTitle"), sparqlEditorPanel); // NOI18N + + logWindow.setColumns(20); + logWindow.setRows(5); + jScrollPane2.setViewportView(logWindow); + + javax.swing.GroupLayout logPanelLayout = new javax.swing.GroupLayout(logPanel); + logPanel.setLayout(logPanelLayout); + logPanelLayout.setHorizontalGroup( + logPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 641, Short.MAX_VALUE) + .addGroup(logPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(logPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 617, Short.MAX_VALUE) + .addContainerGap())) + ); + logPanelLayout.setVerticalGroup( + logPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 425, Short.MAX_VALUE) + .addGroup(logPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(logPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE) + .addContainerGap())) + ); + + graphBuilderTab.addTab(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.logPanel.TabConstraints.tabTitle"), logPanel); // NOI18N + + configurationPanel.setPreferredSize(new java.awt.Dimension(640, 200)); + + pythonPostProcessingFileName.setText(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.pythonPostProcessingFileName.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(pythonPostProcessingLabel, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.pythonPostProcessingLabel.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(setPythonPostProcessingFileName, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.setPythonPostProcessingFileName.text")); // NOI18N + setPythonPostProcessingFileName.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + setPythonPostProcessingFileNameActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(pythonPreProcessingLabel, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.pythonPreProcessingLabel.text")); // NOI18N + + pythonPreProcessingFileName.setText(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.pythonPreProcessingFileName.text")); // NOI18N + pythonPreProcessingFileName.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + pythonPreProcessingFileNameActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(setPythonPreProcessingFileName, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.setPythonPreProcessingFileName.text")); // NOI18N + setPythonPreProcessingFileName.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + setPythonPreProcessingFileNameActionPerformed(evt); + } + }); + + javax.swing.GroupLayout pythonPanelLayout = new javax.swing.GroupLayout(pythonPanel); + pythonPanel.setLayout(pythonPanelLayout); + pythonPanelLayout.setHorizontalGroup( + pythonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(pythonPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(pythonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(pythonPreProcessingLabel) + .addComponent(pythonPostProcessingLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(pythonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(pythonPreProcessingFileName) + .addComponent(pythonPostProcessingFileName)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(pythonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(setPythonPreProcessingFileName, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(setPythonPostProcessingFileName, javax.swing.GroupLayout.Alignment.TRAILING)) + .addContainerGap()) + ); + + pythonPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, setPythonPostProcessingFileName, setPythonPreProcessingFileName); + + pythonPanelLayout.setVerticalGroup( + pythonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(pythonPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(pythonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(pythonPreProcessingLabel) + .addComponent(pythonPreProcessingFileName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(setPythonPreProcessingFileName)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(pythonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(pythonPostProcessingLabel) + .addComponent(pythonPostProcessingFileName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(setPythonPostProcessingFileName, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pythonPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, pythonPostProcessingFileName, pythonPostProcessingLabel, pythonPreProcessingFileName, pythonPreProcessingLabel, setPythonPostProcessingFileName, setPythonPreProcessingFileName); + + org.openide.awt.Mnemonics.setLocalizedText(loadConfiguration, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.loadConfiguration.text")); // NOI18N + loadConfiguration.setToolTipText(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.loadConfiguration.toolTipText")); // NOI18N + loadConfiguration.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + loadConfigurationActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(saveConfiguration, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.saveConfiguration.text")); // NOI18N + saveConfiguration.setToolTipText(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.saveConfiguration.toolTipText")); // NOI18N + saveConfiguration.setActionCommand(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.saveConfiguration.actionCommand")); // NOI18N + saveConfiguration.setPreferredSize(new java.awt.Dimension(0, 0)); + saveConfiguration.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + saveConfigurationActionPerformed(evt); + } + }); + + configurationSelector.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"})); + configurationSelector.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + configurationSelectorActionPerformed(evt); + } + }); + + saveConfigurationNameTextField.setText(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.saveConfigurationNameTextField.text")); // NOI18N + saveConfigurationNameTextField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + saveConfigurationNameTextFieldActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(setConfiguration, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.setConfiguration.text")); // NOI18N + setConfiguration.setToolTipText(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.setConfiguration.toolTipText")); // NOI18N + setConfiguration.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + setConfigurationActionPerformed(evt); + } + }); + + javax.swing.GroupLayout confiugrationManagementPanelLayout = new javax.swing.GroupLayout(confiugrationManagementPanel); + confiugrationManagementPanel.setLayout(confiugrationManagementPanelLayout); + confiugrationManagementPanelLayout.setHorizontalGroup( + confiugrationManagementPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(confiugrationManagementPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(confiugrationManagementPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(saveConfigurationNameTextField, javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(confiugrationManagementPanelLayout.createSequentialGroup() + .addComponent(setConfiguration, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(configurationSelector, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(confiugrationManagementPanelLayout.createSequentialGroup() + .addComponent(loadConfiguration) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(saveConfiguration, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE))) + .addContainerGap()) + ); + confiugrationManagementPanelLayout.setVerticalGroup( + confiugrationManagementPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(confiugrationManagementPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(confiugrationManagementPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(setConfiguration) + .addComponent(configurationSelector, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(saveConfigurationNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(confiugrationManagementPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(saveConfiguration, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(loadConfiguration)) + .addContainerGap()) + ); + + org.openide.awt.Mnemonics.setLocalizedText(ignoreBlankNode, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.ignoreBlankNode.text")); // NOI18N + ignoreBlankNode.setToolTipText(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.ignoreBlankNode.toolTipText")); // NOI18N + ignoreBlankNode.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + ignoreBlankNodeActionPerformed(evt); + } + }); + + sparqlQueryResultButton.setLabel(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.label")); // NOI18N + sparqlQueryResultButton.setName(""); // NOI18N + sparqlQueryResultButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + sparqlQueryResultButtonActionPerformed(evt); + } + }); + + fynSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1)); + + org.openide.awt.Mnemonics.setLocalizedText(sparqlQueryResultLabel, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.sparqlQueryResultLabel.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(autoLayout, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.autoLayout.text")); // NOI18N + autoLayout.setPreferredSize(new java.awt.Dimension(0, 0)); + autoLayout.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + autoLayoutActionPerformed(evt); + } + }); + + sparqlQueryResultFileName.setText(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.sparqlQueryResultFileName.text")); // NOI18N + sparqlQueryResultFileName.setToolTipText(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.sparqlQueryResultFileName.toolTipText")); // NOI18N + sparqlQueryResultFileName.setPreferredSize(new java.awt.Dimension(4, 10)); + sparqlQueryResultFileName.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + sparqlQueryResultFileNameActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(fynLabel, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.fynLabel.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(resetWorkspace, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.resetWorkspace.text")); // NOI18N + resetWorkspace.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + resetWorkspaceActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(sparqlQueryResultLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(sparqlQueryResultFileName, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(sparqlQueryResultButton, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(resetWorkspace) + .addComponent(autoLayout, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(ignoreBlankNode) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(fynSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(fynLabel))))) + .addContainerGap()) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(sparqlQueryResultLabel) + .addComponent(sparqlQueryResultFileName, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(sparqlQueryResultButton)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(resetWorkspace) + .addComponent(ignoreBlankNode)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(autoLayout, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(fynSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(fynLabel)) + .addContainerGap()) + ); + + jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, sparqlQueryResultButton, sparqlQueryResultFileName, sparqlQueryResultLabel); + + javax.swing.GroupLayout configurationPanelLayout = new javax.swing.GroupLayout(configurationPanel); + configurationPanel.setLayout(configurationPanelLayout); + configurationPanelLayout.setHorizontalGroup( + configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(configurationPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(pythonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jSeparator1) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jSeparator2) + .addComponent(confiugrationManagementPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) + ); + configurationPanelLayout.setVerticalGroup( + configurationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(configurationPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(4, 4, 4) + .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(3, 3, 3) + .addComponent(pythonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE) + .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(confiugrationManagementPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(64, Short.MAX_VALUE)) + ); + + graphBuilderTab.addTab(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.configurationPanel.TabConstraints.tabTitle"), configurationPanel); // NOI18N + + jScrollPane1.setViewportView(graphBuilderTab); + graphBuilderTab.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.jTabbedPane1.AccessibleContext.accessibleName")); // NOI18N + + add(jScrollPane1, java.awt.BorderLayout.CENTER); + + start.setBackground(new java.awt.Color(255, 0, 51)); + org.openide.awt.Mnemonics.setLocalizedText(start, org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.start.text")); // NOI18N + start.setToolTipText(org.openide.util.NbBundle.getMessage(SemanticWebImportMainWindowTopComponent.class, "SemanticWebImportMainWindowTopComponent.start.toolTipText")); // NOI18N + start.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM); + start.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + startCreateGraphsAction(evt); + } + }); + add(start, java.awt.BorderLayout.SOUTH); + }// //GEN-END:initComponents + + private void sparqlDriverSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sparqlDriverSelectorActionPerformed + + if (sparqlDriverSelectorInitialized) { + if ("comboBoxChanged".equals(evt.getActionCommand())) { + refreshActiveSparqlDriver(); + } + } + }//GEN-LAST:event_sparqlDriverSelectorActionPerformed + + private void sparqlQueryResultButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sparqlQueryResultButtonActionPerformed + }//GEN-LAST:event_sparqlQueryResultButtonActionPerformed + + private void sparqlQueryResultFileNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sparqlQueryResultFileNameActionPerformed + }//GEN-LAST:event_sparqlQueryResultFileNameActionPerformed + + private void saveConfigurationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveConfigurationActionPerformed + configurationManager.saveConfigurationActionPerformed(sparqlDriver, saveConfigurationNameTextField.getText(), sparqlRequestEditor.getQueryText(), pythonPreProcessingFileName.getText(), pythonPostProcessingFileName.getText()); + }//GEN-LAST:event_saveConfigurationActionPerformed + + private void setConfigurationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setConfigurationActionPerformed + String configurationName = (String) configurationSelector.getSelectedItem(); + setConfigurationAction(configurationName); + }//GEN-LAST:event_setConfigurationActionPerformed + + private void configurationSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configurationSelectorActionPerformed + }//GEN-LAST:event_configurationSelectorActionPerformed + + private void autoLayoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoLayoutActionPerformed + }//GEN-LAST:event_autoLayoutActionPerformed + + private void resetWorkspaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetWorkspaceActionPerformed + }//GEN-LAST:event_resetWorkspaceActionPerformed + + private void ignoreBlankNodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ignoreBlankNodeActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_ignoreBlankNodeActionPerformed + + private void loadConfigurationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadConfigurationActionPerformed + Properties properties = configurationManager.loadConfigurationActionPerformed(evt); + addConfiguration(properties); + resetConfigurationSelector(); + refreshConfigurationSelector(); + String configurationName = properties.getProperty(ConfigurationManager.CONFIGURATION_NAME); + pythonPreProcessingFileName.setText(properties.getProperty(ConfigurationManager.PYTHON_PRE)); + pythonPostProcessingFileName.setText(properties.getProperty(ConfigurationManager.PYTHON_POST)); + setConfigurationAction(configurationName); + saveConfigurationNameTextField.setText(configurationName); + }//GEN-LAST:event_loadConfigurationActionPerformed + + private void saveConfigurationNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveConfigurationNameTextFieldActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_saveConfigurationNameTextFieldActionPerformed + + private void setPythonPostProcessingFileNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setPythonPostProcessingFileNameActionPerformed + setPythonProcessingFileName("File to use for python post-processsing", pythonPostProcessingFileName); + }//GEN-LAST:event_setPythonPostProcessingFileNameActionPerformed + + private void pythonPreProcessingFileNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pythonPreProcessingFileNameActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_pythonPreProcessingFileNameActionPerformed + + private void setPythonPreProcessingFileNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setPythonPreProcessingFileNameActionPerformed + setPythonProcessingFileName("File to use for python pre-processsing", pythonPreProcessingFileName); + }//GEN-LAST:event_setPythonPreProcessingFileNameActionPerformed + + private void setPythonProcessingFileName(final String message, JTextField field) { + File newFile = FilesUtils.selectFile(JFileChooser.OPEN_DIALOG, message, "Load", lastPythonUsedDirectory, this, ".py", "Python script"); + if (newFile == null) { + return; + } + field.setText(newFile.getAbsolutePath()); + lastPythonUsedDirectory = newFile.getParent(); + } + + private void startCreateGraphsAction(java.awt.event.ActionEvent evt) { + startCreateGraphs(); + } + + /* + * This is launching the asynchronous build of the graph. + * Since the task is asynchronous. Processing done when it is finished must be placed in terminate(). + * \sa waitCreateGraphs to wait for the completion of the graph. + * \sa terminate to + */ + public void startCreateGraphs() { + applyPythonScript(pythonPreProcessingFileName.getText()); + + logger.info("Entering startCreateGraphs"); + final SemanticWebImportParser.RequestParameters requestParameters = new SemanticWebImportParser.RequestParameters(sparqlRequestEditor.getQueryText()); + rdfParser = new SemanticWebImportParser(requestParameters); + + logger.info("Starting the RDF importer for Gephi"); + watch = new StopWatch(); + refreshActiveSparqlDriver(); + refreshCurrentConfiguration(); + rdfParser.populateRDFGraph(getSparqlDriver(), configurationManager.getCurrentProperties(), this); + // + } + + @Override + public void taskFinished(LongTask lt) { + applyPythonScript(pythonPostProcessingFileName.getText()); + + logger.log(Level.INFO, "Finished startCreateGraphs. Time elapsed = {0} milliseconds", watch.elapsedMillis()); + } + // End of variables declaration//GEN-END:variables + + /** + * @param fileName + * @TODO restore the python script functionality + */ + private void applyPythonScript(String fileName) { + // Apply python script after import. +// try { +// ScriptingController scripting = Lookup.getDefault().lookup(ScriptingController.class); +// PythonInterpreter interpreter = scripting.getPythonInterpreter(); +// InputStream pythonStream = FilesUtils.getResourceOrFile(fileName); +// interpreter.execfile(pythonStream); +// } catch (IllegalArgumentException ex) { +// +// } + } + + private void refreshActiveSparqlDriver() { + String newDriverName = getCurrentSelectedDriverName(); + + // The panel and the driver needs to be built iff (i) there is none; (ii) the driver selected is different from the current one. + if (sparqlDriver == null || (!newDriverName.equals(sparqlDriver.getClass().getName()))) { + try { + // Build the new driver. + sparqlDriver = SparqlDriverFactory.getDriver(newDriverName); + SparqlDriverParameters parameters = sparqlDriver.getParameters(); + + parametersPanel.removeAll(); + // Fill the new parameters panel. + String panelClassName = sparqlDriver.getParameters().getPanelClassName(); + ClassLoader loader = Lookup.getDefault().lookup(ClassLoader.class); + Constructor constructor = loader.loadClass(panelClassName).getDeclaredConstructor(sparqlDriver.getParameters().getClass()); + DriverParametersPanel newPanel = (DriverParametersPanel) constructor.newInstance(sparqlDriver.getParameters()); + if (newPanel != null) { + newPanel.setParameters(parameters); + parametersPanel.add(newPanel); + parametersPanel.setVisible(true); + parametersPanel.validate(); + } + + parameters.addObserver(newPanel); +// parameters.addObserver(sparqlDriver); + } catch (IllegalArgumentException ex) { + Exceptions.printStackTrace(ex); + } catch (InvocationTargetException ex) { + Exceptions.printStackTrace(ex); + } catch (NoSuchMethodException ex) { + Exceptions.printStackTrace(ex); + } catch (SecurityException ex) { + Exceptions.printStackTrace(ex); + } catch (InstantiationException ex) { + Exceptions.printStackTrace(ex); + } catch (IllegalAccessException ex) { + Exceptions.printStackTrace(ex); + } catch (ClassNotFoundException ex) { + Exceptions.printStackTrace(ex); + } + } + } + + private String getCurrentSelectedDriverName() { + int driverIndex = sparqlDriverSelector.getSelectedIndex(); + SparqlDriver newDriver = driverHandlers.get(driverIndex); + return newDriver.getClass().getName(); + } + + /** + * Set the values of the properties by reading the GUI state elements. + * \todo Should be in the configuration manager, with a listener + * mechanism to update the properties. + */ + private void refreshCurrentConfiguration() { + configurationManager.getCurrentProperties().setProperty(String.valueOf(IGNORE_BLANK_PROPERTIES), Boolean.toString(ignoreBlankNode.isSelected())); + configurationManager.getCurrentProperties().setProperty(String.valueOf(RESET_WORKSPACE), Boolean.toString(resetWorkspace.isSelected())); + configurationManager.getCurrentProperties().setProperty(String.valueOf(POST_PROCESSING), Boolean.toString(autoLayout.isSelected())); + configurationManager.getCurrentProperties().setProperty(String.valueOf(SAVE_SPARQL_RESULT), sparqlQueryResultFileName.getText()); + configurationManager.getCurrentProperties().setProperty(String.valueOf(FYN_LEVEL), Integer.toString((Integer) fynSpinner.getValue())); + } + + /* + * Block until the thread building the graph terminates. + */ + public void waitCreateGraphs() throws InterruptedException { + rdfParser.waitEndpopulateRDFGraph(); + } + + public JPanel getDriverSelectorPanel() { + return driverSelectorPanel; + } + + public String getSparqlRequest() { + return sparqlRequestEditor.getQueryText(); + } + + private SparqlDriver getSparqlDriver() { + return this.sparqlDriver; + } + + private void addConfigurations(Set configurations) { + for (Properties p : configurations) { + addConfiguration(p); + } + } + + private void addConfiguration(Properties configuration) { + configurationManager.getListProperties().put(configuration.getProperty(ConfigurationManager.CONFIGURATION_NAME), configuration); + } + + @Override + public String sparqlQuery(String request) { + CoreseDriver driver = new CoreseDriver(); + try { + driver.getParameters().addResource(createTempLastRdfFile().getAbsolutePath()); + driver.init(); + return driver.sparqlQuery(request); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + return ""; + } + + /** + * Apply a SPARQL request on the RDF used to display the graph. For + * example, a "select ?x ?y ?z where { ?x ?y ?z} limit 10" query will + * return a String[3][] array of size at most 10. The first column will + * contain the results for ?x, the second for ?y, etc. + * + * @param request + * @return The URI of the bindings, each column. + */ + @Override + public String[][] selectOnGraph(final String request) { + CoreseDriver driver = new CoreseDriver(); + try { + driver.getParameters().addResource(createTempLastRdfFile().getAbsolutePath()); + driver.init(); + return driver.selectOnGraph(request); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + return new String[0][0]; + } + + private File createTempLastRdfFile() throws IOException { + File tempFile = File.createTempFile("tempLastRdf", ".rdf"); + tempFile.deleteOnExit(); + try (FileWriter fw = new FileWriter(tempFile)) { + fw.append(rdfParser.getLastRdfResult()); + } + return tempFile; + } + + ConfigurationManager getConfigurationManager() { + return configurationManager; + } + + @Override + public int getPersistenceType() { + return TopComponent.PERSISTENCE_ALWAYS; + } + + void writeProperties(java.util.Properties p) { + // better to version settings since initial version as advocated at + // http://wiki.apidesign.org/wiki/PropertyFiles + p.setProperty("version", "1.0"); + p.setProperty(IGNORE_BLANK_PROPERTIES.getValue(), + Boolean.toString(ignoreBlankNode.isSelected())); + } + + Object readProperties(java.util.Properties p) { + if (instance == null) { + instance = this; + } + instance.readPropertiesImpl(p); + return instance; + } + + private void readPropertiesImpl(java.util.Properties p) { + String version = p.getProperty("version"); + ignoreBlankNode.setSelected( + Boolean.getBoolean(p.getProperty(IGNORE_BLANK_PROPERTIES.getValue()))); + } + + @Override + protected String preferredID() { + return PREFERRED_ID; + } + + public SparqlRequester getDriver() { + return sparqlDriver; + } + + public void addTab(final String title, JPanel panel) { + int tabIndex = findTab(title); + if (tabIndex == -1) { + tabIndex = graphBuilderTab.getTabCount(); + } else { + graphBuilderTab.removeTabAt(tabIndex); + } + graphBuilderTab.insertTab(title, SemanticWebImportMainWindowTopComponent.loadIcon(), panel, title, tabIndex); + } + + private int findTab(String title) { + for (int numTab = 0; numTab < graphBuilderTab.getTabCount(); ++numTab) { + if (graphBuilderTab.getTitleAt(numTab).equals(title)) { + return numTab; + } + } + return -1; + } + + class LogWindowHandler extends Handler { + + public LogWindowHandler() { + setFormatter(new SimpleFormatter()); + } + + @Override + public void publish(LogRecord record) { + logWindow.append(getFormatter().format(record).replace("\n", " -- ") + '\n'); + } + + @Override + public void flush() { + } + + @Override + public void close() throws SecurityException { + } + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/AbstractPostProcessor.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/AbstractPostProcessor.java new file mode 100644 index 0000000000..390c8a3e7c --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/AbstractPostProcessor.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +package fr.inria.edelweiss.semantic.analyzer; + +import org.gephi.graph.api.GraphModel; + +/** + * Define the interfaces for the classes implementing a behaviour to be applied after building a graph from a Sparql + * request. + * + * @author edemairy + */ +public abstract class AbstractPostProcessor implements Runnable { + + private GraphModel model; + + public GraphModel getModel() { + return model; + } + + public void setModel(GraphModel model) { + this.model = model; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/Edge.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/Edge.java new file mode 100644 index 0000000000..de6e91855a --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/Edge.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.analyzer; + +/** + * + * @author edemairy + */ +public class Edge { + private String source; + private String id; + private String destination; + + Edge(String urI, String urI0, String urI1) { + source = urI; + id = urI0; + destination = urI1; + } + + /** + * @return the source + */ + public String getSource() { + return source; + } + + /** + * @param source the source to set + */ + public void setSource(String source) { + this.source = source; + } + + /** + * @return the id + */ + public String getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the destination + */ + public String getDestination() { + return destination; + } + + /** + * @param destination the destination to set + */ + public void setDestination(String destination) { + this.destination = destination; + } + + public String toString() { + return source+" -- "+id+" --> "+destination; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/EmptyAbstractPostProcessor.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/EmptyAbstractPostProcessor.java new file mode 100644 index 0000000000..50bc37adb7 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/EmptyAbstractPostProcessor.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.analyzer; + +import java.util.logging.Logger; + +/** + * + * @author edemairy + */ +public class EmptyAbstractPostProcessor extends AbstractPostProcessor { + + private static final Logger logger = Logger.getLogger(EmptyAbstractPostProcessor.class.getName()); + + @Override + public void run() { + logger.info("Applying empty post-processing"); + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/GephiExtension.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/GephiExtension.java new file mode 100644 index 0000000000..cc5ce53562 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/GephiExtension.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.analyzer; + +import fr.inria.edelweiss.sparql.GephiUtils; + +import javax.swing.text.html.StyleSheet; +import java.awt.Color; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class GephiExtension { + + public static final String GEPHI_PREFIX = "http://gephi.org/"; + public static final String GEPHI_SET_LABEL = GEPHI_PREFIX + "label"; + public static final String GEPHI_SET_SIZE = GEPHI_PREFIX + "size"; + public static final String GEPHI_SET_COLOR_RGB = GEPHI_PREFIX + "colorRGB"; + public static final String GEPHI_SET_COLOR = GEPHI_PREFIX + "color"; + public static final String GEPHI_SET_COLOR_R = GEPHI_PREFIX + "color_r"; + public static final String GEPHI_SET_COLOR_G = GEPHI_PREFIX + "color_g"; + public static final String GEPHI_SET_COLOR_B = GEPHI_PREFIX + "color_b"; + public static final String GEPHI_SET_SHAPE = GEPHI_PREFIX + "sharp"; + + enum C { + + red(Color.RED), blue(Color.BLUE), green(Color.GREEN), pink(Color.PINK), white(Color.WHITE), black(Color.BLACK), + gray(Color.GRAY), yellow(Color.YELLOW), cyan(Color.CYAN), orange(Color.ORANGE), magenta(Color.MAGENTA), darkGray(Color.DARK_GRAY), + lightGray(Color.LIGHT_GRAY); + private final Color color; + + C(Color color) { + this.color = color; + } + + public static Color get(String name) { + for (C a : C.values()) { + if (a.toString().equals(name)) { + return a.color; + } + } + return null; + } + } + + enum Shape { + + SPHERE("sphere"), DISK("disk"), RECTANGLE("rectangle"), CIRCLE("circle"), DOT("dot"), SQUARE("square"); + private final String shapeName; + + Shape(final String shapeName) { + this.shapeName = shapeName; + } + + public static String getShape(String name) { + for (Shape s : Shape.values()) { + if (s.toString().equals(name)) { + return s.shapeName; + } + } + return null; + } + } + private static final Logger logger = Logger.getLogger(GephiExtension.class.getName()); + + public static boolean isGephiExtension(final String name) { + return name.startsWith(GEPHI_PREFIX); + } + + public static void processGephiExtension(final String sourceLabel, final String edgeLabel, final String targetLabel, final GephiUtils gephiUtil) { + if (gephiUtil.isEdge(sourceLabel)) { + logger.log(Level.SEVERE, "Setting values on edges is not supported.\n {0} -- {1} --> {2} failed.", new Object[]{sourceLabel, edgeLabel, targetLabel}); + return; + } + if (!gephiUtil.nodeExist(sourceLabel)) { + gephiUtil.addNode(sourceLabel); + } + if (edgeLabel.equals(GEPHI_SET_LABEL)) { + gephiUtil.setNodeLabel(sourceLabel, targetLabel); + } + + if (edgeLabel.equals(GEPHI_SET_SIZE)) { + float targetSize = GephiUtils.convertFloat(targetLabel); + gephiUtil.setNodeSize(sourceLabel, targetSize); + } + + if (edgeLabel.equals(GEPHI_SET_COLOR_RGB)) { + String[] colorRGB = GephiUtils.stringSplit(targetLabel); + float color_r = GephiUtils.convertFloatColor(colorRGB[0]); + float color_g = GephiUtils.convertFloatColor(colorRGB[1]); + float color_b = GephiUtils.convertFloatColor(colorRGB[2]); + gephiUtil.setNodeColor(sourceLabel, color_r, color_g, color_b); + } + + if (edgeLabel.equals(GEPHI_SET_COLOR)) { + Color c; + StyleSheet style = new StyleSheet(); + c = style.stringToColor(targetLabel.toLowerCase()); + if (c == null) { + logger.log(Level.WARNING, "Color \"{0}\" not found. Setting the color to black instead.", targetLabel); + c = Color.BLACK; + } + + int r = c.getRed(); + int g = c.getGreen(); + int b = c.getBlue(); + String rValue = Integer.toString(r); + String gValue = Integer.toString(g); + String bValue = Integer.toString(b); + float color_r = GephiUtils.convertFloatColor(rValue); + float color_g = GephiUtils.convertFloatColor(gValue); + float color_b = GephiUtils.convertFloatColor(bValue); + gephiUtil.setNodeColor(sourceLabel, color_r, color_g, color_b); + } + + if (edgeLabel.equals(GEPHI_SET_COLOR_R)) { + float color_r = GephiUtils.convertFloatColor(targetLabel); + gephiUtil.setNodeColor_R(sourceLabel, color_r); + } + + if (edgeLabel.equals(GEPHI_SET_COLOR_G)) { + float color_g = GephiUtils.convertFloatColor(targetLabel); + gephiUtil.setNodeColor_G(sourceLabel, color_g); + } + + if (edgeLabel.equals(GEPHI_SET_COLOR_B)) { + float color_b = GephiUtils.convertFloatColor(targetLabel); + gephiUtil.setNodeColor_B(sourceLabel, color_b); + } + + if (edgeLabel.equals(GEPHI_SET_SHAPE)) { + String shape; + shape = Shape.getShape(targetLabel.toLowerCase()); + gephiUtil.setNodeShape(sourceLabel, shape); + } else { + String nameNewAttribute = edgeLabel.replaceFirst(GEPHI_PREFIX, ""); + if (gephiUtil.isEdge(sourceLabel)) { + gephiUtil.addAttributeToEdges(nameNewAttribute, String.class); + gephiUtil.setEdgeAttr(sourceLabel, nameNewAttribute, targetLabel); + } else { + gephiUtil.addAttributeToNodes(nameNewAttribute, String.class); + gephiUtil.setNodeAttr(sourceLabel, nameNewAttribute, targetLabel); + } + } + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/RdfAnalyzer.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/RdfAnalyzer.java new file mode 100644 index 0000000000..227d14d04e --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/RdfAnalyzer.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.analyzer; + +import fr.inria.edelweiss.semantic.LayoutExampleAbstractPostProcessor; +import fr.inria.edelweiss.sparql.RdfParser; +import fr.inria.edelweiss.sparql.SparqlDriver; +import org.gephi.graph.api.GraphModel; +import org.gephi.utils.longtask.spi.LongTask; +import org.gephi.utils.progress.Progress; +import org.gephi.utils.progress.ProgressTicket; +import org.openide.util.Exceptions; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * The purpose of this class is to build a semantic graph from the result of a + * SPARQL request to a SPARQL driver. It is responsible to call the driver + * parameterized with the request and parse the result to produce the graph. + * + * @author Erwan Demairy + */ +public class RdfAnalyzer implements LongTask, Runnable { + + private static final Logger logger = Logger.getLogger(RdfAnalyzer.class.getName()); + final GraphModel model; + final String sparqlRequest; + private SparqlDriver driver; + private AbstractPostProcessor abstractPostProcessor; + private String saveResultName; + private String sparqlRequestResult; + private ProgressTicket progressTicket; + private final int fynLevel; + + /** + * Constructor. + * + * @param newModel Model to fill. + * @param newSparqlRequest SPARQL request to fill with the model. + */ + public RdfAnalyzer(final GraphModel newModel, final String newSparqlRequest, final int fynLevel) { + super(); + this.model = newModel; + this.sparqlRequest = newSparqlRequest; + this.fynLevel = fynLevel; + abstractPostProcessor = new EmptyAbstractPostProcessor(); + } + + @Override + public final void run() { + logger.info("Begin: Building the implementation relationships graph."); + int waitSeconds = 5; + Progress.start(progressTicket, waitSeconds); + + try { + Progress.progress(progressTicket); + sparqlRequestResult = driver.sparqlQuery(sparqlRequest); + + InputStream rdf = new ByteArrayInputStream(getSparqlRequestResult().getBytes(StandardCharsets.UTF_8)); + RdfParser parser = new RdfParser(rdf, model, fynLevel); + + Progress.progress(progressTicket); + parser.parse(); + logger.log(Level.INFO, "Number of triples parsed: {0}", parser.getTripleNumber()); + } catch (Exception e) { + logger.log(Level.INFO, "error when obtaining the nodes and edges: {0}", e.getMessage()); + Exceptions.printStackTrace(e); + } + + Progress.progress(progressTicket); + try { + saveResult(getSparqlRequestResult()); + } catch (Exception e) { + logger.log(Level.INFO, "error when saving the result: {0}", e.getMessage()); + } + Progress.progress(progressTicket); + abstractPostProcessor.setModel(model); + abstractPostProcessor.run(); + + logger.info("End: Building the implementation relationships graph."); + Progress.finish(progressTicket); + } + + public final void setPostProcessing(final LayoutExampleAbstractPostProcessor newPostProcessor) { + this.abstractPostProcessor = newPostProcessor; + } + + public final SparqlDriver getSparqlEngine() { + return this.driver; + } + + public final void setSparqlEngine(final SparqlDriver newDriver) { + this.driver = newDriver; + } + + public void setSaveResult(String saveResultName) { + this.saveResultName = saveResultName; + } + + private void saveResult(String sparqlRequestResult) throws IOException { + if (this.saveResultName.isEmpty()) { + return; + } + try (var fSave = new FileOutputStream(saveResultName)) { + fSave.write(sparqlRequestResult.getBytes()); + } + } + + /** + * @return the sparqlRequestResult + */ + public String getSparqlRequestResult() { + return sparqlRequestResult; + } + + @Override + public boolean cancel() { + return true; + } + + @Override + public void setProgressTicket(ProgressTicket pt) { + this.progressTicket = pt; + } + +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/RdfIterator.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/RdfIterator.java new file mode 100644 index 0000000000..9de22e5d20 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/analyzer/RdfIterator.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.analyzer; + +import com.hp.hpl.jena.rdf.arp.ALiteral; +import com.hp.hpl.jena.rdf.arp.ARP; +import com.hp.hpl.jena.rdf.arp.AResource; +import com.hp.hpl.jena.rdf.arp.StatementHandler; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXParseException; + +/** + * + * @author edemairy + */ +public class RdfIterator implements Iterator { + + private static final Logger logger = Logger.getLogger(RdfIterator.class.getName()); + private InputStream rdf; + private boolean parsed; + ArrayList content; + Iterator internalIterator; + + public RdfIterator(InputStream rdf) { + this.rdf = rdf; + parsed = false; + this.content = new ArrayList(); + } + + @Override + public boolean hasNext() { + initIfNecesary(); + return internalIterator.hasNext(); + } + + @Override + public Edge next() { + initIfNecesary(); + return internalIterator.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException("Operation not implemented."); + } + + private void initIfNecesary() { + if (parsed) { + return; + } else { + parse(); + internalIterator = content.iterator(); + parsed = true; + } + } + + private void parse() { + final ARP arp = new ARP(); + + arp.getHandlers().setErrorHandler(new ErrorHandler() { + + @Override + public void fatalError(final SAXParseException e) { + logger.log(Level.SEVERE, e.getMessage()); + } + + @Override + public void error(final SAXParseException e) { + logger.log(Level.SEVERE, e.getMessage()); + } + + @Override + public void warning(final SAXParseException e) { + logger.log(Level.INFO, e.getMessage()); + } + }); + arp.getHandlers().setStatementHandler(new ArpParsingHandler()); + + // parsing. + + try { + arp.load(rdf); + } catch (Exception ex) { + logger.log(Level.SEVERE, ex.getMessage()); + } + } + + private class ArpParsingHandler implements StatementHandler { + + @Override + public void statement(AResource subj, AResource pred, AResource obj) { + content.add(new Edge(subj.getURI(), pred.getURI(), obj.getURI())); + } + + @Override + public void statement(AResource subj, AResource pred, ALiteral lit) { + content.add(new Edge(subj.getURI(), pred.getURI(), lit.toString())); + } + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/configurationmanager/ConfigurationManager.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/configurationmanager/ConfigurationManager.java new file mode 100644 index 0000000000..2971a9f555 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/configurationmanager/ConfigurationManager.java @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +package fr.inria.edelweiss.semantic.configurationmanager; + +import fr.inria.edelweiss.semantic.SemanticWebImportMainWindowTopComponent; +import fr.inria.edelweiss.semantic.utils.FilesUtils; +import fr.inria.edelweiss.sparql.SparqlDriver; +import fr.inria.edelweiss.sparql.SparqlDriverParameters; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.jar.JarFile; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JFileChooser; +import org.openide.util.Exceptions; + +/** + * + * @author edemairy + */ +public class ConfigurationManager { + + static String lastDirectorySaveConfiguration = System.getenv("HOME") + "/.semanticwebimport/"; + public final static String DRIVER_NAME = "SparqlDriver"; + public final static String CONFIGURATION_NAME = "Name"; + public final static String SPARQL_REQUEST = "SparqlRequest"; + public final static String PYTHON_PRE = "PythonPre"; + public final static String PYTHON_POST = "PythonPost"; + private static final Logger logger = Logger.getLogger(ConfigurationManager.class.getName()); + private Map listProperties = null; + private Properties currentProperties = new Properties(); + private final Component parent; + + public ConfigurationManager(Component newParent) { + parent = newParent; + } + + /** + * @return the listProperties + */ + public Map getListProperties() { + return listProperties; + } + + /** + * @param listProperties the listProperties to set + */ + public void setListProperties(Map listProperties) { + this.listProperties = listProperties; + } + + public void setCurrentProperties(String configurationName) { + currentProperties = listProperties.get(configurationName); + } + + public Properties getCurrentProperties() { + return currentProperties; + } + + public void saveConfigurationActionPerformed(SparqlDriver sparqlDriver, String configurationName, String sparqlRequest, String pythonPre, String pythonPost) { + OutputStream os = null; + try { + File newFile = FilesUtils.selectFile(JFileChooser.SAVE_DIALOG, "Saving configuration \"" + configurationName + "\"", "Save", lastDirectorySaveConfiguration, parent, ".xml", "Configuration file"); + if (newFile == null) { + return; + } + os = new java.io.FileOutputStream(newFile); + try { + Properties properties = new Properties(currentProperties); + + sparqlDriver.getParameters().writeProperties(properties); + properties.setProperty(CONFIGURATION_NAME, configurationName); + properties.setProperty(DRIVER_NAME, sparqlDriver.getClass().getName()); + properties.setProperty(SPARQL_REQUEST, sparqlRequest); + properties.setProperty(PYTHON_POST, pythonPost); + properties.setProperty(PYTHON_PRE, pythonPre); + properties.storeToXML(os, "Properties to save."); + + os.close(); + + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + + } catch (FileNotFoundException ex) { + Exceptions.printStackTrace(ex); + } finally { + try { + if (os != null) { + os.close(); + } + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + } + + public Properties loadConfigurationActionPerformed(ActionEvent evt) { + File newFile = FilesUtils.selectFile(JFileChooser.OPEN_DIALOG, "Loading configuration", "Load", lastDirectorySaveConfiguration, parent, ".xml", "Configuration file"); + if (newFile == null) { + return new Properties(); + } + InputStream is = null; + try { + is = new java.io.FileInputStream(newFile); + } catch (FileNotFoundException ex) { + Exceptions.printStackTrace(ex); + } + if (is == null) { + throw new IllegalArgumentException("Impossible to open the file."); + } + Properties result = new Properties(); + try { + result.loadFromXML(is); + } catch (IOException ex) { + logger.log(Level.SEVERE, "exception occurred when loading the file: {0}", ex.getMessage()); + } + return result; + } + + /** + * + * @param directoryPath Path to the directory inside the jar of this class + * where to find the configuration files. + * @return A set of properties, each object containing a configuration for + * the plugin. + */ + public Set loadResourceConfigurations(final String directoryPath) { + Set result = new HashSet(); + ArrayList paths = listFilesInJar(ConfigurationManager.class, directoryPath); + for (String path : paths) { + String fileName = directoryPath + path; + try { + result.add(loadResourceConfiguration(fileName)); + } catch (IOException ex) { + logger.log(Level.SEVERE, "Exception occured when attempting to read as a set of properties the resource file: {0}", fileName); + } + } + return result; + } + + public Properties loadResourceConfiguration(final String fileName) throws IOException { + Properties newProperties = new Properties(); + InputStream is = SemanticWebImportMainWindowTopComponent.class.getResourceAsStream(fileName); + newProperties.loadFromXML(is); + is.close(); + return newProperties; + } + + /** + * List the files inside a jar in a given directory. + * + * @param classJar The jar searched is the jar containing the class + * classJar. + * @param path Path to list inside the jar. + * @return A list of short file names (i.e. removing the string "path"). + */ + static protected ArrayList listFilesInJar(java.lang.Class classJar, String path) { + ArrayList result = new ArrayList(); + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + URL dirURL = classLoader.getResource(removeFirstSlash(path)); + logger.log(Level.INFO, " dirURL = {0}, protocol = {1}", new Object[]{dirURL.getPath(), dirURL.getProtocol()}); + try { + if (dirURL.getProtocol().equals("jar")) { + String jarPath = dirURL.getPath().substring("file:".length(), dirURL.getPath().indexOf("!")); + String jarName = URLDecoder.decode(jarPath, "UTF-8"); + result = listFilesInJar(jarName, path); + } else if (dirURL.getProtocol().equals("file")) { + File folder = new File(dirURL.getFile()); + File[] contenuti = folder.listFiles(); + String entryName; + for (File actual : contenuti) { + entryName = actual.getName(); + entryName = entryName.substring(0, entryName.lastIndexOf('.')); + result.add(entryName); + } + + } else { + logger.log(Level.SEVERE, "Unsupported kind of file: the path {0} is of type: {1}.", new Object[]{path, dirURL.getProtocol()}); + } + } catch (IOException ex) { + logger.log(Level.SEVERE, "Exception when attempting to read the default configurations: {0}.", ex.getMessage()); + } + + return result; + } + + protected static ArrayList listFilesInJar(String jarName, String path) throws IOException { + if (path.startsWith("/")) { + path = path.substring(1); + } + ArrayList result = new ArrayList(); + try (JarFile jar = new JarFile(jarName)) { + var entries = jar.entries(); + while (entries.hasMoreElements()) { + var name = entries.nextElement().getName(); + logger.log(Level.INFO, "{0}", name); + if (name.startsWith(path)) { //filter according to the path + var entry = name.substring(path.length()); + int checkSubdir = entry.indexOf("/"); + if (checkSubdir >= 0) { + // if it is a subdirectory, we just return the directory name + entry = entry.substring(0, checkSubdir); + } + if (!entry.isEmpty()) { + result.add(entry); + } + } + } + } + return result; + } + + private static String removeFirstSlash(String path) { + if (path.charAt(0) == '/') { + return path.substring(1); + } else { + return path; + } + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/NullLongTaskListener.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/NullLongTaskListener.java new file mode 100644 index 0000000000..822e3d25ea --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/NullLongTaskListener.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + + +package fr.inria.edelweiss.semantic.importer; + +import org.gephi.utils.longtask.api.LongTaskListener; +import org.gephi.utils.longtask.spi.LongTask; + +/** + * + * @author Erwan Demairy + */ +class NullLongTaskListener implements LongTaskListener { + + public NullLongTaskListener() { + } + + @Override + public void taskFinished(LongTask lt) { + } + +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImportBuilder.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImportBuilder.java new file mode 100644 index 0000000000..fdb362027a --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImportBuilder.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.importer; + +import org.gephi.io.importer.api.FileType; +import org.gephi.io.importer.spi.FileImporter; +import org.gephi.io.importer.spi.FileImporterBuilder; +import org.openide.util.lookup.ServiceProvider; + +/** + * Factory class for building the importer instances. + * @author edemairy + */ +@ServiceProvider(service = FileImporterBuilder.class) +public class SemanticWebImportBuilder implements FileImporterBuilder { + + private static String lastFileName = ""; + + @Override + public final FileImporter buildImporter() { + return new SemanticWebImporter(); + } + + @Override + public final FileType[] getFileTypes() { + return new FileType[]{ + new FileType(".rdf", "RDF files"), + new FileType(".rdfs", "RDFS files") + }; + } + + @Override + public final boolean isMatchingImporter(final org.openide.filesystems.FileObject fileObject) { + boolean result = (fileObject.getExt().equalsIgnoreCase("rdf") || fileObject.getExt().equalsIgnoreCase("rdfs")); + if (result) { + setLastFileName(fileObject.getPath()); + } + return result; + } + + @Override + public final String getName() { + return "SemanticWebImportBuilder"; + } + + /** + * @return the lastFileName + */ + public static String getLastFileName() { + return lastFileName; + } + + /** + * @param lastFileName the lastFileName to set + */ + private static void setLastFileName(String lastFileName) { + SemanticWebImportBuilder.lastFileName = lastFileName; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImportParser.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImportParser.java new file mode 100644 index 0000000000..3d35c93474 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImportParser.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.importer; + +import fr.inria.edelweiss.semantic.LayoutExampleAbstractPostProcessor; +import org.gephi.graph.api.Graph; +import org.gephi.graph.api.GraphController; +import org.gephi.graph.api.GraphModel; +import org.gephi.graph.api.Table; +import org.gephi.project.api.ProjectController; +import org.gephi.project.api.Workspace; +import org.gephi.utils.longtask.api.LongTaskErrorHandler; +import org.gephi.utils.longtask.api.LongTaskExecutor; +import org.gephi.utils.longtask.api.LongTaskListener; +import org.gephi.utils.longtask.spi.LongTask; +import org.openide.util.Lookup; + +import java.util.Properties; +import java.util.concurrent.Semaphore; +import java.util.logging.Level; +import java.util.logging.Logger; + +import fr.inria.edelweiss.semantic.PluginProperties; +import fr.inria.edelweiss.semantic.analyzer.RdfAnalyzer; +import fr.inria.edelweiss.sparql.GephiUtils; +import fr.inria.edelweiss.sparql.SparqlDriver; + + +/** + * Responsible for making the request and building the resulting graph + * asynchronously. The purpose of this class is to:
  1. use a SPARQL driver + * to obtain a RDF/XML result;
  2. populate the graph by extracting in the + * result the nodes and the edges.
+ * + * @author Erwan Demairy + */ +public class SemanticWebImportParser implements LongTaskListener { + + private static final Logger logger = Logger.getLogger(SemanticWebImportParser.class.getName()); + private final Semaphore waitEndPopulate = new Semaphore(0); + LongTaskExecutor executor = new LongTaskExecutor(true); + private ProjectController pc; + private Graph rdfGraph; + private RequestParameters parameters; + private RdfAnalyzer analyzer; + private SparqlDriver driver; + private LongTaskListener listener; // listener waiting for the end of the population task. + + public SemanticWebImportParser() { + this(new RequestParameters("")); + } + + public SemanticWebImportParser(RequestParameters requests) { + this.parameters = requests; + } + + /** + * Asynchronous operation that fills the current workspace. + * + * @param driverUsed SPARQL request driver. + * @param properties Parameters to use. + * @sa waitEndpopulateRDFGraph + */ + public final void populateRDFGraph(SparqlDriver driverUsed, Properties properties, LongTaskListener listener) { + this.listener = listener; + boolean resetWorkspace = Boolean.parseBoolean(properties.getProperty(PluginProperties.RESET_WORKSPACE.getValue(), "false")); + boolean postProcessing = Boolean.parseBoolean(properties.getProperty(PluginProperties.POST_PROCESSING.getValue(), "false")); + String saveResultName = properties.getProperty(PluginProperties.SAVE_SPARQL_RESULT.getValue(), ""); + int fynLevel = Integer.parseInt(properties.getProperty(PluginProperties.FYN_LEVEL.getValue(), "0")); + + logger.log(Level.INFO, "resetWorkspace = {0}", resetWorkspace); + logger.log(Level.INFO, "postProcessing = {0}", postProcessing); + + this.driver = driverUsed; + this.driver.setPluginProperties(properties); + + GephiUtils.createProjectIfEmpty(); + GephiUtils.createWorkspaceIfEmpty(); + + pc = Lookup.getDefault().lookup(ProjectController.class); + Workspace dataWorkspace = pc.getCurrentWorkspace(); + GraphModel model = getCurrentGraphModel(dataWorkspace); + // @TODO how to reset the graph + if (resetWorkspace) { + if (model != null) { + model.getGraph().clear(); + logger.log(Level.INFO, "workspace reset done"); + } + } + Table nodeTable = model.getNodeTable(); + if (!nodeTable.hasColumn("namespace")) { + nodeTable.addColumn("namespace", String.class); + } + + analyzer = initAnalyzer(model, parameters.getRdfRequest(), fynLevel); + analyzer.setSaveResult(saveResultName); + if (postProcessing) { + LayoutExampleAbstractPostProcessor postProcessor = new LayoutExampleAbstractPostProcessor(); + analyzer.setPostProcessing(postProcessor); + } + executor.setLongTaskListener(this); + executor.execute(analyzer, analyzer, "Importing Semantic Graph", new LongTaskErrorHandler() { + @Override + public void fatalError(Throwable thrwbl) { + thrwbl.printStackTrace(); + } + }); + + } + + @Override + public void taskFinished(LongTask lt) { + if (waitEndPopulate.availablePermits() < 1) { + waitEndPopulate.release(); + } + listener.taskFinished(lt); + } + + public final void waitEndpopulateRDFGraph() throws InterruptedException { + waitEndPopulate.acquire(); + } + + private RdfAnalyzer initAnalyzer(GraphModel model, String rdfRequest, int fynLevel) { + driver.init(); + RdfAnalyzer localAnalyzer = new RdfAnalyzer(model, rdfRequest, fynLevel); + localAnalyzer.setSparqlEngine(driver); + return localAnalyzer; + } + + public RequestParameters getParameters() { + return parameters; + } + + public void setParameters(RequestParameters newParameters) { + this.parameters = newParameters; + } + + private GraphModel getCurrentGraphModel(final Workspace currentWorkspace) { + final GraphController currentGraphController = Lookup.getDefault().lookup(GraphController.class); + return currentGraphController.getGraphModel(currentWorkspace); + } + + /** + * @return the rdfGraph + */ + public Graph getRdfGraph() { + return this.rdfGraph; + } + + public String getLastRdfResult() { + return analyzer.getSparqlRequestResult(); + } + + static public class RequestParameters { + + private String rdfRequest; + + public RequestParameters(String rdfRequest) { + setRdfRequest(rdfRequest); + } + + public String getRdfRequest() { + return this.rdfRequest; + } + + public final void setRdfRequest(String nodeRdfRequest) { + this.rdfRequest = nodeRdfRequest; + } + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImporter.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImporter.java new file mode 100644 index 0000000000..65a751cb03 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImporter.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.importer; + +import fr.inria.edelweiss.sparql.corese.CoreseDriver; +import java.io.Reader; +import java.util.List; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.gephi.graph.api.Edge; +import org.gephi.graph.api.GraphController; +import org.gephi.graph.api.GraphModel; +import org.gephi.graph.api.Node; +import org.gephi.io.importer.api.ContainerLoader; +import org.gephi.io.importer.api.EdgeDraft; +import org.gephi.io.importer.api.ElementDraft.Factory; +import org.gephi.io.importer.api.NodeDraft; +import org.gephi.io.importer.api.Report; +import org.gephi.io.importer.spi.FileImporter; +import org.gephi.project.api.ProjectController; +import org.gephi.project.api.Workspace; +import org.gephi.utils.longtask.spi.LongTask; +import org.gephi.utils.progress.ProgressTicket; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; + +/** + * Where the import job is done. + *
    + *
  • receive a Reader to obtain the data to import, \sa setReader; + *
  • returns a container, \sa getContainer; + *
  • update a progress bar, \sa setProgressTicket; + *
  • fill a log file, \sa getReport. + *
+ * @author edemairy + */ +public class SemanticWebImporter implements FileImporter, LongTask { + + private static final Logger LOGGER = Logger.getLogger(SemanticWebImporter.class.getName()); + private Reader reader; + private ContainerLoader container; + private Report report; + private ProgressTicket progressTicket; + private boolean cancel = false; + private String sparqlRequest; + private SemanticWebImportParser rdfParser; + private final CoreseDriver sparqlDriver; + + public SemanticWebImporter() { + sparqlDriver = new CoreseDriver(); + } + + @Override + public final boolean execute(final ContainerLoader loader) { + this.container = loader; + this.report = new Report(); + + progressTicket.setDisplayName("SemanticWebImporter"); + progressTicket.start(); + + LOGGER.info("Beginning the import"); + final SemanticWebImportParser.RequestParameters requestParameters = + new SemanticWebImportParser.RequestParameters(getSparqlRequest()); + rdfParser = new SemanticWebImportParser(requestParameters); + + LOGGER.info("Starting the RDF importer for Gephi"); + + rdfParser.populateRDFGraph(sparqlDriver, new Properties(), new NullLongTaskListener()); + try { + rdfParser.waitEndpopulateRDFGraph(); + } catch (InterruptedException ex) { + Exceptions.printStackTrace(ex); + LOGGER.log(Level.WARNING, "Interrupted!", ex); + Thread.currentThread().interrupt(); + } + LOGGER.info("Finished the import"); + + ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); + Workspace dataWorkspace = pc.getCurrentWorkspace(); + GraphController currentGraphController = Lookup.getDefault().lookup(GraphController.class); + GraphModel model = currentGraphController.getGraphModel(dataWorkspace); + + Factory draftFactory = container.factory(); + for (Node currentNode : model.getGraph().getNodes()) { + String nodeDraftLabel = currentNode.getLabel(); + NodeDraft nodeDraft = draftFactory.newNodeDraft(nodeDraftLabel); + nodeDraft.setLabel(nodeDraftLabel); + LOGGER.log(Level.INFO, "Adding new node: {0}", nodeDraftLabel); + loader.addNode(nodeDraft); + } + + for (Edge currentEdge: model.getGraph().getEdges()) { + EdgeDraft edgeDraft = draftFactory.newEdgeDraft(); + edgeDraft.setLabel(currentEdge.getLabel()); + + String nodeDraftSourceLabel = currentEdge.getSource().getLabel(); + NodeDraft nodeDraftSource = loader.getNode(nodeDraftSourceLabel); + + String nodeDraftTargetLabel = currentEdge.getTarget().getLabel(); + NodeDraft nodeDraftTarget = loader.getNode(nodeDraftTargetLabel); + + edgeDraft.setSource(nodeDraftSource); + edgeDraft.setTarget(nodeDraftTarget); + LOGGER.log(Level.INFO, "Adding edge from {0} to {1}", new Object[]{nodeDraftSourceLabel, nodeDraftTargetLabel}); + loader.addEdge(edgeDraft); + } + + progressTicket.finish(); + return !cancel; + } + + @Override + public final ContainerLoader getContainer() { + return container; + } + + @Override + public final Report getReport() { + return report; + } + + @Override + public final boolean cancel() { + cancel = true; + return true; + } + + @Override + public final void setProgressTicket(final ProgressTicket newProgressTicket) { + this.progressTicket = newProgressTicket; + } + + @Override + public final void setReader(Reader reader) { + this.reader = reader; + } + + public final String getSparqlRequest() { + return sparqlRequest; + } + + public final void setSparqlRequest(final String newSparqlRequest) { + this.sparqlRequest = newSparqlRequest; + } + + public final CoreseDriver getDriver() { + return sparqlDriver; + } + + void setResources(List resourceList) { + sparqlDriver.getParameters().addResources( resourceList.toArray(new String[]{}) ); + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImporterPanel.form b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImporterPanel.form new file mode 100644 index 0000000000..4f9161c45c --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImporterPanel.form @@ -0,0 +1,81 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImporterPanel.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImporterPanel.java new file mode 100644 index 0000000000..50cd4ee841 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImporterPanel.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +package fr.inria.edelweiss.semantic.importer; + +import fr.inria.edelweiss.sparql.corese.CoreseDriver; + +import java.util.List; + +/** + * + * @author edemairy + */ + + +public class SemanticWebImporterPanel extends javax.swing.JPanel { + private static final long serialVersionUID = -5564063032941454007L; + private CoreseDriver driver; + + /** Creates new form SemanticWebImporterPanel */ + public SemanticWebImporterPanel() { + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jPanel1 = new javax.swing.JPanel(); + jSplitPane1 = new javax.swing.JSplitPane(); + sparqlQueryEditor = new fr.inria.corese.gui.query.SparqlQueryEditor(); + coreseDriverParametersPanel = new fr.inria.edelweiss.sparql.corese.CoreseDriverParametersPanel(); + + jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); + jSplitPane1.setRightComponent(sparqlQueryEditor); + jSplitPane1.setLeftComponent(coreseDriverParametersPanel); + + var jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 468, Short.MAX_VALUE)) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + // Variables declaration - do not modify//GEN-BEGIN:variables + private fr.inria.edelweiss.sparql.corese.CoreseDriverParametersPanel coreseDriverParametersPanel; + private javax.swing.JPanel jPanel1; + private javax.swing.JSplitPane jSplitPane1; + private fr.inria.corese.gui.query.SparqlQueryEditor sparqlQueryEditor; + // End of variables declaration//GEN-END:variables + + public void addResource(String lastFileName) { + coreseDriverParametersPanel.addResource(lastFileName); + } + + public void setSparqlRequest(final String request) { + sparqlQueryEditor.setQueryText(request); + } + + String getSparqlRequest() { + return ""; //sparqlQueryEditor.getQueryText(); + } + + public List getResourceList() { + return coreseDriverParametersPanel.getResourceList(); + } + + void setDriver(CoreseDriver driver) { + this.driver = driver; + coreseDriverParametersPanel.setParameters(driver.getParameters()); + } + +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImporterUI.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImporterUI.java new file mode 100644 index 0000000000..18b091d38d --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/importer/SemanticWebImporterUI.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +package fr.inria.edelweiss.semantic.importer; + +import fr.inria.edelweiss.sparql.corese.CoreseDriver; +import javax.swing.JPanel; +import org.gephi.io.importer.spi.Importer; +import org.gephi.io.importer.spi.ImporterUI; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author edemairy + */ +@ServiceProvider(service = ImporterUI.class) +public class SemanticWebImporterUI implements ImporterUI { + + private SemanticWebImporterPanel panel; + private SemanticWebImporter importer; + private CoreseDriver driver; + + @Override + public void setup(Importer[] importers) { + this.importer = (SemanticWebImporter) importers[0]; + } + + @Override + public JPanel getPanel() { + driver = new CoreseDriver(); + panel = new SemanticWebImporterPanel(); + panel.setDriver(driver); + panel.addResource(SemanticWebImportBuilder.getLastFileName()); + panel.setSparqlRequest("construct \n{?x ?r ?y } \nwhere\n{?x ?r ?y}"); + return panel; + } + + /* + * Called when the user press ok. + */ + @Override + public void unsetup(boolean bln) { + importer.setResources(panel.getResourceList()); + importer.setSparqlRequest(panel.getSparqlRequest()); + } + + @Override + public String getDisplayName() { + return "SemanticWebImporter"; + } + + @Override + public boolean isUIForImporter(Importer importer) { + return importer instanceof SemanticWebImporter; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatistics.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatistics.java new file mode 100644 index 0000000000..40e2129b45 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatistics.java @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.statistics; + +import fr.com.hp.hpl.jena.rdf.arp.MalformedURIException; +import fr.com.hp.hpl.jena.rdf.arp.URI; +import fr.inria.edelweiss.semantic.SemanticWebImportMainWindowTopComponent; +import fr.inria.edelweiss.semantic.statistics.gui.JTreeTable; +import fr.inria.edelweiss.semantic.statistics.gui.TypeTreeModel; +import fr.inria.edelweiss.semantic.statistics.gui.TypeTreeNode; +import fr.inria.edelweiss.sparql.SparqlRequester; +import org.gephi.graph.api.GraphModel; +import org.gephi.statistics.spi.Statistics; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.tree.TreeNode; +import java.awt.BorderLayout; +import java.awt.HeadlessException; +import java.io.IOException; +import java.util.Comparator; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * @author edemairy + */ +public class SemanticWebStatistics implements Statistics { + + public static final String GET_SUBCLASSES = "select ?x ?t where { ?x rdfs:subClassOf ?t } group by ?x"; + public static final String COUNT_TYPES = "select ?t (count(?x) as ?total) where { ?x rdf:type ?t } group by ?t"; + public static final String DRIVER_TYPE = "fr.inria.edelweiss.sparql.corese.CoreseDriver"; + private static final Logger logger = Logger.getLogger(SemanticWebStatistics.class.getName()); + private final StringBuilder summary = new StringBuilder(); + private final StringBuilder report = new StringBuilder(); + + /* + * Turn the exception mechanism in a boolean function. + */ + static protected boolean isURILegal(final String uri) { + try { + URI newUri = new URI(uri); + } catch (NullPointerException e) { + return false; + } catch (MalformedURIException e) { + return false; + } + return true; + } + + /** + * Computes the statistics. The resulting report can be obtained from the {@link Statistics#getReport() getReport} method. + * + * @param gm The input. + */ + @Override + public void execute(GraphModel gm) { + try { + SparqlRequester sparqlRequester = SemanticWebImportMainWindowTopComponent.getSparqlRequester(); + Map countTypes = countTypes(sparqlRequester.selectOnGraph(COUNT_TYPES)); + TypeTreeModel typeModel = buildTreeModel(sparqlRequester.selectOnGraph(GET_SUBCLASSES)); + updateModelCount(typeModel, countTypes); + displayTypeTree(typeModel); + summary.append(countTypes.size()).append(" types found"); + report.append("

").append(countTypes.size()).append(" types were found :

"); + for (String key : countTypes.keySet()) { + report.append("

").append(key).append(": found ").append(countTypes.get(key)).append(" times

"); + } + } catch (HeadlessException ex) { + report.append("An exception occurred: ").append(ex.getMessage()); + } + } + + @Override + public String getReport() { + return report.toString(); + } + + public String getSummary() { + return summary.toString(); + } + + /** + * Display the model in a JTreeTable. + * + * @param typeModel to display. + */ + protected void displayTypeTree(TypeTreeModel typeModel) { + JPanel frame = new JPanel(new BorderLayout()); + JTreeTable treeTable = new JTreeTable(typeModel); + frame.add(new JScrollPane(treeTable), BorderLayout.CENTER); + try { + SemanticWebImportMainWindowTopComponent.getDefault().addTab("Tree Type", frame); + } catch (IOException ex) { + logger.log(Level.SEVERE, "An exception occurred when attempting to display the type tree: ", ex.getMessage()); + } + } + + /** + * Convert the result returned by a select counting the types into a + * map. + * + * @param selectOnGraph Result obtained with a select request. The first + * column must contain the name of the type, the second column must + * contain the number of occurrences found for this type. + * @return The counted types. + */ + protected Map countTypes(String[][] selectOnGraph) { + HashMap result = new HashMap(); + for (int i = 0; i < selectOnGraph.length; ++i) { + String name = selectOnGraph[i][0]; + Integer count = Integer.parseInt(selectOnGraph[i][1]); + result.put(name, count); + } + return result; + } + + /** + * Register for each node who are its fathers and children. Note that a + * node can have several children and/or father. + * + * @param selectOnGraph + * @return + */ + protected TypeTreeModel buildTreeModel(String[][] selectOnGraph) { + TypeTreeNode root = new TypeTreeNode("Root", 0, 0); + TypeTreeModel result = new TypeTreeModel(root); + HashMap builtNodes = new HashMap(); + + for (int i = 0; i < selectOnGraph.length; ++i) { + String childTypeName = selectOnGraph[i][0]; + String fatherTypeName = selectOnGraph[i][1]; + TypeTreeNode fatherNode; + if (builtNodes.containsKey(fatherTypeName)) { + fatherNode = builtNodes.get(fatherTypeName); + } else { + fatherNode = new TypeTreeNode(fatherTypeName, 0, 0); + builtNodes.put(fatherTypeName, fatherNode); + } + TypeTreeNode childNode; + if (builtNodes.containsKey(childTypeName)) { + childNode = builtNodes.get(childTypeName); + } else { + childNode = new TypeTreeNode(childTypeName, 0, 0); + builtNodes.put(childTypeName, childNode); + } + fatherNode.add(childNode); + } + for (String nodeName : builtNodes.keySet()) { + TypeTreeNode currentNode = builtNodes.get(nodeName); + if (!currentNode.hasFather()) { + result.getRoot().add(currentNode); + } + } + return result; + } + + /** + * Add the count for each node of typeModel, and add nodes if they are + * present in countTypes, but not in typeModel. It can happen that a + * type is known with rdf:type (used to obtain countTypes), but that + * there is no known rdfs:subClassOf relationship with it (letting the + * typeModel unaware of this type). + * + * @param typeModel + * @param countTypes + */ + protected void updateModelCount(TypeTreeModel typeModel, final Map countTypes) { + var seenTypes = new HashSet(); + int total = 0; + for (Integer count : countTypes.values()) { + total += count; + } + if (total == 0) { + throw new IllegalArgumentException("total count must not be 0."); + } + + TypeTreeNode node = typeModel.getRoot(); + var queue = new LinkedList(); + queue.add(node); + while (!queue.isEmpty()) { + TypeTreeNode currentNode = queue.pollLast(); + String nodeName = currentNode.getName(); + int countType = (countTypes.get(nodeName) != null) ? countTypes.get(nodeName) : 0; + currentNode.setNumber(countType); + currentNode.setPercentage(100.0 * countType / total); + seenTypes.add(nodeName); + + Enumeration childs = currentNode.children(); + while (childs.hasMoreElements()) { + queue.addFirst((TypeTreeNode) childs.nextElement()); + } + } + Set unseenTypes = countTypes.keySet(); + unseenTypes.removeAll(seenTypes); + for (String unseenType : unseenTypes) { + typeModel.getRoot().add(new TypeTreeNode(unseenType, countTypes.get(unseenType), 100.0 * countTypes.get(unseenType) / total)); + } + } +} + +/** + * Compares by ascending count of successors, then by alphabetical order if + * there is counts are equal. + * + * @author Erwan Demairy + */ +class SuccessorComparator implements Comparator { + + private Map> successors; + + public SuccessorComparator(Map> successors) { + this.successors = successors; + } + + @Override + public int compare(String o1, String o2) { + + if (successors.get(o1).size() < successors.get(o2).size()) { + return -1; + } else if (successors.get(o1).size() > successors.get(o2).size()) { + return 1; + } else { + return o1.compareTo(o2); + } + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatisticsBuilder.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatisticsBuilder.java new file mode 100644 index 0000000000..be88e7c53d --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatisticsBuilder.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.statistics; + +import org.gephi.statistics.spi.Statistics; +import org.gephi.statistics.spi.StatisticsBuilder; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author edemairy + */ + +@ServiceProvider(service=StatisticsBuilder.class) +public class SemanticWebStatisticsBuilder implements StatisticsBuilder { + + private SemanticWebStatistics statistics; + + @Override + public String getName() { + return SemanticWebStatisticsBuilder.class.getSimpleName(); + } + + @Override + public Statistics getStatistics() { + this.statistics = new SemanticWebStatistics(); + return statistics; + } + + @Override + public Class getStatisticsClass() { + return SemanticWebStatistics.class; + } + +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatisticsPanel.form b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatisticsPanel.form new file mode 100644 index 0000000000..b7a90e2fab --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatisticsPanel.form @@ -0,0 +1,31 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatisticsPanel.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatisticsPanel.java new file mode 100644 index 0000000000..2c023d196b --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatisticsPanel.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +/* + * SemanticWebStatisticsPanel.java + * + * Created on Dec 13, 2011, 4:14:31 PM + */ +package fr.inria.edelweiss.semantic.statistics; + +import org.gephi.statistics.spi.Statistics; + +/** + * + * @author edemairy + */ +public class SemanticWebStatisticsPanel extends javax.swing.JPanel { + private static final long serialVersionUID = 191053265603936122L; + private Statistics statistics; + + /** Creates new form SemanticWebStatisticsPanel */ + public SemanticWebStatisticsPanel() { + initComponents(); + } + + SemanticWebStatisticsPanel(Statistics statistics) { + this.statistics = statistics; + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + + setLayout(new java.awt.BorderLayout()); + + jLabel1.setText(org.openide.util.NbBundle.getMessage(SemanticWebStatisticsPanel.class, "SemanticWebStatisticsPanel.jLabel1.text")); // NOI18N + add(jLabel1, java.awt.BorderLayout.CENTER); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel jLabel1; + // End of variables declaration//GEN-END:variables +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatisticsUI.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatisticsUI.java new file mode 100644 index 0000000000..698eefe9d2 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/SemanticWebStatisticsUI.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.statistics; + +import javax.swing.JPanel; +import org.gephi.statistics.spi.Statistics; +import org.gephi.statistics.spi.StatisticsUI; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author edemairy + */ +@ServiceProvider(service=StatisticsUI.class) +public class SemanticWebStatisticsUI implements StatisticsUI{ + private final String DISPLAY_NAME = "SW Type Statistics"; + private final int POSITION = 666; + private SemanticWebStatistics statistics; + + public JPanel getSettingsPanel() { + return new SemanticWebStatisticsPanel(statistics); + } + + public void setup(Statistics ststcs) { + statistics = (SemanticWebStatistics) ststcs; + } + + public void unsetup() { + statistics = null; + } + + public Class getStatisticsClass() { + return SemanticWebStatistics.class; + } + + public String getValue() { + return statistics.getSummary(); + } + + public String getDisplayName() { + return DISPLAY_NAME; + } + + public String getCategory() { + return CATEGORY_NODE_OVERVIEW; + } + + public int getPosition() { + return POSITION; + } + + @Override + public String getShortDescription() { + return "Compute the number of types and relationships in the current dataset."; + } + +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/AbstractCellEditor.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/AbstractCellEditor.java new file mode 100644 index 0000000000..14ba94b83e --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/AbstractCellEditor.java @@ -0,0 +1,111 @@ +package fr.inria.edelweiss.semantic.statistics.gui; + +/* + * %W% %E% + * + * Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY + * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR + * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR + * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE + * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, + * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER + * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF + * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS + * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + */ + +import java.util.EventObject; +import javax.swing.CellEditor; +import javax.swing.event.CellEditorListener; +import javax.swing.event.ChangeEvent; +import javax.swing.event.EventListenerList; + +/** + * @version %I% %G% + * + * A base class for CellEditors, providing default implementations for all + * methods in the CellEditor interface and support for managing a series + * of listeners. + * + * @author Philip Milne + */ + +public class AbstractCellEditor implements CellEditor { + + protected EventListenerList listenerList = new EventListenerList(); + + public Object getCellEditorValue() { return null; } + public boolean isCellEditable(EventObject e) { return true; } + public boolean shouldSelectCell(EventObject anEvent) { return false; } + public boolean stopCellEditing() { return true; } + public void cancelCellEditing() {} + + public void addCellEditorListener(CellEditorListener l) { + listenerList.add(CellEditorListener.class, l); + } + + public void removeCellEditorListener(CellEditorListener l) { + listenerList.remove(CellEditorListener.class, l); + } + + /** + * Notify all listeners that have registered interest for + * notification on this event type. + * @see EventListenerList + */ + protected void fireEditingStopped() { + // Guaranteed to return a non-null array + Object[] listeners = listenerList.getListenerList(); + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length-2; i>=0; i-=2) { + if (listeners[i]==CellEditorListener.class) { + ((CellEditorListener)listeners[i+1]).editingStopped(new ChangeEvent(this)); + } + } + } + + /** + * Notify all listeners that have registered interest for + * notification on this event type. + * @see EventListenerList + */ + protected void fireEditingCanceled() { + // Guaranteed to return a non-null array + Object[] listeners = listenerList.getListenerList(); + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length-2; i>=0; i-=2) { + if (listeners[i]==CellEditorListener.class) { + ((CellEditorListener)listeners[i+1]).editingCanceled(new ChangeEvent(this)); + } + } + } +} + diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/AbstractTreeTableModel.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/AbstractTreeTableModel.java new file mode 100644 index 0000000000..0bcfeb2301 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/AbstractTreeTableModel.java @@ -0,0 +1,234 @@ +/* + * + * Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY + * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR + * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR + * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE + * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, + * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER + * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF + * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS + * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + */ +package fr.inria.edelweiss.semantic.statistics.gui; + +import javax.swing.event.EventListenerList; +import javax.swing.event.TreeModelEvent; +import javax.swing.event.TreeModelListener; +import javax.swing.tree.TreePath; + + +/** + * An abstract implementation of the TreeTableModel interface, handling + * the list of listeners. + * + * @author Philip Milne + * @version %I% %G% + */ + +public abstract class AbstractTreeTableModel implements TreeTableModel { + protected Object root; + protected EventListenerList listenerList = new EventListenerList(); + + protected AbstractTreeTableModel(Object root) { + this.root = root; + } + + // + // Default implmentations for methods in the TreeModel interface. + // + + public Object getRoot() { + return root; + } + + public boolean isLeaf(Object node) { + return getChildCount(node) == 0; + } + + public void valueForPathChanged(TreePath path, Object newValue) { + } + + // This is not called in the JTree's default mode: use a naive implementation. + public int getIndexOfChild(Object parent, Object child) { + for (int i = 0; i < getChildCount(parent); i++) { + if (getChild(parent, i).equals(child)) { + return i; + } + } + return -1; + } + + public void addTreeModelListener(TreeModelListener l) { + listenerList.add(TreeModelListener.class, l); + } + + public void removeTreeModelListener(TreeModelListener l) { + listenerList.remove(TreeModelListener.class, l); + } + + /* + * Notify all listeners that have registered interest for + * notification on this event type. The event instance + * is lazily created using the parameters passed into + * the fire method. + * @see EventListenerList + */ + protected void fireTreeNodesChanged(Object source, Object[] path, + int[] childIndices, + Object[] children) { + // Guaranteed to return a non-null array + Object[] listeners = listenerList.getListenerList(); + TreeModelEvent e = null; + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == TreeModelListener.class) { + // Lazily create the event: + if (e == null) { + e = new TreeModelEvent(source, path, + childIndices, children); + } + ((TreeModelListener) listeners[i + 1]).treeNodesChanged(e); + } + } + } + + /* + * Notify all listeners that have registered interest for + * notification on this event type. The event instance + * is lazily created using the parameters passed into + * the fire method. + * @see EventListenerList + */ + protected void fireTreeNodesInserted(Object source, Object[] path, + int[] childIndices, + Object[] children) { + // Guaranteed to return a non-null array + Object[] listeners = listenerList.getListenerList(); + TreeModelEvent e = null; + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == TreeModelListener.class) { + // Lazily create the event: + if (e == null) { + e = new TreeModelEvent(source, path, + childIndices, children); + } + ((TreeModelListener) listeners[i + 1]).treeNodesInserted(e); + } + } + } + + /* + * Notify all listeners that have registered interest for + * notification on this event type. The event instance + * is lazily created using the parameters passed into + * the fire method. + * @see EventListenerList + */ + protected void fireTreeNodesRemoved(Object source, Object[] path, + int[] childIndices, + Object[] children) { + // Guaranteed to return a non-null array + Object[] listeners = listenerList.getListenerList(); + TreeModelEvent e = null; + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == TreeModelListener.class) { + // Lazily create the event: + if (e == null) + e = new TreeModelEvent(source, path, + childIndices, children); + ((TreeModelListener) listeners[i + 1]).treeNodesRemoved(e); + } + } + } + + /* + * Notify all listeners that have registered interest for + * notification on this event type. The event instance + * is lazily created using the parameters passed into + * the fire method. + * @see EventListenerList + */ + protected void fireTreeStructureChanged(Object source, Object[] path, + int[] childIndices, + Object[] children) { + // Guaranteed to return a non-null array + Object[] listeners = listenerList.getListenerList(); + TreeModelEvent e = null; + // Process the listeners last to first, notifying + // those that are interested in this event + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == TreeModelListener.class) { + // Lazily create the event: + if (e == null) + e = new TreeModelEvent(source, path, + childIndices, children); + ((TreeModelListener) listeners[i + 1]).treeStructureChanged(e); + } + } + } + + // + // Default impelmentations for methods in the TreeTableModel interface. + // + + public Class getColumnClass(int column) { + return Object.class; + } + + /** + * By default, make the column with the Tree in it the only editable one. + * Making this column editable causes the JTable to forward mouse + * and keyboard events in the Tree column to the underlying JTree. + */ + public boolean isCellEditable(Object node, int column) { + return getColumnClass(column) == TreeTableModel.class; + } + + public void setValueAt(Object aValue, Object node, int column) { + } + + + // Left to be implemented in the subclass: + + /* + * public Object getChild(Object parent, int index) + * public int getChildCount(Object parent) + * public int getColumnCount() + * public String getColumnName(Object node, int column) + * public Object getValueAt(Object node, int column) + */ + +} + diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/JTreeTable.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/JTreeTable.java new file mode 100644 index 0000000000..eae19f2c9f --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/JTreeTable.java @@ -0,0 +1,155 @@ +/* + * %W% %E% + * + * Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY + * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR + * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR + * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE + * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, + * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER + * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF + * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS + * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + */ +package fr.inria.edelweiss.semantic.statistics.gui; + +import javax.swing.*; +import java.awt.Dimension; +import java.awt.Component; +import java.awt.Graphics; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import javax.swing.tree.DefaultTreeSelectionModel; +import javax.swing.tree.TreeModel; + +/** + * This example shows how to create a simple JTreeTable component, + * by using a JTree as a renderer (and editor) for the cells in a + * particular column in the JTable. + * + * @version %I% %G% + * + * @author Philip Milne + * @author Scott Violet + */ +public class JTreeTable extends JTable { + + private static final long serialVersionUID = 4435181815819049703L; + protected TreeTableCellRenderer tree; + + public JTreeTable(TreeTableModel treeTableModel) { + super(); + + // Create the tree. It will be used as a renderer and editor. + tree = new TreeTableCellRenderer(treeTableModel); + + // Install a tableModel representing the visible rows in the tree. + super.setModel( + new TreeTableModelAdapter(treeTableModel, tree)); + + // Force the JTable and JTree to share their row selection models. + var selectionModel = new DefaultTreeSelectionModel(); + tree.setSelectionModel( selectionModel ); + // Make the tree and table row heights the same. + tree.setRowHeight(getRowHeight()); + + // Install the tree editor renderer and editor. + setDefaultRenderer(TreeTableModel.class, tree); + setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor()); + + setShowGrid(true); + setIntercellSpacing(new Dimension(0, 0)); + + this.setDragEnabled(true); + this.setTransferHandler(new JTreeTableHandler()); + } + + /* Workaround for BasicTableUI anomaly. Make sure the UI never tries to + * paint the editor. The UI currently uses different techniques to + * paint the renderers and editors and overriding setBounds() below + * is not the right thing to do for an editor. Returning -1 for the + * editing row in this case, ensures the editor is never painted. + */ + public int getEditingRow() { + return (getColumnClass(editingColumn) == TreeTableModel.class) ? -1 : editingRow; + } + + // + // The renderer used to display the tree nodes, a JTree. + // + public class TreeTableCellRenderer extends JTree implements TableCellRenderer { + + private static final long serialVersionUID = 1996621516702976415L; + protected int visibleRow; + + public TreeTableCellRenderer(TreeModel model) { + super(model); + } + + public void setBounds(int x, int y, int w, int h) { + super.setBounds(x, 0, w, JTreeTable.this.getHeight()); + } + + public void paint(Graphics g) { + g.translate(0, -visibleRow * getRowHeight()); + super.paint(g); + } + + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, int column) { + if (isSelected) { + setBackground(table.getSelectionBackground()); + } else { + setBackground(table.getBackground()); + } + + visibleRow = row; + return this; + } + } + + // + // The editor used to interact with tree nodes, a JTree. + // + public class TreeTableCellEditor extends AbstractCellEditor implements TableCellEditor { + + public Component getTableCellEditorComponent(JTable table, Object value, + boolean isSelected, int r, int c) { + return tree; + } + } + + public String getCell(int row, int column) { + return getModel().getValueAt(row, column).toString(); + } + +} \ No newline at end of file diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/JTreeTableHandler.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/JTreeTableHandler.java new file mode 100644 index 0000000000..36e1b86897 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/JTreeTableHandler.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.statistics.gui; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; +import javax.swing.JComponent; +import javax.swing.TransferHandler; + +/** + * + * @author Erwan Demairy + */ +class JTreeTableHandler extends TransferHandler { + + private static final long serialVersionUID = 2445967652825693813L; + + public JTreeTableHandler() { + } + + public boolean canImport(TransferHandler.TransferSupport info) { + // Check for String flavor + if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { + return false; + } + return true; + } + + public Transferable createTransferable(JComponent c) { + JTreeTable table = (JTreeTable) c; + int numRow = table.getSelectedRow(); + String cellName = table.getCell(numRow, 0); + return new StringSelection(cellName); + } + + + public int getSourceActions(JComponent c) { + return TransferHandler.COPY_OR_MOVE; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/TreeTableModel.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/TreeTableModel.java new file mode 100644 index 0000000000..3085d0a8e4 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/TreeTableModel.java @@ -0,0 +1,82 @@ +/* + * %W% %E% + * + * Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY + * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR + * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR + * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE + * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, + * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER + * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF + * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS + * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + */ +package fr.inria.edelweiss.semantic.statistics.gui; + +import javax.swing.tree.TreeModel; + +/** + * + * @author edemairy + */ +public interface TreeTableModel extends TreeModel +{ + /** + * Returns the number of available column. + */ + int getColumnCount(); + + /** + * Returns the name for column number column. + */ + String getColumnName(int column); + + /** + * Returns the type for column number column. + */ + Class getColumnClass(int column); + + /** + * Returns the value to be displayed for node node, + * at column number column. + */ + Object getValueAt(Object node, int column); + + /** + * Indicates whether the the value for node node, + * at column number column is editable. + */ + boolean isCellEditable(Object node, int column); + + /** + * Sets the value for node node, + * at column number column. + */ + void setValueAt(Object aValue, Object node, int column); +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/TreeTableModelAdapter.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/TreeTableModelAdapter.java new file mode 100644 index 0000000000..cb212d190f --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/TreeTableModelAdapter.java @@ -0,0 +1,121 @@ +package fr.inria.edelweiss.semantic.statistics.gui; + +import javax.swing.JTree; +import javax.swing.event.TreeExpansionEvent; +import javax.swing.event.TreeExpansionListener; +import javax.swing.table.AbstractTableModel; +import javax.swing.tree.TreePath; + +/** + * %W% %E% + * + * Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY + * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR + * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR + * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE + * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, + * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER + * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF + * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS + * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + */ + + +/** + * This is a wrapper class takes a TreeTableModel and implements + * the table model interface. The implementation is trivial, with + * all of the event dispatching support provided by the superclass: + * the AbstractTableModel. + * + * @version %I% %G% + * + * @author Philip Milne + * @author Scott Violet + */ + + +public class TreeTableModelAdapter extends AbstractTableModel +{ + private static final long serialVersionUID = 3385620292461956860L; + JTree tree; + TreeTableModel treeTableModel; + + public TreeTableModelAdapter(TreeTableModel treeTableModel, JTree tree) { + this.tree = tree; + this.treeTableModel = treeTableModel; + + tree.addTreeExpansionListener(new TreeExpansionListener() { + // Don't use fireTableRowsInserted() here; + // the selection model would get updated twice. + public void treeExpanded(TreeExpansionEvent event) { + fireTableDataChanged(); + } + public void treeCollapsed(TreeExpansionEvent event) { + fireTableDataChanged(); + } + }); + } + + // Wrappers, implementing TableModel interface. + + public int getColumnCount() { + return treeTableModel.getColumnCount(); + } + + public String getColumnName(int column) { + return treeTableModel.getColumnName(column); + } + + public Class getColumnClass(int column) { + return treeTableModel.getColumnClass(column); + } + + public int getRowCount() { + return tree.getRowCount(); + } + + protected Object nodeForRow(int row) { + TreePath treePath = tree.getPathForRow(row); + return treePath.getLastPathComponent(); + } + + public Object getValueAt(int row, int column) { + return treeTableModel.getValueAt(nodeForRow(row), column); + } + + public boolean isCellEditable(int row, int column) { + return treeTableModel.isCellEditable(nodeForRow(row), column); + } + + public void setValueAt(Object value, int row, int column) { + treeTableModel.setValueAt(value, nodeForRow(row), column); + } +} + + diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/TypeTreeModel.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/TypeTreeModel.java new file mode 100644 index 0000000000..d23ab925ec --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/TypeTreeModel.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.statistics.gui; + +import java.util.*; + +/** + * + * @author edemairy + */ +public class TypeTreeModel extends AbstractTreeTableModel implements TreeTableModel { + // Names of the columns. + + static protected String[] columnNames = {"Name", "Number", "Percentage"}; + // Types of the columns. + static protected Class[] cTypes = {TreeTableModel.class, Integer.class, Float.class}; + private TypeTreeNode rootNode; +// private Map nodeTable; + + public TypeTreeModel(TypeTreeNode root) { + super(root); +// nodeTable = new TreeMap(); + this.rootNode = root; + } + + // + // Some convenience methods. + // + protected TypeTreeNode[] getChildren(TypeTreeNode node) { + return node.getChildren(); + } + + // + // The TreeModel interface + // + @Override + public int getChildCount(Object node) { + Object[] children = getChildren((TypeTreeNode) node); + return (children == null) ? 0 : children.length; + } + + @Override + public Object getChild(Object node, int i) { + return getChildren((TypeTreeNode) node)[i]; + } + + @Override + public TypeTreeNode getRoot() { + return rootNode; + } + + // The superclass's implementation would work, but this is more efficient. + @Override + public boolean isLeaf(Object node) { + return (getChildCount(node) == 0); + } + + // + // The TreeTableNode interface. + // + @Override + public int getColumnCount() { + return columnNames.length; + } + + @Override + public String getColumnName(int column) { + return columnNames[column]; + } + + @Override + public Class getColumnClass(int column) { + return cTypes[column]; + } + + @Override + public Object getValueAt(Object objectNode, int column) { + TypeTreeNode node = (TypeTreeNode) objectNode; + try { + switch (column) { + case 0: + return node.getName(); + case 1: + return node.getNumber(); + case 2: + return node.getPercentage(); + } + } catch (SecurityException se) { + } + + return null; + } + + public TypeTreeNode findNode(final String name) { + LinkedList queueNodes = new LinkedList(); + queueNodes.add(rootNode); + while (!queueNodes.isEmpty()) { + TypeTreeNode currentNode = queueNodes.removeLast(); + if (currentNode.getName().equals(name)) { + return currentNode; + } else { + for (TypeTreeNode node : currentNode.getChildren()) { + queueNodes.add(node); + } + } + } + return null; + } + + public TypeTreeNode findCreateNode(final String name) { + TypeTreeNode result = findNode(name); + if (result == null) { + result = new TypeTreeNode(name, 0, 0); + } + return result; + } + + public void removeLeaves() { + LinkedList queueNodes = new LinkedList(); + queueNodes.add(getRoot()); + while (!queueNodes.isEmpty()) { + TypeTreeNode currentNode = queueNodes.removeLast(); + TypeTreeNode[] children = currentNode.getChildren(); + for (TypeTreeNode child : children) { + if (child.isLeaf()) { + currentNode.remove(child); + } else { + queueNodes.add(child); + } + } + } + } + +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/TypeTreeNode.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/TypeTreeNode.java new file mode 100644 index 0000000000..86cb048666 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/statistics/gui/TypeTreeNode.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.statistics.gui; + +import java.util.ArrayList; +import java.util.Vector; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.MutableTreeNode; + +/** + * + * This class is a data container for the Tree. + */ +public class TypeTreeNode extends DefaultMutableTreeNode implements Comparable { + + private static final long serialVersionUID = 5927002411753001709L; + private String name; + private int number; + private double percentage; + private ArrayList fathers = new ArrayList(); + + public TypeTreeNode(final String name, final int number, final double percentage) { + this.name = name; + this.number = number; + this.percentage = percentage; + } + + @Override + public void add(MutableTreeNode node) { + if (children == null) { + children = new Vector<>(); + } + children.insertElementAt(node, getChildCount()); + TypeTreeNode typeTreeNode = (TypeTreeNode) node; + typeTreeNode.addFather(this); + } + + /** + * Returns the the string to be used to display this leaf in the JTree. + */ + @Override + public String toString() { + return getName(); + } + + /** + * Loads the children, caching the results in the children var. + */ + protected TypeTreeNode[] getChildren() { + ArrayList result = new ArrayList(); + for (int i = 0; i < getChildCount(); ++i) { + result.add((TypeTreeNode) getChildAt(i)); + } + return result.toArray(new TypeTreeNode[0]); + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @return the number + */ + public int getNumber() { + return number; + } + + /** + * @return the percentage + */ + public double getPercentage() { + return percentage; + } + + @Override + public int compareTo(TypeTreeNode o) { + return getName().compareTo(o.getName()); + } + + public boolean hasFather() { + return (!fathers.isEmpty()); + } + + private void addFather(TypeTreeNode fatherNode) { + fathers.add(fatherNode); + } + + @Override + public void remove(MutableTreeNode aChild) { + TypeTreeNode node = (TypeTreeNode) aChild; + int index = children.indexOf(aChild); + if (index != -1) { + node.removeFather(this); + children.remove(index); + } else { + + } + } + + private void removeFather(TypeTreeNode aThis) { + fathers.remove(aThis); + } + + /** + * @param number the number to set + */ + public void setNumber(int number) { + this.number = number; + } + + /** + * @param percentage the percentage to set + */ + public void setPercentage(double percentage) { + this.percentage = percentage; + } +} \ No newline at end of file diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/tests/Utils.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/tests/Utils.java new file mode 100644 index 0000000000..96b1ab932a --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/tests/Utils.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.tests; + +import fr.inria.edelweiss.semantic.SemanticWebImportMainWindowTopComponent; +import fr.inria.edelweiss.sparql.SparqlRequester; +import java.io.IOException; + +import org.gephi.project.api.Project; +import org.gephi.project.api.ProjectController; +import org.gephi.project.api.Workspace; +import org.gephi.project.api.WorkspaceProvider; +import org.openide.util.Lookup; + +/** + * + * @author Erwan Demairy + */ +public class Utils { + + private SemanticWebImportMainWindowTopComponent topComponent; + private static Workspace workspace; + + public void initGephi() { + ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class); + projectController.newProject(); + workspace = projectController.getCurrentWorkspace(); + } + + /** + * + * @param configurationName Name of a configuration, e.g. "Humans". + * @return + * @throws IOException + * @throws InterruptedException + */ + public Workspace[] whenUsingConfiguration(final String configurationName) throws IOException, InterruptedException { + topComponent = new SemanticWebImportMainWindowTopComponent(); + topComponent.setConfigurationAction(configurationName); + return whenCreatingGraphs(topComponent); + } + + public Workspace[] whenCreatingGraphs(SemanticWebImportMainWindowTopComponent topComponent) throws InterruptedException { + topComponent.startCreateGraphs(); + topComponent.waitCreateGraphs(); + + ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class); + Project project = projectController.getCurrentProject(); + WorkspaceProvider workspaceprovider = project.getLookup().lookup(WorkspaceProvider.class); + return workspaceprovider.getWorkspaces(); + } + + public SparqlRequester getSparqlRequester() { + return (SparqlRequester)topComponent; + } + + public SparqlRequester getDriver() { + return topComponent.getDriver(); + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/utils/FilesUtils.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/utils/FilesUtils.java new file mode 100644 index 0000000000..cb00e592e7 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/utils/FilesUtils.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.utils; + +import java.awt.Component; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JFileChooser; + +/** + * + * @author Erwan Demairy + */ +public class FilesUtils { + + static final private Logger logger = Logger.getLogger(FilesUtils.class.getName()); + + public static Properties readProperties(String fileName) { + InputStream is = readFile(fileName); + + Properties result = new Properties(); + try { + result.loadFromXML(is); + } catch (IOException ex) { + logger.log(Level.SEVERE, "exception occurred when loading the file: {0}", ex.getMessage()); + throw new IllegalArgumentException(ex); + } + return result; + } + + public static InputStream readFile(String fileName) { + try { + return new FileInputStream(fileName); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } + + /** + * Function to open a JFileChooser and set it properly. + * + * @return a File object if one has been chosen. Null otherwise. + */ + public static File selectFile(final int openMode, final String title, final String buttonText, final String lastDirectoryUsed, final Component parent, final String suffix, final String description) { + JFileChooser chooser = new JFileChooser(lastDirectoryUsed); + chooser.setFileHidingEnabled(false); + chooser.setDialogTitle(title); + chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { + @Override + public boolean accept(File pathname) { + if (pathname.isDirectory()) { + return true; + } + return pathname.getName().endsWith(suffix); + } + + @Override + public String getDescription() { + return description; + } + }); + + int returnVal = chooser.showDialog(parent, buttonText); + if (returnVal != JFileChooser.APPROVE_OPTION) { + return null; + } + return chooser.getSelectedFile(); + } + + public static InputStream getResourceOrFile(String fileName) throws IllegalArgumentException { + InputStream result = FilesUtils.class.getResourceAsStream(fileName); + if (result == null) { + try { + result = new FileInputStream(fileName); + } catch (FileNotFoundException ex) { + } + } + if (result == null) { + throw new IllegalArgumentException(fileName + " not found."); + } + return result; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/utils/StopWatch.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/utils/StopWatch.java new file mode 100644 index 0000000000..b79a5a019e --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/semantic/utils/StopWatch.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.semantic.utils; + +/** + * + * @author Erwan Demairy + */ +public class StopWatch { + + private long start; + + public StopWatch() { + start = java.lang.System.currentTimeMillis(); + } + + public long elapsedMillis() { + long end = java.lang.System.currentTimeMillis(); + return end-start; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/DriverParametersPanel.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/DriverParametersPanel.java new file mode 100644 index 0000000000..d644863cf8 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/DriverParametersPanel.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.sparql; + +import java.util.Observer; +import javax.swing.JPanel; + +/** + * + * @author Erwan Demairy + */ +public abstract class DriverParametersPanel

extends JPanel implements Observer { + private static final long serialVersionUID = 1512481963303513796L; + private P parameters; + public P getParameters() { + return parameters; + } + + public void setParameters(final P parameters) { + this.parameters = parameters; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/GephiUtils.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/GephiUtils.java new file mode 100644 index 0000000000..4cc9e82b53 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/GephiUtils.java @@ -0,0 +1,339 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.sparql; + +import org.gephi.graph.api.Edge; +import org.gephi.graph.api.Element; +import org.gephi.graph.api.Graph; +import org.gephi.graph.api.GraphController; +import org.gephi.graph.api.GraphModel; +import org.gephi.graph.api.Node; +import org.gephi.project.api.ProjectController; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; + +import java.awt.Color; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author edemairy + *

+ * Wrapper to help to build a graph in Gephi. + */ +public class GephiUtils { + + public static final String GEPHI_PREFIX = "http://gephi.org"; + public static final String SPARQLID = "sparqlid"; + + public static Graph getCurrentGraph() { + GraphController graphController = Lookup.getDefault().lookup(GraphController.class); + GraphModel model = graphController.getGraphModel(); + return model.getGraph(); + } + + static void createProject() { + ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); + pc.newProject(); + } + + private final Graph graph; + private final GraphModel model; + + public GephiUtils(GraphModel model) { + this.model = model; + graph = model.getDirectedGraph(); + } + + public static void createProjectIfEmpty() { + ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); + if (pc.getCurrentProject() == null) { + pc.newProject(); + } + } + + public static void createWorkspaceIfEmpty() { + ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); + if (pc.getCurrentWorkspace() == null) { + pc.newWorkspace(pc.getCurrentProject()); + } + } + + public static void renameCurrentWorkspace(String newName) { + ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); + pc.renameWorkspace(pc.getCurrentWorkspace(), newName); + } + + public static boolean isBlankNode(String id) { + Pattern junk = Pattern.compile("_.*"); + Matcher matcherJunk = junk.matcher(id); + return matcherJunk.matches(); + } + + public static String decodeString(final String id) { + String decodedName = ""; + decodedName = URLDecoder.decode(id, StandardCharsets.UTF_8); + return decodedName; + } + + public static float convertFloat(final String id) { + float decodedNum = 0; + try { + decodedNum = Float.parseFloat(id.replaceAll("\"", "\\\"")); + } catch (NumberFormatException ex) { + Exceptions.printStackTrace(ex); + } + return decodedNum; + } + + // Get values of color size RGB (0->1) + public static float convertFloatColor(final String id) { + float decodedNum = 0, temp; + try { + temp = Float.parseFloat(id.replaceAll("\"", "\\\"")); + decodedNum = (temp % 256) / 255; + } catch (NumberFormatException ex) { + Exceptions.printStackTrace(ex); + } + return decodedNum; + } + + //Split color values RGB (0,0,0) + public static String[] stringSplit(final String id) { + String delimiter = "\\,"; + String[] stringValues = null; + String temp; + try { + temp = id.replaceAll("\"", "\\\""); + //temp= id.substring(1,id.length()-1); + stringValues = temp.split(delimiter); + } catch (Exception ex) { + Exceptions.printStackTrace(ex); + } + return stringValues; + } + + public void addNode(String id) { + if (!nodeExist(id)) { + Node newNode = model.factory().newNode(); + String decodedName = decodeString(id); + SplittedName splittedName = splitName(decodedName); + + newNode.setLabel(decodedName); + setSparqlId(newNode, decodedName); + newNode.setAttribute("namespace", splittedName.getNamespace()); + + int idNum = (Integer.parseInt((String) newNode.getId())); + + newNode.setX((float) (100 * (idNum / 360.0) * Math.cos(Math.PI * (idNum / 36.0)))); + newNode.setY((float) (100 * (idNum / 360.0) * Math.sin(Math.PI * (idNum / 36.0)))); + newNode.setZ(0); + newNode.setR((float) ((idNum % 16) / 15.0)); + newNode.setG((float) ((idNum >> 8 >> 4) / 15.0)); + newNode.setB((float) ((idNum >> 10 >> 8) / 15.0)); + newNode.setSize(1); + + graph.addNode(newNode); + } + } + + public boolean nodeExist(final String s) { + return (findNode(s) != null); + } + + /** + * @param s + * @return + */ + public Node findNode(final String s) { + String decodedString = decodeString(s); + for (Node n : graph.getNodes().toArray()) { + if (getSparqlId(n).equals(decodedString)) { + return n; + } + } + return null; + } + + public void addEdge(String s0, String edge, String s1) { + // Build the vertices between nodes + + Edge newEdge = model.factory().newEdge(findNode(s0), findNode(s1), 1, true); + newEdge.setLabel(edge); + graph.addEdge(newEdge); + } + + public void setNodeLabel(final String sourceNodeName, final String argumentName) { + findNode(sourceNodeName).setLabel(argumentName); + } + + public void setNodeSize(final String sourceNodeName, final float argumentValue) { + findNode(sourceNodeName).setSize(argumentValue); + } + + public void setNodeColor(final String sourceNodeName, final float r, final float g, final float b) { + findNode(sourceNodeName).setColor(new Color(r, g, b)); + } + + public void setNodeColor_R(final String sourceNodeName, final float r) { + findNode(sourceNodeName).setR(r); + } + + public void setNodeColor_G(final String sourceNodeName, final float g) { + findNode(sourceNodeName).setG(g); + } + + public void setNodeColor_B(final String sourceNodeName, final float b) { + findNode(sourceNodeName).setB(b); + } + + public void setNodeShape(final String sourceNodeName, final String shapeName) { + // @todo find the correct way to access shape of a node. + //findNode (sourceNodeName).setNodeData().setShape(shapeName); + } + + public Object[] getNodeAttributes(final String sourceNodeName) { + var node = findNode(sourceNodeName); + if (node == null) { + addNode(sourceNodeName); + node = findNode(sourceNodeName); + } + return node.getAttributes(); + } + + public static void addAttributeToNodes(final String columnName, Class klass) { + var nodeTable = getCurrentGraph().getModel().getNodeTable(); + if (!nodeTable.hasColumn(columnName)) { + nodeTable.addColumn(columnName, klass); + } + } + + protected static SplittedName splitName(final String fullName) { + String namespace; + if (fullName.contains("#")) { + namespace = fullName.substring(0, fullName.indexOf('#')); + } else if (fullName.contains("/")) { + // Namespace = until the last '/', Id = right part of '/'. + namespace = fullName.substring(0, fullName.lastIndexOf('/')); + } else { + namespace = ""; + } + + return new SplittedName(namespace, shortenName(fullName)); + } + + protected static String shortenName(final String fullName) { + String result; + + if (fullName.isEmpty()) { + result = ""; + } else { + result = removePrefix(fullName); + result = cleanSuffix(result); + } + + return result; + } + + public void removeNode(String id) { + if (nodeExist(id)) { + var node = findNode(id); + model.getGraph().removeNode(node); + } + } + + public void removeEdge(String id) { + if (graph.getEdge(id) != null) { + var edge = graph.getEdge(id); + model.getGraph().removeEdge(edge); + } + } + + public boolean isEdge(String id) { + return (graph.getEdge(id) != null); + } + + public static void addAttributeToEdges(String columnName, Class klass) { + var edgeTable = getCurrentGraph().getModel().getEdgeTable(); + if (!edgeTable.hasColumn(columnName)) { + edgeTable.addColumn(columnName, klass); + } + } + + public Object[] getEdgeAttributes(String id) { + var edge = model.getGraph().getEdge(id); + return edge.getAttributes(); + + } + + public void setEdgeLabel(String sourceLabel, String targetLabel) { + model.getGraph().getEdge(sourceLabel).setLabel(targetLabel); + } + + public static void setSparqlId(Element node, String decodedName) { + node.setAttribute(SPARQLID, decodedName); + } + + public static String getSparqlId(Element node) { + return node.getAttribute(SPARQLID).toString(); + } + + public void setNodeAttr(String sourceLabel, String nameNewAttribute, String targetLabel) { + var n = findNode(sourceLabel); + n.setAttribute(nameNewAttribute, targetLabel); + } + + public void setEdgeAttr(String sourceLabel, String nameNewAttribute, String targetLabel) { + var e = graph.getEdge(sourceLabel); + e.setAttribute(nameNewAttribute, targetLabel); + } + + public static class SplittedName { + + private final String id; + private final String namespace; + + public SplittedName(final String namespace, String id) { + this.namespace = namespace; + this.id = id; + } + + public String getNamespace() { + return this.namespace; + } + + public String getId() { + return this.id; + } + } + + public static String removePrefix(final String name) { + String result = name; + + if (name.contains("#")) { + result = name.replaceAll(".*#", ""); + } + + return result; + } + + public static String cleanSuffix(final String name) { + String result = name; + + if (name.endsWith("/")) { + result = result.substring(0, result.length() - 1); + } + + final int lastPos = result.lastIndexOf("/"); + + if (lastPos != -1) { + result = result.substring(lastPos + 1); + } + + return result; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/RdfParser.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/RdfParser.java new file mode 100644 index 0000000000..55f43bc10c --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/RdfParser.java @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +package fr.inria.edelweiss.sparql; + +import com.hp.hpl.jena.rdf.arp.ALiteral; +import com.hp.hpl.jena.rdf.arp.ARP; +import com.hp.hpl.jena.rdf.arp.AResource; +import com.hp.hpl.jena.rdf.arp.StatementHandler; +import fr.inria.edelweiss.semantic.analyzer.GephiExtension; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.gephi.graph.api.Graph; +import org.gephi.graph.api.GraphModel; +import org.openide.util.Exceptions; +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +/** + * Fill a Gephi graph from the content of an rdf stream. + * + * @author Erwan Demairy + */ +public class RdfParser { + + private static final Logger logger = Logger.getLogger(RdfParser.class.getName()); + private InputStream fileToParse; + private GraphModel modelToFill; + private int tripleNumber; + int depth = 0; + + public RdfParser(final InputStream fileToParse, final GraphModel modelToFill, int depth) { + this.fileToParse = fileToParse; + this.modelToFill = modelToFill; + this.depth = depth; + } + + /** + * @return the resulting graph. + */ + public final Graph parse() { + final ARP arp = new ARP(); + + // initialisation - uses ARPConfig interface only. + arp.getHandlers().setErrorHandler(new ErrorHandler() { + @Override + public void fatalError(final SAXParseException e) { + logger.log(Level.SEVERE, e.getMessage()); + } + + @Override + public void error(final SAXParseException e) { + logger.log(Level.SEVERE, e.getMessage()); + } + + @Override + public void warning(final SAXParseException e) { + logger.log(Level.INFO, e.getMessage()); + } + }); + final ARPParsingHandler statementHandler = new ARPParsingHandler(getModelToFill(), this.getDepth()); + arp.getHandlers().setStatementHandler(statementHandler); + + // parsing. + GephiUtils.addAttributeToNodes(GephiUtils.SPARQLID, String.class); + try { + arp.load(getFileToParse()); + } catch (SAXException ex) { + logger.log(Level.SEVERE, ex.getMessage()); + } catch (IOException ex) { + logger.log(Level.SEVERE, ex.getMessage()); + } + tripleNumber = statementHandler.getTripleNumber(); + return modelToFill.getGraph(); + } + + public InputStream getFileToParse() { + return fileToParse; + } + + public void setFileToParse(final InputStream fileToParse) { + this.fileToParse = fileToParse; + } + + public GraphModel getModelToFill() { + return modelToFill; + } + + public void setModelToFill(final GraphModel modelToFill) { + this.modelToFill = modelToFill; + } + + public int getDepth() { + return this.depth; + } + + public void setDepth(final int depth) { + this.depth = depth; + } + + /** + * @return the tripleNumber + */ + public int getTripleNumber() { + return tripleNumber; + } + + /** + * Class responsible for converting the rdf file in a graph. + */ + public static class ARPParsingHandler implements StatementHandler { + + private GraphModel modelToFill; + final transient private GephiUtils gephiUtils; + private int tripleNumber; + int count; + + public ARPParsingHandler(final GraphModel modelToFill, final int count) { + setModelToFill(modelToFill); + gephiUtils = new GephiUtils(modelToFill); + tripleNumber = 0; + this.count = count; + } + + @Override + public void statement(final AResource nodeSource, final AResource edge, final ALiteral nodeTarget) { + addEdge(nodeSource.toString(), edge.toString(), nodeTarget.toString()); + tripleNumber++; + } + + @Override + public void statement(final AResource nodeSource, final AResource edge, final AResource nodeTarget) { + addEdge(nodeSource.toString(), edge.toString(), nodeTarget.toString()); + tripleNumber++; + } + + private void addEdge(final String sourceLabel, final String edgeLabel, final String targetLabel) { + + String sourceDecoded = GephiUtils.decodeString(sourceLabel); + String edgeDecoded = GephiUtils.decodeString(edgeLabel); + String targetDecoded = GephiUtils.decodeString(targetLabel); + + if (GephiExtension.isGephiExtension(edgeDecoded)) { + GephiExtension.processGephiExtension(sourceDecoded, edgeDecoded, targetDecoded, gephiUtils); + } else { + gephiUtils.addNode(sourceDecoded); + gephiUtils.addNode(targetDecoded); + gephiUtils.addEdge(sourceDecoded, edgeDecoded, targetDecoded); + if (count == 0) { + return; + } else { + InputStream followRDF; + followRDF = getRDF(targetDecoded.toString()); + RdfParser temp = new RdfParser(followRDF, modelToFill, --count); + temp.parse(); + return; + } + } + } + + public GraphModel getModelToFill() { + return modelToFill; + } + + final public void setModelToFill(final GraphModel modelToFill) { + this.modelToFill = modelToFill; + } + + public int getTripleNumber() { + return tripleNumber; + } + + public static String sendGetRequest(String endpoint, String requestParameters) { + String result = null; + if (endpoint.startsWith("http://")) { + // Send a GET request to the servlet + try { + // Construct data + StringBuffer data = new StringBuffer(); + // Send data + String urlStr = endpoint; + if (requestParameters != null && requestParameters.length() > 0) { + urlStr += "?" + requestParameters; + } + final URL url = new URL(urlStr); + final URLConnection conn = url.openConnection(); + conn.addRequestProperty("Accept", "application/rdf+xml"); + // Get the response + final InputStream inputStream = conn.getInputStream(); + final BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); + StringBuffer sb = new StringBuffer(); + String line; + while ((line = rd.readLine()) != null) { + sb.append(line); + } + rd.close(); + result = sb.toString(); + } catch (Exception e) { + Exceptions.printStackTrace(e); + } + } + return result; + } + + public static InputStream getRDF(final String strURI) { + InputStream result = null; + try { + URL url = new URL(strURI); + URLConnection conn = url.openConnection(); + conn.addRequestProperty("Accept", "application/rdf+xml"); + result = new BufferedInputStream(conn.getInputStream()); + } catch (Exception e) { + Exceptions.printStackTrace(e); + } + return result; + } + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/SparqlDriver.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/SparqlDriver.java new file mode 100644 index 0000000000..076355d3a3 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/SparqlDriver.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.sparql; + +import fr.inria.edelweiss.semantic.configurationmanager.ConfigurationManager; +import fr.inria.edelweiss.semantic.utils.FilesUtils; +import java.util.Observer; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Responsible for applying a SPARQL request on data which can be local or remote. + */ +public abstract class SparqlDriver

implements SparqlRequester{ + + private static final Logger logger = Logger.getLogger(SparqlDriver.class.getName()); + private P parameters; + + public P getParameters() { + return parameters; + } + + public void setParameters(final P parameters) { + this.parameters = parameters; + } + + public abstract void init(); + + public void setPluginProperties(Properties properties) { + this.pluginProperties = properties; + } + + public String getDisplayName() { + return getClass().getName(); + } + protected Properties pluginProperties = new Properties(); + + /** + * Use a configuration to:

  • \item \item <\li> + */ + public static SparqlDriver createFromConfigurationFile(String fileName) { + Properties currentProperties = FilesUtils.readProperties(fileName); + String driverName = currentProperties.getProperty(ConfigurationManager.DRIVER_NAME); + SparqlDriver result = null; + try { + result = (SparqlDriver) ClassLoader.getSystemClassLoader().loadClass(driverName).newInstance(); + } catch (ClassNotFoundException ex) { + throw new IllegalArgumentException(ex); + } catch (InstantiationException ex) { + throw new IllegalArgumentException(ex); + } catch (IllegalAccessException ex) { + throw new IllegalArgumentException(ex); + } + if (result == null) { + logger.log(Level.INFO, "No SPARQL driver found with name: \"{0}\"", driverName); + return null; + } + result.getParameters().readProperties(currentProperties); + return result; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/SparqlDriverFactory.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/SparqlDriverFactory.java new file mode 100644 index 0000000000..2f82194f7d --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/SparqlDriverFactory.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +package fr.inria.edelweiss.sparql; + +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author edemairy + */ +@ServiceProvider(service=SparqlDriverFactory.class) +public class SparqlDriverFactory { + static public SparqlDriver getDriver(String driverName) { + SparqlDriver result = null; + try { + Class test = Class.forName(driverName); + result = (SparqlDriver)test.newInstance(); + } catch (Exception e) { + throw new IllegalArgumentException("Exception caught when creating driverName(\""+driverName+"\"):" + e.getMessage() ); + } + return result; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/SparqlDriverParameters.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/SparqlDriverParameters.java new file mode 100644 index 0000000000..20c8107bdf --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/SparqlDriverParameters.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + + +package fr.inria.edelweiss.sparql; + +import java.util.Observable; +import java.util.Properties; + +/** + * Responsible for the management of parameters. + */ +public abstract class SparqlDriverParameters extends Observable { + + /** + * Define how to retrieve the configuration of the driver from a configuration. + */ + public abstract void readProperties(Properties configuration); + + /** + * Define how to store the parameters into a configuration file. + */ + public abstract void writeProperties(Properties p); + + /** + * returns the name of the class responsible for GUI management of the parameters. + */ + public String getPanelClassName() { + String simpleClassName = this.getClass().getSimpleName(); + String className = this.getClass().getCanonicalName(); + int lastIndex = className.lastIndexOf('.'); + String packageName = className.substring(0, lastIndex); + return packageName + "." + simpleClassName + "Panel"; + } + +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/SparqlRequester.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/SparqlRequester.java new file mode 100644 index 0000000000..4fb1f0b3a6 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/SparqlRequester.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.sparql; + +/** + * + * @author Erwan Demairy + */ +public interface SparqlRequester { + /* + * Execute a SPARQL request and return the rdf+xml output. + * @param request Sparql request the driver has to execute. + * @return A string containing the RDF/XMF result. + */ + String sparqlQuery(String request); + + /** + * + * @param request + * @return Each line represent the ids of the binding returned by the select call. + */ + String[][] selectOnGraph(String request); + +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/corese/CoreseDriver.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/corese/CoreseDriver.java new file mode 100644 index 0000000000..9c2db8a26f --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/corese/CoreseDriver.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +package fr.inria.edelweiss.sparql.corese; + +//~--- non-JDK imports -------------------------------------------------------- + +import fr.inria.corese.core.Graph; +import fr.inria.corese.core.load.Load; +import fr.inria.corese.core.load.LoadException; +import fr.inria.corese.core.print.ResultFormat; +import fr.inria.corese.core.query.QueryProcess; +import fr.inria.corese.kgram.api.core.Node; +import fr.inria.corese.kgram.core.Mapping; +import fr.inria.corese.kgram.core.Mappings; +import fr.inria.edelweiss.semantic.PluginProperties; +import fr.inria.edelweiss.sparql.SparqlDriver; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.methods.GetMethod; +import org.openide.util.lookup.ServiceProvider; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Observable; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Collectors; + +/** + */ +@ServiceProvider(service = SparqlDriver.class) +public class CoreseDriver extends SparqlDriver { + + private static final Logger logger = Logger.getLogger(CoreseDriver.class.getName()); + private Load loader; + private Graph graph; + private QueryProcess queryProcess; + private boolean ignoreBlankNodes = false; + + public CoreseDriver() { + setParameters(new CoreseDriverParameters()); + } + + /** + * Load the files given as parameters. + * + */ + @Override + public void init() { + graph = Graph.create(); + loader = Load.create( graph ); + this.queryProcess = QueryProcess.create( graph ); + + for (String resourceName : getParameters().getRdfResources()) { + logger.log(Level.INFO, "loading {0}", resourceName); + loadFile(resourceName); + } + ignoreBlankNodes = Boolean.parseBoolean(pluginProperties.getProperty(PluginProperties.IGNORE_BLANK_PROPERTIES.getValue(), "false")); + } + + /** + * + */ + @Override + public String sparqlQuery(final String request) { + StringBuilder result = new StringBuilder(); + + Mappings results; + try { + results = queryProcess.query(request); + ResultFormat resultRdf = ResultFormat.create(results, ResultFormat.RDF_XML_FORMAT); + result.append(resultRdf); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + return result.toString(); + } + + @Override + public String[][] selectOnGraph(String request) { + Mappings queryResults; + try { + queryResults = queryProcess.query(request); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + String[] variables = queryResults.getSelect().stream().map(Node::getKey).collect(Collectors.toList()).toArray(String[]::new); + String[][] result = new String[queryResults.size()][variables.length]; + int counterResult = 0; + for (Mapping queryResult : queryResults) { + int variableNum = 0; + for (String variable : variables) { + result[counterResult][variableNum] = queryResult.getValue(variable).toString(); + ++variableNum; + } + ++counterResult; + } + return result; + } + + private void loadUrl(final String url) throws IOException, LoadException { + HttpClient client = new HttpClient(); + GetMethod method = new GetMethod(url); + + try { + int returnCode = client.executeMethod(method); + logger.log(Level.INFO, "returned value when getting {0} = {1}", new Object[]{url, returnCode}); + if (returnCode != HttpStatus.SC_OK) { + throw new IOException("An error occurred"); + } else { + InputStream input = new ByteArrayInputStream(method.getResponseBodyAsString().getBytes()); + loader.parse(input); + } + } finally { + method.releaseConnection(); + } + } + + private void loadFile(final String fileName) { + try { + if (fileName.startsWith("http://")) { + loadUrl(fileName); + } else if (checkFileExist(fileName)) { + queryProcess.parse(fileName); + } else if (checkResourceExist(fileName)) { + load_resource_workaround(fileName); + } else { + throw new IllegalArgumentException("No URL, file or resource with name:" + fileName); + } + } catch (IllegalArgumentException ex) { + throw ex; + } catch (Exception ex) { + logger.log(Level.SEVERE, "Exception in loadFile:{0}", ex.getMessage()); + throw new RuntimeException(ex); + } + } + + private void load_resource(final String fileName) throws LoadException { + final InputStream resource = this.getClass().getResourceAsStream(fileName); + loader.parse(resource); + } + + /** + * Workaround because corese does not know which type is the file when loading inputstreams. + * + * @param fileName + * @throws LoadException + */ + private void load_resource_workaround(final String fileName) throws IOException, LoadException { + int dotPos = fileName.lastIndexOf('.'); + var tempFile = File.createTempFile("corese_input", '.' + fileName.substring(dotPos + 1, fileName.length())); + try (FileWriter outputTempFile = new FileWriter(tempFile); + var resource = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(fileName))) + ) { + String currentLine; + while ((currentLine = resource.readLine()) != null) { + outputTempFile.write(currentLine + '\n'); + } + } + loader.parse(tempFile.getAbsolutePath()); + } + + private boolean checkFileExist(final String fileName) { + final File checkFile = new File(fileName); + + if (fileName.isEmpty() || checkFile.exists()) { + return true; + } else { + return false; + } + } + + private boolean checkResourceExist(final String fileName) { + InputStream resource = this.getClass().getResourceAsStream(fileName); + return (resource != null); + } + + @Override + public String getDisplayName() { + return "Local Driver - Corese"; + } + + +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/corese/CoreseDriverParameters.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/corese/CoreseDriverParameters.java new file mode 100644 index 0000000000..17c4103e71 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/corese/CoreseDriverParameters.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +package fr.inria.edelweiss.sparql.corese; + +import fr.inria.edelweiss.sparql.SparqlDriverParameters; + +import javax.swing.DefaultListModel; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.Properties; + +/** + * @author Erwan Demairy + */ +public class CoreseDriverParameters extends SparqlDriverParameters { + public static final String RDF_RESOURCE_LIST = "rdfResourceList"; + DefaultListModel rdfResourceListModel; + + public CoreseDriverParameters() { + rdfResourceListModel = new DefaultListModel<>(); + } + + public String[] getRdfResources() { + final Enumeration list = rdfResourceListModel.elements(); + final ArrayList resultList = new ArrayList<>(); + while (list.hasMoreElements()) { + resultList.add(list.nextElement()); + } + var result = new String[resultList.size()]; + resultList.toArray(result); + return result; + } + + @Override + public void readProperties(Properties properties) { + String listResources = properties.getProperty(RDF_RESOURCE_LIST); + String[] resources = listResources.split(";"); + addResources(resources); + } + + @Override + public void writeProperties(Properties properties) { + var rdfResources = Arrays.asList(getRdfResources()); + var concatenatedListBuilder = new StringBuilder(50); + for (String resource : rdfResources) { + concatenatedListBuilder.append( resource ); + concatenatedListBuilder.append( ";" ); + } + properties.setProperty(RDF_RESOURCE_LIST, concatenatedListBuilder.toString()); + } + + void addResources(File[] selectedFiles) { + for (File currentFile : Arrays.asList(selectedFiles)) { + addResource(currentFile.getPath()); + } + } + + public final void addResources(final String[] resources) { + for (String resource : Arrays.asList(resources)) { + addResource(resource); + } + } + + public final void addResource(final String resource) { + rdfResourceListModel.addElement(resource); + } + + DefaultListModel getRdfResourcesModel() { + return rdfResourceListModel; + } + +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/corese/CoreseDriverParametersPanel.form b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/corese/CoreseDriverParametersPanel.form new file mode 100644 index 0000000000..54135f7d9d --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/corese/CoreseDriverParametersPanel.form @@ -0,0 +1,132 @@ + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/corese/CoreseDriverParametersPanel.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/corese/CoreseDriverParametersPanel.java new file mode 100644 index 0000000000..2ad3914468 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/corese/CoreseDriverParametersPanel.java @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.sparql.corese; + +import fr.inria.edelweiss.sparql.DriverParametersPanel; +import java.util.ArrayList; +import java.util.List; +import java.util.Observable; +import javax.swing.JFileChooser; +import javax.swing.JFrame; + +/**fr.inria.edelweiss.sparql.corese.CoreseDriverParametersPanel + * + * @author edemairy + */ +public class CoreseDriverParametersPanel extends DriverParametersPanel { + + private static final long serialVersionUID = 1590866778026160118L; + CoreseDriverParameters parameters; + + public CoreseDriverParametersPanel() { + super(); + initComponents(); + } + + /** Creates new form CoreseDriverParametersPanel */ + public CoreseDriverParametersPanel(CoreseDriverParameters driverParameters) { + super(); + initComponents(); + setParameters(driverParameters); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + rdfResourcesLabel = new javax.swing.JLabel(); + addRdfResourceButton = new javax.swing.JButton(); + removeRdfResourceButton = new javax.swing.JButton(); + rdfResourceList = new javax.swing.JList(); + addUrl = new javax.swing.JButton(); + urlField = new javax.swing.JTextField(); + + setToolTipText(org.openide.util.NbBundle.getMessage(CoreseDriverParametersPanel.class, "CoreseDriverParametersPanel.toolTipText")); // NOI18N + + rdfResourcesLabel.setText(org.openide.util.NbBundle.getMessage(CoreseDriverParametersPanel.class, "CoreseDriverParametersPanel.rdfResourcesLabel.text")); // NOI18N + + addRdfResourceButton.setActionCommand(org.openide.util.NbBundle.getMessage(CoreseDriverParametersPanel.class, "CoreseDriverParametersPanel.+.actionCommand")); // NOI18N + addRdfResourceButton.setLabel(org.openide.util.NbBundle.getMessage(CoreseDriverParametersPanel.class, "CoreseDriverParametersPanel.+.label")); // NOI18N + addRdfResourceButton.setName("+"); // NOI18N + addRdfResourceButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + addRdfResourceButtonMouseClicked(evt); + } + }); + addRdfResourceButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + addRdfResourceButtonActionPerformed(evt); + } + }); + + removeRdfResourceButton.setActionCommand(org.openide.util.NbBundle.getMessage(CoreseDriverParametersPanel.class, "CoreseDriverParametersPanel.-.actionCommand")); // NOI18N + removeRdfResourceButton.setLabel(org.openide.util.NbBundle.getMessage(CoreseDriverParametersPanel.class, "CoreseDriverParametersPanel.-.label")); // NOI18N + removeRdfResourceButton.setName("-"); // NOI18N + removeRdfResourceButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + removeRdfResourceButtonMouseClicked(evt); + } + }); + removeRdfResourceButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + removeRdfResourceButtonActionPerformed(evt); + } + }); + + rdfResourceList.setName("listResources"); // NOI18N + + addUrl.setText(org.openide.util.NbBundle.getMessage(CoreseDriverParametersPanel.class, "CoreseDriverParametersPanel.addUrl.text")); // NOI18N + addUrl.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + addUrlActionPerformed(evt); + } + }); + + urlField.setText(org.openide.util.NbBundle.getMessage(CoreseDriverParametersPanel.class, "CoreseDriverParametersPanel.urlField.text")); // NOI18N + urlField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + urlFieldActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(rdfResourceList, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(rdfResourcesLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(addRdfResourceButton, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(removeRdfResourceButton, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(addUrl) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(urlField, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(rdfResourcesLabel) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(removeRdfResourceButton) + .addComponent(addRdfResourceButton))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(rdfResourceList, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(addUrl) + .addComponent(urlField, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + private void addRdfResourceButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addRdfResourceButtonMouseClicked + JFileChooser rdfResourceChooser = new JFileChooser(""); + rdfResourceChooser.setMultiSelectionEnabled(true); + int result = rdfResourceChooser.showOpenDialog(this); + if (result == JFileChooser.APPROVE_OPTION) { + parameters.addResources(rdfResourceChooser.getSelectedFiles()); + } +}//GEN-LAST:event_addRdfResourceButtonMouseClicked + + private void addRdfResourceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addRdfResourceButtonActionPerformed +}//GEN-LAST:event_addRdfResourceButtonActionPerformed + + private void removeRdfResourceButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeRdfResourceButtonMouseClicked + int[] selectedIndexes = this.rdfResourceList.getSelectedIndices(); + for (int index : selectedIndexes) { + parameters.getRdfResourcesModel().remove(index); + } +}//GEN-LAST:event_removeRdfResourceButtonMouseClicked + + private void addUrlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addUrlActionPerformed + if (!urlField.getText().isEmpty()) { + parameters.addResource(urlField.getText()); + } +}//GEN-LAST:event_addUrlActionPerformed + + private void urlFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_urlFieldActionPerformed +}//GEN-LAST:event_urlFieldActionPerformed + + private void removeRdfResourceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeRdfResourceButtonActionPerformed + + }//GEN-LAST:event_removeRdfResourceButtonActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton addRdfResourceButton; + private javax.swing.JButton addUrl; + private javax.swing.JList rdfResourceList; + private javax.swing.JLabel rdfResourcesLabel; + private javax.swing.JButton removeRdfResourceButton; + private javax.swing.JTextField urlField; + // End of variables declaration//GEN-END:variables +// DefaultListModel getRdfResourceListModel() { +// return parameters.getdfResourceListModel; +// } + + public void addResource(String lastFileName) { + parameters.addResource(lastFileName); + } + + public List getResourceList() { + ArrayList result = new ArrayList(); + for (int i = 0; i < parameters.getRdfResourcesModel().getSize(); ++i) { + result.add((String) parameters.getRdfResourcesModel().get(i)); + } + return result; + } + + public void setParameters(CoreseDriverParameters parameters) { + this.parameters = parameters; + rdfResourceList.setModel(parameters.getRdfResourcesModel()); + } + + public static void main(String[] args) { + JFrame frame = new JFrame(); + frame.setResizable(true); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + CoreseDriver driver = new CoreseDriver(); + CoreseDriverParameters driverParameters = driver.getParameters(); + CoreseDriverParametersPanel panel = new CoreseDriverParametersPanel(driverParameters); + frame.setContentPane(panel); + frame.setSize(frame.getPreferredSize()); + frame.setVisible(true); + } + + @Override + public void update(Observable o, Object arg) { + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/restdriver/SparqlRestEndPointDriver.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/restdriver/SparqlRestEndPointDriver.java new file mode 100644 index 0000000000..e6ae9786c1 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/restdriver/SparqlRestEndPointDriver.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.sparql.restdriver; + +import fr.inria.edelweiss.sparql.SparqlDriver; +import java.io.*; +import java.net.*; +import java.util.Map; +import java.util.Observable; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JOptionPane; +import org.openide.util.Exceptions; +import org.openide.util.lookup.ServiceProvider; + +/** + * Class responsible for the requests done to REST SPARQL enpoints. + * + * @author edemairy + */ +@ServiceProvider(service = SparqlDriver.class) +public class SparqlRestEndPointDriver extends SparqlDriver { + + private static final Logger logger = Logger.getLogger(SparqlRestEndPointDriver.class.getName()); + private URL queryURL; + + /** + * Constructor. Create default values for the parameters. + */ + public SparqlRestEndPointDriver() { + setParameters(new SparqlRestEndPointDriverParameters()); + } + + @Override + public void init() { + } + + @Override + public String sparqlQuery(String sparqlQuery) { + StringBuilder sparqlQueryResult = new StringBuilder(); + try { + + String restQuery = ""; + try { + restQuery = getParameters().getQueryTagName() + "=" + URLEncoder.encode(sparqlQuery, "UTF-8") + getParameters().makeRequest(); + } catch (UnsupportedEncodingException ex) { + Exceptions.printStackTrace(ex); + } + byte[] restQueryAsBytes = restQuery.getBytes(); + try { + queryURL = new URL(getParameters().getEndPointUrl()); + HttpURLConnection urlConn = (HttpURLConnection) queryURL.openConnection(); + urlConn.setRequestMethod("POST"); + urlConn.setDoOutput(true); + urlConn.setDoInput(true); + urlConn.setUseCaches(false); + urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + urlConn.setRequestProperty("Accept", "application/rdf+xml, txt/xml, rdf/xml"); + + Map properties = getParameters().getRequestProperties(); + for (String propertyName : properties.keySet()) { + urlConn.setRequestProperty(propertyName, properties.get(propertyName)); + } + + OutputStream oStream = urlConn.getOutputStream(); + try { + + logger.log(Level.INFO, "{0} executing request: {1}", new Object[]{getClass().getName(), restQuery}); + oStream.write(restQueryAsBytes); + oStream.flush(); + + BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); + String currentLine; + int nbLines = 0; + logger.log(Level.INFO, "Result request:"); + while ((currentLine = in.readLine()) != null) { + if (nbLines < 10) { + logger.log(Level.INFO, currentLine); + } else { + logger.log(Level.FINE, currentLine); + } + sparqlQueryResult.append(currentLine + "\n"); + ++nbLines; + } + logger.log(Level.INFO, "Result contains {0} lines.", nbLines); + oStream.close(); + in.close(); + } catch (Exception ex) { + oStream.close(); + } + } catch (MalformedURLException ex) { + JOptionPane.showMessageDialog(null, "The URL entered is incorrect"); + } + + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + return sparqlQueryResult.toString(); + } + + @Override + public String getDisplayName() { + return "Remote - REST endpoint"; + } + + @Override + public String[][] selectOnGraph(String request) { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/restdriver/SparqlRestEndPointDriverParameters.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/restdriver/SparqlRestEndPointDriverParameters.java new file mode 100644 index 0000000000..9d65013556 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/restdriver/SparqlRestEndPointDriverParameters.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.sparql.restdriver; + +import fr.inria.edelweiss.sparql.RdfParser; +import fr.inria.edelweiss.sparql.SparqlDriverParameters; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.logging.Level; + +/** + * + * @author Erwan Demairy + */ +public class SparqlRestEndPointDriverParameters extends SparqlDriverParameters { + + private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(RdfParser.class.getName()); + public static final String HOST_URL_TAG = "restSparqlEndPointURL"; + public static final String QUERY_TAG = "restSparqlEndPointQuery"; + public static final String REQUEST_PROPERTIES = "restSparqlEndPointRequestProperties"; + public static final String REQUEST_PARAMETERS = "restSparqlEndPointRequestParameters"; + public static final String QUERY_TAGNAME_DEFAULT_VALUE = "query"; + private Map requestParameters; + private Map requestProperties; + String queryTagName = QUERY_TAGNAME_DEFAULT_VALUE; + + public SparqlRestEndPointDriverParameters() { + requestParameters = new HashMap(); + requestProperties = new HashMap(); + } + + @Override + public void readProperties(Properties configuration) { + try { + setEndPointUrl(configuration.getProperty(SparqlRestEndPointDriverParameters.HOST_URL_TAG)); + setQueryTagName(configuration.getProperty(SparqlRestEndPointDriverParameters.QUERY_TAG)); + setRequestProperties(readMapInProperties(SparqlRestEndPointDriverParameters.REQUEST_PROPERTIES, configuration)); + setRequestParameters(readMapInProperties(SparqlRestEndPointDriverParameters.REQUEST_PARAMETERS, configuration)); + } catch (UnsupportedEncodingException ex) { + logger.severe(ex.getMessage()); + } + } + + @Override + public void writeProperties(Properties p) { + try { + p.setProperty(SparqlRestEndPointDriverParameters.HOST_URL_TAG, getEndPointUrl()); + p.setProperty(SparqlRestEndPointDriverParameters.QUERY_TAG, getQueryTagName()); + writeMapInProperties(getRequestProperties(), SparqlRestEndPointDriverParameters.REQUEST_PROPERTIES, p); + writeMapInProperties(getRequestParameters(), SparqlRestEndPointDriverParameters.REQUEST_PARAMETERS, p); + } catch (UnsupportedEncodingException ex) { + logger.severe(ex.getMessage()); + } + } + + private void writeMapInProperties(final Map map, String nameEntry, Properties p) throws UnsupportedEncodingException { + StringBuilder properties = new StringBuilder(); + for (String key : map.keySet()) { + properties.append(URLEncoder.encode(key, "UTF-8")); + properties.append(";"); + properties.append(URLEncoder.encode(map.get(key), "UTF-8")); + properties.append(";"); + } + p.setProperty(nameEntry, properties.toString()); + } + + private Map readMapInProperties(String nameEntry, Properties p) throws UnsupportedEncodingException { + Map result = new HashMap(); + String property = p.getProperty(nameEntry); + property = (property == null) ? "" : property; + String[] properties = property.split(";"); + if (properties.length % 2 != 0) { + logger.log(Level.WARNING, "The number of properties should be even, but is equal to {0}", properties.length); + } + for (int propertyNum = 0; propertyNum < properties.length / 2; ++propertyNum) { + result.put(properties[propertyNum * 2], URLDecoder.decode(properties[propertyNum * 2 + 1], "UTF-8")); + } + return result; + } + String endPointUrl; + + public final String getEndPointUrl() { + return endPointUrl; + } + + public final void setEndPointUrl(final String newUrl) { + this.endPointUrl = newUrl; + setChanged(); + notifyObservers(); + } + + String makeRequest() { + StringBuilder result = new StringBuilder(); + for (String key : requestParameters.keySet()) { + String restValue = requestParameters.get(key); + result.append("&").append(key).append("=").append(restValue); + } + return result.toString(); + } + + /** + * @return the queryTagName + */ + public String getQueryTagName() { + return queryTagName; + } + + /** + * @param queryTagName the queryTagName to set + */ + public void setQueryTagName(String queryTagName) { + this.queryTagName = queryTagName; + setChanged(); + notifyObservers(); + } + + public Map getRequestProperties() { + return requestProperties; + } + + private void setRequestProperties(Map readMapInProperties) { + requestProperties = readMapInProperties; + setChanged(); + notifyObservers(); + } + + public Map getRequestParameters() { + return requestParameters; + } + + private void setRequestParameters(Map readMapInProperties) { + requestParameters = readMapInProperties; + setChanged(); + notifyObservers(); + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/restdriver/SparqlRestEndPointDriverParametersPanel.form b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/restdriver/SparqlRestEndPointDriverParametersPanel.form new file mode 100644 index 0000000000..09737415e3 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/restdriver/SparqlRestEndPointDriverParametersPanel.form @@ -0,0 +1,289 @@ + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + + + <ResourceString bundle="fr/inria/edelweiss/sparql/restdriver/Bundle.properties" key="SparqlRestEndPointDriverParametersPanel.restParametersTable.columnModel.title0" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + + + + + + + <ResourceString bundle="fr/inria/edelweiss/sparql/restdriver/Bundle.properties" key="SparqlRestEndPointDriverParametersPanel.restParametersTable.columnModel.title1" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + + + + + + + + + + +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + + + <ResourceString bundle="fr/inria/edelweiss/sparql/restdriver/Bundle.properties" key="SparqlRestEndPointParametersPanel.restParametersTable.columnModel.title0" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + + + + + + + <ResourceString bundle="fr/inria/edelweiss/sparql/restdriver/Bundle.properties" key="SparqlRestEndPointParametersPanel.restParametersTable.columnModel.title1" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + + + + + + + + + + +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/restdriver/SparqlRestEndPointDriverParametersPanel.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/restdriver/SparqlRestEndPointDriverParametersPanel.java new file mode 100644 index 0000000000..4bd1ab0e33 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/restdriver/SparqlRestEndPointDriverParametersPanel.java @@ -0,0 +1,425 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +package fr.inria.edelweiss.sparql.restdriver; + +import fr.inria.edelweiss.sparql.DriverParametersPanel; +import fr.inria.edelweiss.sparql.RdfParser; +import java.util.ArrayList; +import java.util.Map; +import java.util.Observable; +import java.util.logging.Level; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.table.DefaultTableModel; + +/* + * SparqlRestEndPointDriverParametersPanel.java + * + * Created on Jul 19, 2011, 3:51:43 PM + */ +/** + * + * @author edemairy + */ +public class SparqlRestEndPointDriverParametersPanel + extends DriverParametersPanel { + + private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(RdfParser.class.getName()); + private static final long serialVersionUID = -2150909085565094001L; + private DefaultTableModel restParametersModel; + private DefaultTableModel restPropertiesModel; + private boolean inParametersUpdate = false; + + public SparqlRestEndPointDriverParametersPanel(final SparqlRestEndPointDriverParameters parameters) { + super(); + initComponents(); + + setParameters(parameters); + reset(); + + restParametersModel = new DefaultTableModel(); + restParametersTable.setModel(restParametersModel); + fillParameters(); + restParametersTable.invalidate(); + + restPropertiesModel = new DefaultTableModel() { + private static final long serialVersionUID = 320734002831587245L; + + @Override + public int getRowCount() { + return parameters.getRequestProperties().size(); + } + + @Override + public int getColumnCount() { + return 2; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + switch (columnIndex) { + case 0: + return parameters.getRequestProperties().keySet().toArray()[rowIndex]; + case 1: + return parameters.getRequestProperties().values().toArray()[rowIndex]; + } + return null; + } + + @Override + public void addRow(Object[] rowData) { + parameters.getRequestProperties().put((String) rowData[0], (String) rowData[1]); + } + }; + restPropertiesTable.setModel(restPropertiesModel); + fillProperties(); + restPropertiesTable.invalidate(); + } + + private void fillParameters() { + restParametersModel.addColumn("REST parameter name"); + restParametersModel.addColumn("Value"); + for (String parameterName : getParameters().getRequestParameters().keySet()) { + String[] datas = new String[2]; + datas[0] = parameterName; + datas[1] = getParameters().getRequestParameters().get(parameterName); + restParametersModel.addRow(datas); + } + } + + private void fillProperties() { + restPropertiesModel.addColumn("Properties parameter name"); + restPropertiesModel.addColumn("Value"); + for (String propertyName : getParameters().getRequestProperties().keySet()) { + String[] datas = new String[2]; + datas[0] = propertyName; + datas[1] = getParameters().getRequestProperties().get(propertyName); + restPropertiesModel.addRow(datas); + } + } + + public String getUrl() { + return urlTextField.getText(); + } + + public final void setUrl(String newUrl) { + urlTextField.setText(newUrl); + } + + /** + * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + urlTextField = new javax.swing.JTextField(); + urlLabel1 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + restParametersTable = new javax.swing.JTable(); + addTagButton = new javax.swing.JButton(); + newParameterRestName = new javax.swing.JTextField(); + newParameterRestValue = new javax.swing.JTextField(); + removeTagButton = new javax.swing.JButton(); + queryTagName = new javax.swing.JTextField(); + jLabel1 = new javax.swing.JLabel(); + jScrollPane2 = new javax.swing.JScrollPane(); + restPropertiesTable = new javax.swing.JTable(); + newPropertyName = new javax.swing.JTextField(); + newPropertyValue = new javax.swing.JTextField(); + addPropertyButton = new javax.swing.JButton(); + removePropertyButton = new javax.swing.JButton(); + + urlTextField.setText(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.urlTextField.text")); // NOI18N + urlTextField.getDocument().addDocumentListener(new DocumentListener() { + public void changedUpdate(DocumentEvent e) { + updateUrlText(); + } + public void removeUpdate(DocumentEvent e) { + updateUrlText(); + } + public void insertUpdate(DocumentEvent e) { + updateUrlText(); + } + private void updateUrlText() { + try { + inParametersUpdate = true; + getParameters().setEndPointUrl(urlTextField.getText()); + } finally { + inParametersUpdate = false; + } + } + }); + + urlLabel1.setText(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.urlLabel1.text")); // NOI18N + + restParametersTable.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + + }, + new String [] { + "nurll", "nullr" + } + )); + restParametersTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS); + restParametersTable.setColumnSelectionAllowed(true); + jScrollPane1.setViewportView(restParametersTable); + restParametersTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + if (restParametersTable.getColumnModel().getColumnCount() > 0) { + restParametersTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.restParametersTable.columnModel.title0")); // NOI18N + restParametersTable.getColumnModel().getColumn(1).setHeaderValue(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.restParametersTable.columnModel.title1")); // NOI18N + } + + addTagButton.setText(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.addTagButton.text")); // NOI18N + addTagButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + addTagButtonMouseClicked(evt); + } + }); + addTagButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + addTagButtonActionPerformed(evt); + } + }); + + newParameterRestName.setText(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.newParameterRestName.text")); // NOI18N + + newParameterRestValue.setText(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.newParameterRestValue.text")); // NOI18N + + removeTagButton.setText(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.removeTagButton.text")); // NOI18N + removeTagButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + removeTagButtonMouseClicked(evt); + } + }); + + queryTagName.setText(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.queryTagName.text")); // NOI18N + queryTagName.getDocument().addDocumentListener(new DocumentListener() { + public void changedUpdate(DocumentEvent e) { + updateQueryTagName(); + } + public void removeUpdate(DocumentEvent e) { + updateQueryTagName(); + } + public void insertUpdate(DocumentEvent e) { + updateQueryTagName(); + } + private void updateQueryTagName() { + try { + inParametersUpdate = true; + getParameters().setQueryTagName(queryTagName.getText()); + } finally { + inParametersUpdate = false; + } + } + }); + + jLabel1.setText(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.jLabel1.text")); // NOI18N + + restPropertiesTable.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + + }, + new String [] { + "nullr", "nullr" + } + )); + restPropertiesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS); + restPropertiesTable.setColumnSelectionAllowed(true); + jScrollPane2.setViewportView(restPropertiesTable); + restPropertiesTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + if (restPropertiesTable.getColumnModel().getColumnCount() > 0) { + restPropertiesTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointParametersPanel.restParametersTable.columnModel.title0")); // NOI18N + restPropertiesTable.getColumnModel().getColumn(1).setHeaderValue(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointParametersPanel.restParametersTable.columnModel.title1")); // NOI18N + } + + newPropertyName.setText(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.newPropertyName.text")); // NOI18N + + newPropertyValue.setText(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.newPropertyValue.text")); // NOI18N + newPropertyValue.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + newPropertyValueActionPerformed(evt); + } + }); + + addPropertyButton.setText(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.addPropertyButton.text")); // NOI18N + addPropertyButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + addPropertyButtonMouseClicked(evt); + } + }); + addPropertyButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + addPropertyButtonActionPerformed(evt); + } + }); + + removePropertyButton.setText(org.openide.util.NbBundle.getMessage(SparqlRestEndPointDriverParametersPanel.class, "SparqlRestEndPointDriverParametersPanel.removePropertyButton.text")); // NOI18N + removePropertyButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + removePropertyButtonMouseClicked(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(urlLabel1) + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(24, 24, 24) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(urlTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE) + .addComponent(queryTagName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE))) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addComponent(newPropertyName) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(newPropertyValue) + .addGap(18, 18, 18) + .addComponent(addPropertyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(removePropertyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addComponent(newParameterRestName) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(newParameterRestValue) + .addGap(18, 18, 18) + .addComponent(addTagButton) + .addGap(18, 18, 18) + .addComponent(removeTagButton)) + .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(urlLabel1) + .addComponent(urlTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(queryTagName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel1)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 73, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(addPropertyButton) + .addComponent(removePropertyButton)) + .addComponent(newPropertyName, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(newPropertyValue, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(4, 4, 4) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(newParameterRestName, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(newParameterRestValue, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(addTagButton) + .addComponent(removeTagButton)) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + private void addTagButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addTagButtonMouseClicked + String[] rowData = new String[3]; + rowData[0] = newParameterRestName.getText(); + rowData[1] = newParameterRestValue.getText(); + restParametersModel.addRow(rowData); + restParametersTable.invalidate(); + this.invalidate(); + this.validate(); + }//GEN-LAST:event_addTagButtonMouseClicked + + private void addTagButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTagButtonActionPerformed + }//GEN-LAST:event_addTagButtonActionPerformed + + private void removeTagButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeTagButtonMouseClicked + for (int i : restParametersTable.getSelectedRows()) { + restParametersModel.removeRow(i); + } + }//GEN-LAST:event_removeTagButtonMouseClicked + + private void addPropertyButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addPropertyButtonMouseClicked + String[] rowData = new String[3]; + rowData[0] = newPropertyName.getText(); + rowData[1] = newPropertyValue.getText(); + restPropertiesModel.addRow(rowData); + restPropertiesTable.invalidate(); + this.invalidate(); + this.validate(); + }//GEN-LAST:event_addPropertyButtonMouseClicked + + private void addPropertyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPropertyButtonActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_addPropertyButtonActionPerformed + + private void removePropertyButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removePropertyButtonMouseClicked + for (int i : restPropertiesTable.getSelectedRows()) { + restPropertiesModel.removeRow(i); + } + }//GEN-LAST:event_removePropertyButtonMouseClicked + + private void newPropertyValueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newPropertyValueActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_newPropertyValueActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton addPropertyButton; + private javax.swing.JButton addTagButton; + private javax.swing.JLabel jLabel1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JTextField newParameterRestName; + private javax.swing.JTextField newParameterRestValue; + private javax.swing.JTextField newPropertyName; + private javax.swing.JTextField newPropertyValue; + private javax.swing.JTextField queryTagName; + private javax.swing.JButton removePropertyButton; + private javax.swing.JButton removeTagButton; + private javax.swing.JTable restParametersTable; + private javax.swing.JTable restPropertiesTable; + private javax.swing.JLabel urlLabel1; + private javax.swing.JTextField urlTextField; + // End of variables declaration//GEN-END:variables + + void fillMap(Map map) { + ArrayList> data = new ArrayList>(restParametersModel.getDataVector().size()); + map.clear(); + for (int row = 0; row < data.size(); ++row) { + ArrayList currentRow = data.get(row); + map.put(currentRow.get(0), currentRow.get(1)); + } + } + + String getQueryTagName() { + return queryTagName.getText(); + } + + void setQueryTagName(final String newTagName) { + queryTagName.setText(newTagName); + } + + final void reset() { + setUrl(getParameters().getEndPointUrl()); + setQueryTagName(getParameters().getQueryTagName()); + } + + @Override + public void update(Observable o, Object arg) { + logger.log(Level.INFO, "in update: {0} {1}", new Object[]{inParametersUpdate, getParameters().getQueryTagName()}); + if (!inParametersUpdate) { + reset(); + } + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/Bundle.properties b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/Bundle.properties new file mode 100644 index 0000000000..029e16448c --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/Bundle.properties @@ -0,0 +1,3 @@ + +SparqlSoapEndPointDriverParametersPanel.urlTextField.text=urlTextField +SparqlSoapEndPointDriverParametersPanel.urlLabel.text=EndPoint URL diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/SparqlSoapEndPointDriver.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/SparqlSoapEndPointDriver.java new file mode 100644 index 0000000000..bf8ad7a043 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/SparqlSoapEndPointDriver.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +//// +///* +// * Copyright (c) 2011, INRIA +// * All rights reserved. +// */ +//// +//package fr.inria.edelweiss.sparql.soap; +// +//import fr.inria.edelweiss.sparql.SparqlDriver; +//import fr.inria.wimmics.sparql.soap.client.SparqlResult; +//import fr.inria.wimmics.sparql.soap.client.SparqlSoapClient; +//import java.util.Observable; +//import java.util.logging.Level; +//import java.util.logging.Logger; +//import org.openide.util.lookup.ServiceProvider; +// +///** +// * +// * @author edemairy +// */ +//@ServiceProvider(service = SparqlDriver.class) +//public class SparqlSoapEndPointDriver extends SparqlDriver { +// +// private static final Logger logger = Logger.getLogger(SparqlSoapEndPointDriver.class.getName()); +// +// @Override +// public String[][] selectOnGraph(String request) { +// throw new UnsupportedOperationException("Not supported yet."); +// } +// +// @Override +// public void update(Observable o, Object arg) { +// } +// +// public SparqlSoapEndPointDriver() { +// setParameters(new SparqlSoapEndPointDriverParameters()); +// } +// +// @Override +// public void init() { +// } +// +// @Override +// public final String sparqlQuery(final String request) { +// logger.log(Level.INFO, "URL called: {0} request:{1}", new Object[]{getParameters().getUrl(), request}); +// SparqlSoapClient client = new SparqlSoapClient(); +// SparqlResult result = client.sparqlQuery(getParameters().getUrl(), request); +// return result.toString(); +// } +// +// @Override +// public String getDisplayName() { +// return "Remote - SOAP endpoint"; +// } +//} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/SparqlSoapEndPointDriverParameters.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/SparqlSoapEndPointDriverParameters.java new file mode 100644 index 0000000000..e573b84c35 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/SparqlSoapEndPointDriverParameters.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + + +package fr.inria.edelweiss.sparql.soap; + +import fr.inria.edelweiss.sparql.SparqlDriverParameters; +import java.util.Properties; + +/** + * + * @author Erwan Demairy + */ +public class SparqlSoapEndPointDriverParameters extends SparqlDriverParameters { + public static final String HOST_URL_TAG = "sparqlEndPointURL"; + private String url = "http://dbpedia.org/sparql"; + private SparqlSoapEndPointDriverParametersPanel panel; + + public SparqlSoapEndPointDriverParameters() { + panel = new SparqlSoapEndPointDriverParametersPanel(this); + } + + public void setUrl(String text) { + url = text; + setChanged(); + notifyObservers(); + } + + public String getUrl() { + return url; + } + + @Override + public void readProperties(Properties configuration) { + setUrl(configuration.getProperty(SparqlSoapEndPointDriverParameters.HOST_URL_TAG)); + panel.reset(); + } + + @Override + public void writeProperties(Properties p) { + p.setProperty(SparqlSoapEndPointDriverParameters.HOST_URL_TAG, getUrl()); + } + +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/SparqlSoapEndPointDriverParametersPanel.form b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/SparqlSoapEndPointDriverParametersPanel.form new file mode 100644 index 0000000000..eaf2b33887 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/SparqlSoapEndPointDriverParametersPanel.form @@ -0,0 +1,65 @@ + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/SparqlSoapEndPointDriverParametersPanel.java b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/SparqlSoapEndPointDriverParametersPanel.java new file mode 100644 index 0000000000..74c23b5b3d --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/edelweiss/sparql/soap/SparqlSoapEndPointDriverParametersPanel.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.edelweiss.sparql.soap; + +import fr.inria.edelweiss.sparql.DriverParametersPanel; +import java.util.Observable; + +/** + * + * @author edemairy + */ +public final class SparqlSoapEndPointDriverParametersPanel extends DriverParametersPanel { + + private static final long serialVersionUID = 8752067213343400680L; + private final SparqlSoapEndPointDriverParameters driverParameters; + + public SparqlSoapEndPointDriverParametersPanel(SparqlSoapEndPointDriverParameters newDriverParameters) { + super(); + initComponents(); + driverParameters = newDriverParameters; + reset(); + } + + /** + * This method is called from within the constructor to initialize the + * form. WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + urlLabel = new javax.swing.JLabel(); + urlTextField = new javax.swing.JTextField(); + + urlLabel.setText(org.openide.util.NbBundle.getMessage(SparqlSoapEndPointDriverParametersPanel.class, "SparqlSoapEndPointDriverParametersPanel.urlLabel.text")); // NOI18N + + urlTextField.setText(org.openide.util.NbBundle.getMessage(SparqlSoapEndPointDriverParametersPanel.class, "SparqlSoapEndPointDriverParametersPanel.urlTextField.text")); // NOI18N + urlTextField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + urlTextFieldActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(urlLabel) + .addGap(50, 50, 50) + .addComponent(urlTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(urlTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(urlLabel)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + }// //GEN-END:initComponents + + private void urlTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_urlTextFieldActionPerformed + driverParameters.setUrl( urlTextField.getText()); + }//GEN-LAST:event_urlTextFieldActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel urlLabel; + private javax.swing.JTextField urlTextField; + // End of variables declaration//GEN-END:variables + + + void reset() { + String url = driverParameters.getUrl(); + urlTextField.setText(url); + } + + public String getUrlValue() { + return urlTextField.getText(); + } + + @Override + public void update(Observable o, Object arg) { + reset(); + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/instance/InstanceFilter.java b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/instance/InstanceFilter.java new file mode 100644 index 0000000000..591b3134ad --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/instance/InstanceFilter.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +package fr.inria.wimmics.semanticweb.filter.instance; + +import fr.inria.edelweiss.semantic.SemanticWebImportMainWindowTopComponent; +import java.util.Formatter; +import java.util.HashSet; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.gephi.filters.spi.ComplexFilter; +import org.gephi.filters.spi.FilterProperty; +import org.gephi.graph.api.Graph; +import org.gephi.graph.api.Node; + +/** + * + * @author Erwan Demairy + */ +public class InstanceFilter implements ComplexFilter { + + private static final Logger logger = Logger.getLogger(InstanceFilter.class.getName()); + private String type; + + public InstanceFilter() { + } + + @Override + public String getName() { + return "Model Types Filter"; + } + + @Override + public FilterProperty[] getProperties() { + FilterProperty[] result = new FilterProperty[0]; + try { + result = new FilterProperty[]{FilterProperty.createProperty(this, String.class, "type", "getType", "setType")}; + } catch (NoSuchMethodException ex) { + Logger.getLogger(InstanceFilter.class.getName()).log(Level.SEVERE, null, ex); + } + return result; + } + + public String getType() { + return type; + } + + public void setType(String newType) { + type = newType; + } + static public String GET_ALLTYPES_OF = + "SELECT ?t WHERE { " + + "{ ?x rdf:type ?t } Union " + + "{ ?x rdfs:subClassOf ?t } Union " + + "{ ?x rdfs:subPropertyOf ?t}" + + "} " + + "group by ?t"; + + @Override + public Graph filter(Graph graph) { + try (Formatter getSubtypesOfrequest = new Formatter().format(GET_ALLTYPES_OF, type)) { + String[][] nodesToKeepList = SemanticWebImportMainWindowTopComponent.getSparqlRequester().selectOnGraph(getSubtypesOfrequest.toString()); + HashSet nodesToKeepSet = convertStringArrayToSet(nodesToKeepList); + + Node[] nodes = graph.getNodes().toArray(); + for (Node node : nodes) { + if (!nodesToKeepSet.contains((String) node.getId())) { + graph.removeNode(node); + } + } + } + return graph; + } + + private HashSet convertStringArrayToSet(String[][] listNodes) { + HashSet result = new HashSet(); + for (int i = 0; i < listNodes.length; ++i) { + result.add(listNodes[i][0]); + } + return result; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/instance/InstanceFilterBuilder.java b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/instance/InstanceFilterBuilder.java new file mode 100644 index 0000000000..639d8c3a68 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/instance/InstanceFilterBuilder.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.wimmics.semanticweb.filter.instance; + +import fr.inria.edelweiss.semantic.SemanticWebImportMainWindowTopComponent; +import javax.swing.Icon; +import javax.swing.JPanel; +import org.gephi.filters.spi.Category; +import org.gephi.filters.spi.Filter; +import org.gephi.filters.spi.FilterBuilder; +import org.gephi.project.api.Workspace; +import org.openide.util.lookup.ServiceProvider; + +/** + * Class responsible for building a new semanticweb filter. + * + * @author Erwan Demairy + */ +@ServiceProvider(service = FilterBuilder.class) +public class InstanceFilterBuilder implements FilterBuilder { + @Override + public Category getCategory() { + return new Category("SemanticWeb", getIcon()); +// return FilterLibrary.ATTRIBUTES; + } + + @Override + public String getName() { + return "Model Types Filter"; + } + + @Override + public Icon getIcon() { + return SemanticWebImportMainWindowTopComponent.loadIcon(); + } + + @Override + public String getDescription() { + return "Remove all the nodes that are types, so that only instances are kept."; + } + + @Override + public Filter getFilter(Workspace workspace) { + return new InstanceFilter(); + } + + @Override + public JPanel getPanel(Filter filter) { + InstanceFilter semanticWebFilter = (InstanceFilter) filter; + return new InstanceFilterPanel(semanticWebFilter); + } + + @Override + public void destroy(Filter filter) { + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/instance/InstanceFilterPanel.form b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/instance/InstanceFilterPanel.form new file mode 100644 index 0000000000..4bc3fb8271 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/instance/InstanceFilterPanel.form @@ -0,0 +1,28 @@ + + +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/instance/InstanceFilterPanel.java b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/instance/InstanceFilterPanel.java new file mode 100644 index 0000000000..5fcfdbece2 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/instance/InstanceFilterPanel.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.wimmics.semanticweb.filter.instance; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import org.gephi.filters.spi.FilterProperty; + +/** + * + * @author Erwan Demairy + */ +public class InstanceFilterPanel extends javax.swing.JPanel implements ActionListener { + + private static final long serialVersionUID = -6108289528761360770L; + private final InstanceFilter filter; + + public InstanceFilterPanel(InstanceFilter filter) { + this.filter = filter; + initComponents(); + } + + @Override + public void actionPerformed(ActionEvent e) { + FilterProperty typeToFilter = filter.getProperties()[0]; + } + + /** + * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 498, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 36, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/sparql/SPARQLFilterPanel.form b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/sparql/SPARQLFilterPanel.form new file mode 100644 index 0000000000..8cb8a9a595 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/sparql/SPARQLFilterPanel.form @@ -0,0 +1,64 @@ + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/sparql/SparqlFilter.java b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/sparql/SparqlFilter.java new file mode 100644 index 0000000000..1b52990e63 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/sparql/SparqlFilter.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +package fr.inria.wimmics.semanticweb.filter.sparql; + +import fr.inria.edelweiss.semantic.SemanticWebImportMainWindowTopComponent; +import fr.inria.edelweiss.sparql.GephiUtils; + +import java.util.HashSet; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.gephi.filters.spi.ComplexFilter; +import org.gephi.filters.spi.FilterProperty; +import org.gephi.graph.api.Graph; +import org.gephi.graph.api.Node; + +/** + * + * @author Erwan Demairy + */ +public class SparqlFilter implements ComplexFilter { + + private final Logger logger = Logger.getLogger(SparqlFilter.class.getName()); + private String selectRequest; + + public SparqlFilter() { + } + + @Override + public String getName() { + return "SPARQL Filter"; + } + + @Override + public FilterProperty[] getProperties() { + FilterProperty[] result = new FilterProperty[0]; + try { + result = new FilterProperty[]{FilterProperty.createProperty(this, String.class, "selectRequest", "getSelectRequest", "setSelectRequest")}; + } catch (NoSuchMethodException ex) { + Logger.getLogger(SparqlFilter.class.getName()).log(Level.SEVERE, null, ex); + } + return result; + } + + public String getSelectRequest() { + return selectRequest; + } + + public void setSelectRequest(String newType) { + selectRequest = newType; + } + + @Override + public Graph filter(Graph graph) { + String[][] nodesToKeepList = SemanticWebImportMainWindowTopComponent.getSparqlRequester().selectOnGraph(selectRequest); + HashSet nodesToKeepSet = convertStringArrayToSet(nodesToKeepList); + + Node[] nodes = graph.getNodes().toArray(); + forNodes: + for (Node node : nodes) { + if (nodesToKeepSet.contains(GephiUtils.getSparqlId(node))) { + continue forNodes; + } else { + graph.removeNode(node); + } + } + return graph; + } + + private HashSet convertStringArrayToSet(String[][] listNodes) { + HashSet result = new HashSet(); + for (int i = 0; i < listNodes.length; ++i) { + for (int j = 0; j < listNodes[0].length; ++j) { + result.add(listNodes[i][j]); + } + } + return result; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/sparql/SparqlFilterBuilder.java b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/sparql/SparqlFilterBuilder.java new file mode 100644 index 0000000000..719d4f29cb --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/sparql/SparqlFilterBuilder.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.wimmics.semanticweb.filter.sparql; + +import fr.inria.edelweiss.semantic.SemanticWebImportMainWindowTopComponent; +import javax.swing.Icon; +import javax.swing.JPanel; +import org.gephi.filters.spi.Category; +import org.gephi.filters.spi.Filter; +import org.gephi.filters.spi.FilterBuilder; +import org.gephi.project.api.Workspace; +import org.openide.util.lookup.ServiceProvider; + +/** + * Class responsible for building a new semanticweb filter. + * + * @author Erwan Demairy + */ +@ServiceProvider(service = FilterBuilder.class) +public class SparqlFilterBuilder implements FilterBuilder { + @Override + public Category getCategory() { + return new Category("SemanticWeb", getIcon()); + } + + @Override + public String getName() { + return "SPARQL Filter"; + } + + @Override + public Icon getIcon() { + return SemanticWebImportMainWindowTopComponent.loadIcon(); + } + + @Override + public String getDescription() { + return "Keep only the nodes returned by the SELECT expression provided."; + } + + @Override + public Filter getFilter(Workspace workspace) { + return new SparqlFilter(); + } + + @Override + public JPanel getPanel(Filter filter) { + SparqlFilter semanticWebFilter = (SparqlFilter) filter; + return new SparqlFilterPanel(semanticWebFilter); + } + + @Override + public void destroy(Filter filter) { + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/sparql/SparqlFilterPanel.java b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/sparql/SparqlFilterPanel.java new file mode 100644 index 0000000000..a63fa3419a --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/sparql/SparqlFilterPanel.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.wimmics.semanticweb.filter.sparql; + +import org.gephi.filters.spi.FilterProperty; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + + +/** + * + * @author Erwan Demairy + */ +public class SparqlFilterPanel extends javax.swing.JPanel implements ActionListener { + + private static final long serialVersionUID = -1459885291629743647L; + private final transient SparqlFilter filter; // \TODO assess whether filter should be Serializable + + public SparqlFilterPanel(SparqlFilter filter) { + this.filter = filter; + initComponents(); + updateButton.addActionListener(this); + String request = filter.getSelectRequest(); + if ((request != null) && !request.isEmpty()) { + sparqlRequestEditor.setQueryText(request); + } else { + updateFilterValue(); + } + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + sparqlRequestEditor = new fr.inria.corese.gui.query.SparqlQueryEditor(); + updateButton = new javax.swing.JButton(); + + sparqlRequestEditor.setMinimumSize(new java.awt.Dimension(431, 253)); + sparqlRequestEditor.setName(""); // NOI18N + sparqlRequestEditor.setQueryText(org.openide.util.NbBundle.getMessage(SparqlFilterPanel.class, "SPARQLFilterPanel.queryText")); // NOI18N + + updateButton.setText(org.openide.util.NbBundle.getMessage(SparqlFilterPanel.class, "SPARQLFilterPanel.updateButton.text")); // NOI18N + updateButton.addActionListener(this::updateButtonActionPerformed); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(sparqlRequestEditor, javax.swing.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE) + .addComponent(updateButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(sparqlRequestEditor, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(updateButton) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + private void updateButtonActionPerformed(java.awt.event.ActionEvent ignoredEvt) {//GEN-FIRST:event_updateButtonActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_updateButtonActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private fr.inria.corese.gui.query.SparqlQueryEditor sparqlRequestEditor; + private javax.swing.JButton updateButton; + // End of variables declaration//GEN-END:variables + + private void updateFilterValue() { + FilterProperty typeToFilter = filter.getProperties()[0]; + typeToFilter.setValue(sparqlRequestEditor.getQueryText()); + + } + + @Override + public void actionPerformed(ActionEvent e) { + updateFilterValue(); + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/type/TypeFilter.java b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/type/TypeFilter.java new file mode 100644 index 0000000000..31d2e07693 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/type/TypeFilter.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ + +package fr.inria.wimmics.semanticweb.filter.type; + +import fr.inria.edelweiss.semantic.SemanticWebImportMainWindowTopComponent; +import java.util.Formatter; +import java.util.HashSet; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.gephi.filters.spi.ComplexFilter; +import org.gephi.filters.spi.FilterProperty; +import org.gephi.graph.api.Graph; +import org.gephi.graph.api.Node; + +/** + * + * @author Erwan Demairy + */ +public class TypeFilter implements ComplexFilter { + + private Logger logger = Logger.getLogger(TypeFilter.class.getName()); + private String type; + + public TypeFilter() { + } + + @Override + public String getName() { + return "Node Type Filter"; + } + + @Override + public FilterProperty[] getProperties() { + FilterProperty[] result = new FilterProperty[0]; + try { + result = new FilterProperty[]{FilterProperty.createProperty(this, String.class, "type", "getType", "setType")}; + } catch (NoSuchMethodException ex) { + Logger.getLogger(TypeFilter.class.getName()).log(Level.SEVERE, null, ex); + } + return result; + } + + public String getType() { + return type; + } + + public void setType(String newType) { + type = newType; + } + static public String GET_SUBTYPES_OF = + "select ?x where { " + + "{" + + "?x rdf:type ?t . " + + "?t rdfs:subClassOf ?u " + + "} " + + "Union " + + "{" + + "?x rdf:type ?u " + + "} " + + "Filter(?u ~ \"%s\") " + + "}"; + + @Override + public Graph filter(Graph graph) { + try (Formatter getSubtypesOfrequest = new Formatter().format(GET_SUBTYPES_OF, type)) { + + String[][] nodesToKeepList = SemanticWebImportMainWindowTopComponent.getSparqlRequester().selectOnGraph(getSubtypesOfrequest.toString()); + HashSet nodesToKeepSet = convertStringArrayToSet(nodesToKeepList); + + Node[] nodes = graph.getNodes().toArray(); + for (Node node : nodes) { + if (!nodesToKeepSet.contains((String) node.getId())) { + graph.removeNode(node); + } + } + } + return graph; + } + + private HashSet convertStringArrayToSet(String[][] listNodes) { + HashSet result = new HashSet(); + for (int i = 0; i < listNodes.length; ++i) { + result.add(listNodes[i][0]); + } + return result; + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/type/TypeFilterBuilder.java b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/type/TypeFilterBuilder.java new file mode 100644 index 0000000000..9232311239 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/type/TypeFilterBuilder.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.wimmics.semanticweb.filter.type; + +import fr.inria.edelweiss.semantic.SemanticWebImportMainWindowTopComponent; +import javax.swing.Icon; +import javax.swing.JPanel; + +import org.gephi.filters.spi.Category; +import org.gephi.filters.spi.Filter; +import org.gephi.filters.spi.FilterBuilder; +import org.gephi.project.api.Workspace; +import org.openide.util.lookup.ServiceProvider; + +/** + * Class responsible for building a new semanticweb filter. + * + * @author Erwan Demairy + */ +@ServiceProvider(service = FilterBuilder.class) +public class TypeFilterBuilder implements FilterBuilder { + + @Override + public Category getCategory() { + return new Category("SemanticWeb", getIcon()); + +// return FilterLibrary.ATTRIBUTES; + } + + @Override + public String getName() { + return "Node Type Filter"; + } + + @Override + public Icon getIcon() { + return SemanticWebImportMainWindowTopComponent.loadIcon(); + } + + @Override + public String getDescription() { + return "Returns the nodes having a type matching, as a regexp, the string given as argument."; + } + + @Override + public Filter getFilter(Workspace workspace) { + return new TypeFilter(); + } + + @Override + public JPanel getPanel(Filter filter) { + TypeFilter semanticWebFilter = (TypeFilter) filter; + return new TypeFilterPanel(semanticWebFilter); + } + + public void destroy(Filter filter) { + } +} diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/type/TypeFilterPanel.form b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/type/TypeFilterPanel.form new file mode 100644 index 0000000000..5dfc78458e --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/type/TypeFilterPanel.form @@ -0,0 +1,57 @@ + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    diff --git a/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/type/TypeFilterPanel.java b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/type/TypeFilterPanel.java new file mode 100644 index 0000000000..eb7e5e2765 --- /dev/null +++ b/modules/SemanticWebImport/src/main/java/fr/inria/wimmics/semanticweb/filter/type/TypeFilterPanel.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2011, INRIA + * All rights reserved. + */ +package fr.inria.wimmics.semanticweb.filter.type; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import org.gephi.filters.spi.FilterProperty; + +/** + * + * @author Erwan Demairy + */ +public class TypeFilterPanel extends javax.swing.JPanel implements ActionListener { + + private static final long serialVersionUID = 488283956724990955L; + private final TypeFilter filter; + + public TypeFilterPanel(TypeFilter filter) { + this.filter = filter; + initComponents(); + typeField.addActionListener(this); + } + + @Override + public void actionPerformed(ActionEvent e) { + FilterProperty typeToFilter = filter.getProperties()[0]; + typeToFilter.setValue(typeField.getText()); + } + + /** + * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + typeField = new javax.swing.JTextField(); + jLabel1 = new javax.swing.JLabel(); + + typeField.setText(org.openide.util.NbBundle.getMessage(TypeFilterPanel.class, "TypeFilterPanel.typeField.text")); // NOI18N + + jLabel1.setText(org.openide.util.NbBundle.getMessage(TypeFilterPanel.class, "TypeFilterPanel.jLabel1.text")); // NOI18N + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(typeField, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(typeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel1)) + .addContainerGap()) + ); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel jLabel1; + private javax.swing.JTextField typeField; + // End of variables declaration//GEN-END:variables +} diff --git a/modules/SemanticWebImport/src/main/nbm/manifest.mf b/modules/SemanticWebImport/src/main/nbm/manifest.mf new file mode 100644 index 0000000000..883462665e --- /dev/null +++ b/modules/SemanticWebImport/src/main/nbm/manifest.mf @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module-Name: SemanticWebImport +OpenIDE-Module-Short-Description: Allow to configure the view of rdf and rdfs files. +OpenIDE-Module-Long-Description: The purpose of this plugin is: +OpenIDE-Module-Display-Category: Import diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/autolayout.py b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/autolayout.py new file mode 100644 index 0000000000..c605db10c5 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/autolayout.py @@ -0,0 +1,44 @@ +import org.openide.util.Lookup as Lookup +import org.gephi.ranking.api.RankingController +import org.gephi.ranking.api.Ranking as Ranking +import org.gephi.ranking.api.Transformer as Transformer +import java.awt.Color as Color + + +rankingController = Lookup.getDefault().lookup(org.gephi.ranking.api.RankingController) + +# Set the color in function of the degree. +degreeRanking = rankingController.getModel().getRanking(Ranking.NODE_ELEMENT, Ranking.DEGREE_RANKING); +colorTransformer = rankingController.getModel().getTransformer(Ranking.NODE_ELEMENT, Transformer.RENDERABLE_COLOR) +colorTransformer.setColors([Color.BLUE, Color.YELLOW]) + +rankingController.transform(degreeRanking, colorTransformer) + +# Set the size in function of the degree of the nodes. +sizeTransformer = rankingController.getModel().getTransformer(Ranking.NODE_ELEMENT, Transformer.RENDERABLE_SIZE) +sizeTransformer.setMinSize(3) +sizeTransformer.setMaxSize(40) +rankingController.transform(degreeRanking, sizeTransformer) + + +### Layout of the graph +# Construction of a layout object +import org.gephi.layout.plugin.forceAtlas2.ForceAtlas2Builder as ForceAtlas2Builder +import org.gephi.layout.plugin.forceAtlas2.ForceAtlas2 as ForceAtlas2 +fa2builder = ForceAtlas2Builder() +fa2 = ForceAtlas2(fa2builder) + +# Setting the layout object +import org.gephi.graph.api.GraphController as GraphController +graphModel = Lookup.getDefault().lookup(GraphController).getModel() +fa2.setGraphModel(graphModel) +fa2.setAdjustSizes(True) # To prevent overlap + +print("executing layout") +# Run the layout. +fa2.initAlgo() +for i in range(5000): + fa2.goAlgo() + + + diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/autolayout3D.py b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/autolayout3D.py new file mode 100644 index 0000000000..0e66986738 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/autolayout3D.py @@ -0,0 +1,51 @@ +import org.openide.util.Lookup as Lookup +import org.gephi.ranking.api.RankingController +import org.gephi.ranking.api.Ranking as Ranking +import org.gephi.ranking.api.Transformer as Transformer +import java.awt.Color as Color + + +rankingController = Lookup.getDefault().lookup(org.gephi.ranking.api.RankingController) + +# Set the color in function of the degree. +degreeRanking = rankingController.getModel().getRanking(Ranking.NODE_ELEMENT, Ranking.DEGREE_RANKING); +colorTransformer = rankingController.getModel().getTransformer(Ranking.NODE_ELEMENT, Transformer.RENDERABLE_COLOR) +colorTransformer.setColors([Color.BLUE, Color.YELLOW]) + +rankingController.transform(degreeRanking, colorTransformer) + +# Set the size in function of the degree of the nodes. +sizeTransformer = rankingController.getModel().getTransformer(Ranking.NODE_ELEMENT, Transformer.RENDERABLE_SIZE) +sizeTransformer.setMinSize(3) +sizeTransformer.setMaxSize(40) +rankingController.transform(degreeRanking, sizeTransformer) + + +### Layout of the graph +# Construction of a layout object +import org.gephi.layout.plugin.forceAtlas2.ForceAtlas2Builder as ForceAtlas2Builder +import org.gephi.layout.plugin.forceAtlas2.ForceAtlas2 as ForceAtlas2 +fa2builder = ForceAtlas2Builder() +fa2 = ForceAtlas2(fa2builder) + +# Setting the layout object +import org.gephi.graph.api.GraphController as GraphController +graphModel = Lookup.getDefault().lookup(GraphController).getModel() +fa2.setGraphModel(graphModel) +fa2.setAdjustSizes(True) # To prevent overlap + +print("setting z coordinates") +### Setting a random z coordinate on each node +import random +graph = graphModel.getGraph() +for n in graph.getNodes(): + n.getNodeData().setZ(graph.getDegree(n)*10) + +print("executing layout") +# Run the layout. +fa2.initAlgo() +for i in range(5000): + fa2.goAlgo() + + + diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/human_2007_09_11.rdf b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/human_2007_09_11.rdf new file mode 100644 index 0000000000..76bbf41e98 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/human_2007_09_11.rdf @@ -0,0 +1,139 @@ + + + ]> + + + + + Harry + + + + + + + John + 14 + 37 + + + + Mark + 8 + 14 + 9 + 36 + + + + + + + Eve + + + + + + + David + + + + + Alice + + + + + + Jack + + + + 95 + + + Flora + + + + + Laura + + + + + Jennifer + + + + 7 + 28 + 12 + 8 + Lucas + + + + + + 11 + 38 + 102 + 12 + Gaston + + + + + + + + + 10 + 42 + 46 + 13 + William + + + + 8 + 71 + 30 + 9 + Pierre + + + + + + 7 + 36 + 9 + 40 + + + + + + + + + Laura + + + + 12 + 44 + + + + \ No newline at end of file diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/human_2007_09_11.rdfs b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/human_2007_09_11.rdfs new file mode 100644 index 0000000000..dd532d2a1e --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/human_2007_09_11.rdfs @@ -0,0 +1,208 @@ + + + + ]> + + + + + + a living organism characterized by voluntary movement. + + être vivant doué de sensibilite de mobilité. + + + + + + an animal that produces gametes (spermatozoa) that can fertilize female gametes (ova). + + individu appartenant au sexe qui possède le pouvoir de fécondation. + + + + + + an animal that produces gametes (ova) that can be fertilized by male gametes (spermatozoa). + + animal appartenant au sexe apte à produire des ovules. + + + + + + + an adult male person + + mâle adulte de l'espèce humaine. + + + + + + + + a member of the human species + + + + + un membre de l'espèce humaine. + + + + + + someone who lectures professionally + + personne qui enseigne une discipline, une technique, un art. + + + + + + + + a person who devotes himself to doing research + + + personne adonnée à des recherches spécialisées. + + + + + + + an adult female person + + femelle adulte de l'espèce humaine. + + + + + + + relation between an animal and another animal from which it is descended. + + relation entre un animal et un autre animal duquel il descend. + + + + + + relation between an animal and another animal which gave birth to it. + + relation entre un animal et un autre animal qui lui a donné naissance. + + + + + relation between an animal and another animal to which it gave birth. + + relation entre un animal et un autre animal auquel il a donné naissance. + + + + + + + to have for parent a male. + + avoir pour parent un mâle. + + + + + + + to have for parent a female. + + avoir pour parent un femmelle. + + + + + + + relation with a male who has the same parents. + + relation avec un mâle ayant les mêmes parents. + + + + + + + relation with a female who has the same parents. + + relation avec une femelle ayant les mêmes parents. + + + + + + + relation between a person and another person he or she knows well and regards with affection and trust. + + relation entre une personne et une autre personne qui est l'objet d'un attachement privilégié. + + + + + + designation of something. + désignation de quelque chose. + + + + + + + + express in some way the approximate length of the shoes for a person. + taille, exprimée en points, des chaussures d'une personne. + + + + + + complete existence duration. + durée complète d'existence. + + + + + + + + + express in some way the approximate dimensions of the shirts of a person. + dimensions approximatives des chemises portées par une personne. + + + + + + + + + express in some way the approximate dimensions of the trousers of a person. + dimensions approximatives des pantalons portés par une personne. + + + + + + + + a person's partner in marriage. + le partenaire d'une personne dans un mariage. + + + + diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/human_2007_09_11.rul b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/human_2007_09_11.rul new file mode 100644 index 0000000000..30a6e68626 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/human_2007_09_11.rul @@ -0,0 +1,26 @@ + + + + + + +]> + + + + + + PREFIX humans: <&humans;> + { ?x rdf:type humans:Male + ?x rdf:type humans:Person } + + + + { ?x rdf:type humans:Man } + + + + + \ No newline at end of file diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/humans_autolayout.xml b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/humans_autolayout.xml new file mode 100644 index 0000000000..51ab769997 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/examples/humans_autolayout.xml @@ -0,0 +1,15 @@ + + + +Properties to save. +HumansAndAutoLayout +construct{ + ?x ?r ?y +} where { + ?x ?r ?y +} + +/fr/inria/edelweiss/examples/autolayout.py +fr.inria.edelweiss.sparql.corese.CoreseDriver +/fr/inria/edelweiss/examples/human_2007_09_11.rdf;/fr/inria/edelweiss/examples/human_2007_09_11.rdfs;/fr/inria/edelweiss/examples/human_2007_09_11.rul; + diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/resources/semantic_web_icon.png b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/resources/semantic_web_icon.png new file mode 100644 index 0000000000..310bb170c2 Binary files /dev/null and b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/resources/semantic_web_icon.png differ diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/resources/semantic_web_icon_16.png b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/resources/semantic_web_icon_16.png new file mode 100644 index 0000000000..60f797dee9 Binary files /dev/null and b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/resources/semantic_web_icon_16.png differ diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/Bundle.properties b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/Bundle.properties new file mode 100644 index 0000000000..cbe70e1f28 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/Bundle.properties @@ -0,0 +1,61 @@ +CTL_SemanticWebImportMainWindowAction=SemanticWebImport +CTL_SemanticWebImportMainWindowTopComponent=Semantic Web Import +CTL_testAction=test +HINT_SemanticWebImportMainWindowTopComponent=This is a SemanticWebImportMainWindow window +OpenIDE-Module-Display-Category=Import +OpenIDE-Module-Long-Description=\ + The purpose of this plugin is:\n1. to be able to read .rdfs, .rul and .rdf files;\n2. display the ontology (.rdf);\n3. display the graph of the .rdf, according to the parameters set on the types and relations defined by the ontology. +OpenIDE-Module-Name=SemanticWebImport +OpenIDE-Module-Short-Description=Allow to configure the view of rdf and rdfs files. +SemanticWebImportMainWindowTopComponent.startSemanticWebImport.AccessibleContext.accessibleName=start +SemanticWebImportMainWindowTopComponent.jTabbedPane1.AccessibleContext.accessibleName=tab1 +NodeParametersDialog.cancelButton.text=Cancel +NodeParametersDialog.gTextField.text= +NodeParametersDialog.bTextField.text= +NodeParametersDialog.aTextField.text= +NodeParametersDialog.rTextField.text= +NodeParametersDialog.rLabel.text=R +NodeParametersDialog.gLabel.text=G +NodeParametersDialog.bLabel.text=B +NodeParametersDialog.aLabel.text=A +NodeParametersDialog.sizeTextField.text= +NodeParametersDialog.sizeLabel.text=size +NodeParametersDialog.okButton.text=OK +SemanticWebImportMainWindowTopComponent.rdfFileChooserButton.AccessibleContext.accessibleDescription=Add a new RDF resource +SemanticWebImportMainWindowTopComponent.rulFileChooserButton.AccessibleContext.accessibleDescription=Remove the selected resources from the list +testTopComponent.jButton1.text=jButton1 +testTopComponent.jButton2.text=jButton2 +SemanticWebImportMainWindowTopComponent.jScrollPane1.AccessibleContext.accessibleName= +SemanticWebImportMainWindowTopComponent.sparqlDriverLabel.text=SPARQL Driver +SemanticWebImportMainWindowTopComponent.sparqlQueryResultButton.text=set filename +SemanticWebImportMainWindowTopComponent.sparqlQueryResultFileName.text= +SemanticWebImportMainWindowTopComponent.sparqlQueryResultLabel.text=SPARQL Query Result Output +SemanticWebImportMainWindowTopComponent.sparqlQueryResultFileName.toolTipText=Let empty if you do not want to store the result. +SemanticWebImportMainWindowTopComponent.saveConfiguration.toolTipText=Save current configuration in a file +SemanticWebImportMainWindowTopComponent.saveConfiguration.text=Save Configuration +SemanticWebImportMainWindowTopComponent.sparqlRequestLabel.text=SPARQL Query +SemanticWebImportMainWindowTopComponent.autoLayout.text=Apply autolayout +SemanticWebImportMainWindowTopComponent.start.text=Run +SemanticWebImportMainWindowTopComponent.resetWorkspace.text=Reset the workspace +SemanticWebImportMainWindowTopComponent.driverSelectorPanel.TabConstraints.tabTitle=Driver +SemanticWebImportMainWindowTopComponent.sparqlEditorPanel.TabConstraints.tabTitle=Query +SemanticWebImportMainWindowTopComponent.configurationPanel.TabConstraints.tabTitle=Configurations +SemanticWebImportMainWindowTopComponent.graphBuilderTab.toolTipText= +SemanticWebImportMainWindowTopComponent.logPanel.TabConstraints.tabTitle=Log +SemanticWebImportMainWindowTopComponent.start.toolTipText=Make a request with the selected driver. +SemanticWebImportMainWindowTopComponent.ignoreBlankNode.toolTipText= +SemanticWebImportMainWindowTopComponent.ignoreBlankNode.text=ignore blank nodes +SemanticWebImportMainWindowTopComponent.saveConfiguration.actionCommand=Save +SemanticWebImportMainWindowTopComponent.setConfiguration.toolTipText=Set the parameters using a loaded configuration. +SemanticWebImportMainWindowTopComponent.setConfiguration.text=Set Configuration +SemanticWebImportMainWindowTopComponent.loadConfiguration.toolTipText=Load a configuration file. +SemanticWebImportMainWindowTopComponent.loadConfiguration.text=Load Configuration +SemanticWebImportMainWindowTopComponent.saveConfigurationNameTextField.text= +SemanticWebImportMainWindowTopComponent.fynLabel.text=Follow your nose level of recursion +SemanticWebImportMainWindowTopComponent.pythonPreProcessingLabel.text=Python pre-processing script +SemanticWebImportMainWindowTopComponent.pythonPostProcessingLabel.text=Python post-processing script +SemanticWebImportMainWindowTopComponent.pythonPreProcessingFileName.text= +SemanticWebImportMainWindowTopComponent.pythonPostProcessingFileName.text= +SemanticWebImportMainWindowTopComponent.label=set +SemanticWebImportMainWindowTopComponent.setPythonPreProcessingFileName.text=set +SemanticWebImportMainWindowTopComponent.setPythonPostProcessingFileName.text=set diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/default_configuration/DBPedia.xml b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/default_configuration/DBPedia.xml new file mode 100644 index 0000000000..223049cbb5 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/default_configuration/DBPedia.xml @@ -0,0 +1,16 @@ + + + +SparqlDriver +DBPedia +construct{ + ?x ?r ?y +} where { + ?x ?r ?y +} + limit 100 +https://dbpedia.org/sparql +fr.inria.edelweiss.sparql.restdriver.SparqlRestEndPointDriver +query + + diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/default_configuration/DBPediaMovies.xml b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/default_configuration/DBPediaMovies.xml new file mode 100644 index 0000000000..d8d159f6b6 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/default_configuration/DBPediaMovies.xml @@ -0,0 +1,27 @@ + + + +SparqlDriver +DBPediaMovies +# "node gephi:attr v" defines a column named ddattr for the nodes +# and set v as its value for node. +prefix gephi:<http://gephi.org/> +CONSTRUCT{ + ?film gephi:label ?title . + ?film gephi:category "film" . + ?director gephi:category "director" . + ?actor gephi:category "actor" . + ?film <http://dbpedia.org/ontology/director> ?director . + ?film <http://dbpedia.org/ontology/starring> ?actor +} WHERE { + ?film rdfs:label ?title . + ?film <http://dbpedia.org/ontology/director> ?director . + ?film <http://dbpedia.org/ontology/starring> ?actor + FILTER(lang(?title)="en") +} LIMIT 1000 +https://dbpedia.org/sparql +fr.inria.edelweiss.sparql.restdriver.SparqlRestEndPointDriver +query + + + diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/default_configuration/Humans.xml b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/default_configuration/Humans.xml new file mode 100644 index 0000000000..fc91be2b83 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/default_configuration/Humans.xml @@ -0,0 +1,13 @@ + + + +SparqlDriver +Humans +construct{ + ?x ?r ?y +} where { + ?x ?r ?y +} +fr.inria.edelweiss.sparql.corese.CoreseDriver +/fr/inria/edelweiss/examples/human_2007_09_11.rdf;/fr/inria/edelweiss/examples/human_2007_09_11.rdfs;/fr/inria/edelweiss/examples/human_2007_09_11.rul + diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/default_configuration/bio2rdf_rest.xml b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/default_configuration/bio2rdf_rest.xml new file mode 100644 index 0000000000..baa04623fb --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/default_configuration/bio2rdf_rest.xml @@ -0,0 +1,14 @@ + + + +Properties to save. +Example - REST services access +query +construct { +?x ?r ?y +} where { +?x ?r ?y +} limit 100 +https://bio2rdf.org/sparql +fr.inria.edelweiss.sparql.restdriver.SparqlRestEndPointDriver + diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/gui/Bundle.properties b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/gui/Bundle.properties new file mode 100644 index 0000000000..d3e073d172 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/gui/Bundle.properties @@ -0,0 +1,6 @@ +SparqlEndPointPanel.okButton.text=OK +SparqlEndPointPanel.urlLabel.text=EndPoint URL +SparqlEndPointPanel.cancelButton.text=Cancel +SparqlEndPointPanel.urlTextField.text=urlTextField +SparqlEndPointPanel.jLabel1.text=Local SPARQL Driver +SparqlEndPointPanel.okButton.actionCommand=OK diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/importer/Bundle.properties b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/importer/Bundle.properties new file mode 100644 index 0000000000..b7e4b5d91f --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/importer/Bundle.properties @@ -0,0 +1,2 @@ +SemanticWebImporterDialog.cancel.text=cancel +SemanticWebImporterDialog.ok.text=ok diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/importer/package.html b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/importer/package.html new file mode 100644 index 0000000000..6dd630dc11 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/importer/package.html @@ -0,0 +1,29 @@ + + + + + + + +

    Package Specification

    + The importer is architected the following way:
    +
      +
    1. the @see SemanticWebImportBuilder is the factory used register + the association between a file extension and an Importer.
    2. +
    3. SemanticWebImporter is the import class;
    4. +
    5. SemanticWebImporterUI allows the user to parameterize the + import.
    6. +
    7. SemanticWebImportParser @todo
    8. +
    9. SemanticWebImportParser.RequestParameters @todo
      +
    10. +
    +
      +
    +

    Related Documentation

    +

    @see http://wiki.gephi.org/index.php/HowTo_write_an_import +

    +
    +
    + + diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/statistics/Bundle.properties b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/statistics/Bundle.properties new file mode 100644 index 0000000000..09921c5518 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/semantic/statistics/Bundle.properties @@ -0,0 +1 @@ +OpenIDE-Module-Name=SemanticWebStatistics diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/sparql/Bundle.properties b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/sparql/Bundle.properties new file mode 100644 index 0000000000..534f9f0475 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/sparql/Bundle.properties @@ -0,0 +1,2 @@ +SparqlEndPointParameters.title=SPARQL End Point Parameters +SparqlRestEndPointParametersPanel.jTable1.columnModel.title3=Title 4 diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/sparql/corese/Bundle.properties b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/sparql/corese/Bundle.properties new file mode 100644 index 0000000000..02280e2292 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/sparql/corese/Bundle.properties @@ -0,0 +1,8 @@ +CoreseDriverParametersPanel.toolTipText=Parameters for the Corese driver +CoreseDriverParametersPanel.+.label=+ +CoreseDriverParametersPanel.+.actionCommand=changeRDFfilename +CoreseDriverParametersPanel.-.label=- +CoreseDriverParametersPanel.-.actionCommand=changeRDFfilename +CoreseDriverParametersPanel.rdfResourcesLabel.text=RDF resources list +CoreseDriverParametersPanel.addUrl.text=+URL +CoreseDriverParametersPanel.urlField.text= diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/sparql/restdriver/Bundle.properties b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/sparql/restdriver/Bundle.properties new file mode 100644 index 0000000000..de408202f3 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/sparql/restdriver/Bundle.properties @@ -0,0 +1,17 @@ + +SparqlRestEndPointDriverParametersPanel.jLabel1.text=query tag name +SparqlRestEndPointDriverParametersPanel.queryTagName.text=query +SparqlRestEndPointDriverParametersPanel.removeTagButton.text=- +SparqlRestEndPointDriverParametersPanel.newParameterRestValue.text=REST value +SparqlRestEndPointDriverParametersPanel.removePropertyButton.text=- +SparqlRestEndPointDriverParametersPanel.newParameterRestName.text=REST name +SparqlRestEndPointDriverParametersPanel.urlTextField.text=http:// +SparqlRestEndPointDriverParametersPanel.restParametersTable.columnModel.title1=nullr +SparqlRestEndPointDriverParametersPanel.restParametersTable.columnModel.title0=nurll +SparqlRestEndPointDriverParametersPanel.newPropertyName.text=Property Name +SparqlRestEndPointDriverParametersPanel.addTagButton.text=+ +SparqlRestEndPointDriverParametersPanel.newPropertyValue.text=Property value +SparqlRestEndPointDriverParametersPanel.urlLabel1.text=EndPoint URL +SparqlRestEndPointDriverParametersPanel.addPropertyButton.text=+ +SparqlRestEndPointParametersPanel.restParametersTable.columnModel.title0=nullr +SparqlRestEndPointParametersPanel.restParametersTable.columnModel.title1=nullr diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/sparql/soap/Bundle.properties b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/sparql/soap/Bundle.properties new file mode 100644 index 0000000000..029e16448c --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/edelweiss/sparql/soap/Bundle.properties @@ -0,0 +1,3 @@ + +SparqlSoapEndPointDriverParametersPanel.urlTextField.text=urlTextField +SparqlSoapEndPointDriverParametersPanel.urlLabel.text=EndPoint URL diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/wimmics/semanticweb/filter/sparql/Bundle.properties b/modules/SemanticWebImport/src/main/resources/fr/inria/wimmics/semanticweb/filter/sparql/Bundle.properties new file mode 100644 index 0000000000..7b8a497059 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/wimmics/semanticweb/filter/sparql/Bundle.properties @@ -0,0 +1,5 @@ +OpenIDE-Module-Name=SemanticWebFilter +SPARQLFilterPanel.typeField.text= +SPARQLFilterPanel.jLabel1.text=Select request: +SPARQLFilterPanel.queryText=select distinct ?Concept \nwhere {\n [] a ?Concept\n}\nlimit 100 +SPARQLFilterPanel.updateButton.text=update diff --git a/modules/SemanticWebImport/src/main/resources/fr/inria/wimmics/semanticweb/filter/type/Bundle.properties b/modules/SemanticWebImport/src/main/resources/fr/inria/wimmics/semanticweb/filter/type/Bundle.properties new file mode 100644 index 0000000000..3dfa62c625 --- /dev/null +++ b/modules/SemanticWebImport/src/main/resources/fr/inria/wimmics/semanticweb/filter/type/Bundle.properties @@ -0,0 +1,3 @@ +OpenIDE-Module-Name=SemanticWebFilter +TypeFilterPanel.typeField.text= +TypeFilterPanel.jLabel1.text=Node Type to filter: diff --git a/nbproject/private/platform-private.properties b/nbproject/private/platform-private.properties new file mode 100644 index 0000000000..5044fbd835 --- /dev/null +++ b/nbproject/private/platform-private.properties @@ -0,0 +1 @@ +user.properties.file=/Users/edemairy/Library/Application Support/NetBeans/8.1/build.properties diff --git a/pom.xml b/pom.xml index afb8f2bf5d..d0a530df23 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ + modules/SemanticWebImport @@ -99,7 +100,7 @@ - + @@ -125,7 +126,7 @@ - + org.apache.maven.plugins @@ -149,7 +150,7 @@ - + org.apache.netbeans.utilities