IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Frameworks Discussion :

fonction extension sparql


Sujet :

Frameworks

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Femme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2015
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 32
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2015
    Messages : 12
    Points : 13
    Points
    13
    Par défaut fonction extension sparql
    Salut,
    je veux ajouter une fonction extension filter dans le grammaire sparql ,

    code de fonction:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    package project;
     
    import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
    import com.hp.hpl.jena.rdf.model.Model;
    import com.hp.hpl.jena.rdf.model.ModelFactory;
    import com.hp.hpl.jena.rdf.model.StmtIterator;
    import com.hp.hpl.jena.sparql.expr.NodeValue;
    import com.hp.hpl.jena.sparql.expr.nodevalue.XSDFuncOp;
    import com.hp.hpl.jena.sparql.function.FunctionBase0;
    import com.hp.hpl.jena.sparql.function.FunctionBase2;
    import com.hp.hpl.jena.sparql.function.FunctionFactory;
    import com.hp.hpl.jena.vocabulary.RDFS;
    import com.hp.hpl.jena.rdf.model.*;
    import com.hp.hpl.jena.util.FileManager;
    import com.hp.hpl.jena.vocabulary.*;
     
    import java.io.*;
    import java.util.HashMap;
    public abstract class haschild extends FunctionBase2 implements FunctionFactory{
    	public NodeValue exec(NodeValue per,String ch) throws FileNotFoundException{
    	Model model = ModelFactory.createDefaultModel();
    	InputStream is = new BufferedInputStream(
    	           new FileInputStream(
    	           "c:/Users/toshibasat/Downloads/SNjournal.webscience.org-vivo.rdf"));
    	 model.read(new InputStreamReader(is), "");
     
     
    	 StmtIterator it=model.listStatements();
    	               while (it.hasNext()){
    	            Statement p=it.next();
     
    	            Property prop = p.getPredicate(  );
    	             Resource res2 = p.getSubject(  );
     
    	                // Get object 
    	                RDFNode node =p.getObject(  );
    	                if((per==res2)||(node.toString()==ch)||(prop.toString()=="HasChild")) 
    	                return NodeValue.makeNode("true", XSDDatatype.XSDboolean);
     
     
    }
    	               return NodeValue.makeNode("false", XSDDatatype.XSDboolean);}
    	}
    code de l'enregistrement de la fonction:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    FunctionRegistry.get().put("http://jena.hpl.hp.com/ARQ/function#haschild",haschild.class);
    j'ai écrire cette requête :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    PREFIX f: <java:app.myFunctions.>
    SELECT * WHERE {?Person foaf:name ?x. FILTER f:haschild(?Person, "Librarian").}
    mais il ne fonctionne pas il affiche ce message d'erreur:
    WARN [AWT-EventQueue-0] (Log.java:63) - Class not found: app.myFunctions.haschild
    WARN [AWT-EventQueue-0] (E_Function.java:77) - URI <java:app.myFunctions.haschild> has no registered function factory
    Question: Quelle est le problème?

  2. #2
    Membre éprouvé
    Avatar de Sapience
    Homme Profil pro
    Consultant sémantique & data à sparna.fr
    Inscrit en
    Avril 2005
    Messages
    305
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Consultant sémantique & data à sparna.fr
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2005
    Messages : 305
    Points : 915
    Points
    915
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Class not found: app.myFunctions.haschild
    Visiblement la classe est attendue dans le package app.myFunctions.

    Mais apparemment ta classe est déclarée dans le package "project". Donc soit tu ajustes le package de ta fonction, soit tu modifies le PREFIX de la requête SPARQL.

  3. #3
    Membre à l'essai
    Femme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2015
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 32
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2015
    Messages : 12
    Points : 13
    Points
    13
    Par défaut erreur
    Salut,
    oui c'est vrai , j'ai modifiée le prefix "PREFIX f: <java:project.>" mais il ne marche pas:
    l'erreur qui afficher:
    Exception in thread "AWT-EventQueue-0" com.hp.hpl.jena.query.QueryBuildException: Can't instantiate function for java:project.haschild
    at com.hp.hpl.jena.sparql.function.FunctionFactoryAuto.create(FunctionFactoryAuto.java:29)
    at com.hp.hpl.jena.sparql.expr.E_Function.bindFunction(E_Function.java:94)
    at com.hp.hpl.jena.sparql.expr.E_Function.buildFunction(E_Function.java:73)
    at com.hp.hpl.jena.sparql.expr.ExprBuild.visit(ExprBuild.java:29)
    at com.hp.hpl.jena.sparql.expr.ExprFunctionN.visit(ExprFunctionN.java:109)
    at com.hp.hpl.jena.sparql.expr.ExprWalker$Walker.visitExprFunction(ExprWalker.java:55)
    at com.hp.hpl.jena.sparql.expr.ExprVisitorFunction.visit(ExprVisitorFunction.java:15)
    at com.hp.hpl.jena.sparql.expr.ExprFunctionN.visit(ExprFunctionN.java:109)
    at com.hp.hpl.jena.sparql.expr.ExprWalker.walk(ExprWalker.java:22)
    at com.hp.hpl.jena.sparql.expr.ExprList.prepareExprs(ExprList.java:86)
    at com.hp.hpl.jena.sparql.algebra.optimize.OpVisitorExprPrepare.visit(OpVisitorExprPrepare.java:24)
    at com.hp.hpl.jena.sparql.algebra.op.OpFilter.visit(OpFilter.java:96)
    at com.hp.hpl.jena.sparql.algebra.OpWalker$WalkerVisitor.visit1(OpWalker.java:85)
    at com.hp.hpl.jena.sparql.algebra.OpVisitorByType.visit(OpVisitorByType.java:71)
    at com.hp.hpl.jena.sparql.algebra.op.OpFilter.visit(OpFilter.java:96)
    at com.hp.hpl.jena.sparql.algebra.OpWalker.walk(OpWalker.java:35)
    at com.hp.hpl.jena.sparql.algebra.OpWalker.walk(OpWalker.java:25)
    at com.hp.hpl.jena.sparql.algebra.optimize.Optimize.rewrite(Optimize.java:138)
    at com.hp.hpl.jena.sparql.algebra.optimize.Optimize.optimize(Optimize.java:67)
    at com.hp.hpl.jena.sparql.algebra.Algebra.optimize(Algebra.java:53)
    at com.hp.hpl.jena.sparql.engine.main.QueryEngineMain.modifyOp(QueryEngineMain.java:72)
    at com.hp.hpl.jena.sparql.engine.QueryEngineBase.createPlan(QueryEngineBase.java:104)
    at com.hp.hpl.jena.sparql.engine.QueryEngineBase.getPlan(QueryEngineBase.java:97)
    at com.hp.hpl.jena.sparql.engine.main.QueryEngineMain$1.create(QueryEngineMain.java:91)
    at com.hp.hpl.jena.sparql.engine.QueryExecutionBase.getPlan(QueryExecutionBase.java:426)
    at com.hp.hpl.jena.sparql.engine.QueryExecutionBase.startQueryIterator(QueryExecutionBase.java:400)
    at com.hp.hpl.jena.sparql.engine.QueryExecutionBase.execResultSet(QueryExecutionBase.java:408)
    at com.hp.hpl.jena.sparql.engine.QueryExecutionBase.execSelect(QueryExecutionBase.java:135)
    at project.frame$2.actionPerformed(frame.java:138)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.InstantiationException
    at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at com.hp.hpl.jena.sparql.function.FunctionFactoryAuto.create(FunctionFactoryAuto.java:26)
    ... 65 more

  4. #4
    Membre éprouvé
    Avatar de Sapience
    Homme Profil pro
    Consultant sémantique & data à sparna.fr
    Inscrit en
    Avril 2005
    Messages
    305
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Consultant sémantique & data à sparna.fr
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2005
    Messages : 305
    Points : 915
    Points
    915
    Par défaut
    Ta classe est déclarée "abstract" et ne peut pas être instanciée. D'où l'exception.

  5. #5
    Membre à l'essai
    Femme Profil pro
    Chercheur en informatique
    Inscrit en
    Mars 2015
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 32
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2015
    Messages : 12
    Points : 13
    Points
    13
    Par défaut erreur
    j'ai un autre problème
    ma requête :
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    SELECT *  WHERE {?Person foaf:name ?x. FILTER(f:haschild(?Person, "Librarian")). }
    Erreur:
    WARN [AWT-EventQueue-0] (Log.java:73) - General exception in <java:project.haschild>(?Person, "Librarian")
    com.hp.hpl.jena.sparql.ARQInternalErrorException
    at com.hp.hpl.jena.sparql.expr.E_Function.eval(E_Function.java:67)
    at com.hp.hpl.jena.sparql.expr.ExprFunctionN.eval(ExprFunctionN.java:103)
    at com.hp.hpl.jena.sparql.expr.ExprFunctionN.eval(ExprFunctionN.java:100)
    at com.hp.hpl.jena.sparql.expr.ExprNode.isSatisfied(ExprNode.java:29)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIterFilterExpr.accept(QueryIterFilterExpr.java:38)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIterProcessBinding.hasNextBinding(QueryIterProcessBinding.java:53)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:86)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:30)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:86)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:30)
    at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:86)
    at com.hp.hpl.jena.sparql.engine.ResultSetStream.hasNext(ResultSetStream.java:57)
    at project.frame$2.actionPerformed(frame.java:139)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

Discussions similaires

  1. [AC-2000] Fonction extensible dans un état
    Par Ach29 dans le forum IHM
    Réponses: 10
    Dernier message: 07/10/2015, 21h25
  2. [Jena] Ajout d'une extension à SPARQL
    Par AbdelhediManel dans le forum Frameworks
    Réponses: 5
    Dernier message: 03/04/2015, 09h30
  3. Ajouter fonction extension solr
    Par calitom dans le forum Langage
    Réponses: 4
    Dernier message: 23/08/2010, 14h37
  4. Delete fichiers fonction extension
    Par jesuismoi dans le forum Scripts/Batch
    Réponses: 2
    Dernier message: 13/04/2010, 11h29
  5. Delete fichier en fonction extension.
    Par jesuismoi dans le forum Scripts/Batch
    Réponses: 1
    Dernier message: 05/04/2010, 14h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo