[Java] Extraire chaine de caractéres fichier

Fermé
ritaing Messages postés 5 Date d'inscription lundi 5 avril 2010 Statut Membre Dernière intervention 11 mai 2010 - Modifié par jipicy le 11/05/2010 à 07:26
ritaing Messages postés 5 Date d'inscription lundi 5 avril 2010 Statut Membre Dernière intervention 11 mai 2010 - 11 mai 2010 à 12:15
salut,

j'ai lu un fichier owl et je voudrais extraire une chaine de caractère de ce fichier et la mettre dans un tableau en java, pour les incorporer à un JComboBox.
Mais même en utilisant la classe readLine et Tokenizer je n'arrive pas à faire l'extraction. Pourriez vous m'aider?
Merci d'avance.
A voir également:

5 réponses

Utilisateur anonyme
10 mai 2010 à 19:22
Salut,

Bien volontiers, mais la question demande à être un peu plus développée:

-Format des lignes lues,
-Ce qu'on doit extraire et mettre dans le tableau qui permettra de créer la JcomboBox,
-La version Java utilisée...

Sans oublier la partie du code concernée.

Cordialement,

Dan
0
ritaing Messages postés 5 Date d'inscription lundi 5 avril 2010 Statut Membre Dernière intervention 11 mai 2010
10 mai 2010 à 22:43
salut,
j'ai lu le fichier owl(exemple:http://osm.cs.byu.edu/CS652s04/ontologies/OWL/carads.owl).

voila la partie du code qui lit et affiche le contenu de fichier ligne par ligne:

private void LoadFile(String fileURL){
try{
BufferedReader buff = new BufferedReader(new FileReader(fileURL));
try {
String line;
while ((line = buff.readLine()) != null) {
System.out.println(line);
}
} finally {
// dans tous les cas, on ferme nos flux
buff.close();
}
} catch (IOException ioe) {
// erreur de fermeture des flux
System.out.println("Erreur --" + ioe.toString());

}
}
je veux extraire les deux chaines (voir le fichier ):maxCardinality et minCardinality, et les mettre dans le tableau qui permettra de créer la JcomboBox,

j'ai utilisé jdk-1.5.

merci.
0
Utilisateur anonyme
11 mai 2010 à 08:31
Salut,

La page : (exemple:http://osm.cs.byu.edu/CS652s04/ontologies/OWL/carads.owl).
n'existe pas.
Le mieux serait que tu me donnes la description de la ligne lue (ce que tu obtiens en lisant une ligne : System.out.println(line); )

Dan
0
ritaing Messages postés 5 Date d'inscription lundi 5 avril 2010 Statut Membre Dernière intervention 11 mai 2010
11 mai 2010 à 12:06
salut
voila le fichier qui se trouve dans la page:
http://osm.cs.byu.edu/CS652s04/ontologies/OWL/carads.owl

<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY carads "http://osm.cs.byu.edu/CS652s04/ontologies/OWL/carads.owl#" >
<!ENTITY example "http://osm.cs.byu.edu/CS652s04/ontologies/annotatedPages/carSrch1_semweb.html#" >
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
]>

<rdf:RDF
xmlns = "&carads;"
xmlns:carads = "&carads;"
xml:base = "&carads;"
xmlns:example = "&example;"
xmlns:owl = "http://www.w3.org/2002/07/owl#"
xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs= "http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema#">

<owl:Ontology rdf:about="">
<rdfs:comment>First OWL ontology example (OWL DL)</rdfs:comment>
<rdfs:label>Car Advistisement Ontology</rdfs:label>
</owl:Ontology>

<owl:Class rdf:ID="CarAds">
<rdfs:label xml:lang="en">CarAds</rdfs:label>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasMake" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">0</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasMake" />
<owl:maxCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:maxCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasMake" />
<owl:allValuesFrom rdf:resource="#Make" />
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasModel" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">0</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasModel" />
<owl:maxCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:maxCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasModel" />
<owl:allValuesFrom rdf:resource="#Model" />
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasYear" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">0</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasYear" />
<owl:maxCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:maxCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasYear" />
<owl:allValuesFrom rdf:resource="#Year" />
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasMileage" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">0</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasMileage" />
<owl:maxCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:maxCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasMileage" />
<owl:allValuesFrom rdf:resource="#Mileage" />
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasPrice" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">0</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasPrice" />
<owl:maxCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:maxCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasPrice" />
<owl:allValuesFrom rdf:resource="#Price" />
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasPhoneNr" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">0</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasPhoneNr" />
<owl:maxCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:maxCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasPhoneNr" />
<owl:allValuesFrom rdf:resource="#PhoneNr" />
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasFeature" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">0</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#hasFeature" />
<owl:allValuesFrom rdf:resource="#Feature" />
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>

<owl:DatatypeProperty rdf:ID="carAdsValue">
<rdfs:domain rdf:resource="#CarAds" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:Class rdf:ID="Make">
<rdfs:label xml:lang="en">Make</rdfs:label>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#makeFor" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#makeFor" />
<owl:allValuesFrom rdf:resource="#CarAds" />
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>

<owl:DatatypeProperty rdf:ID="makeValue">
<rdfs:domain rdf:resource="#Make" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:Class rdf:ID="Model">
<rdfs:label xml:lang="en">Model</rdfs:label>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#modelFor" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#modelFor" />
<owl:allValuesFrom rdf:resource="#CarAds" />
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>

<owl:DatatypeProperty rdf:ID="modelValue">
<rdfs:domain rdf:resource="#Model" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:Class rdf:ID="Year">
<rdfs:label xml:lang="en">Year</rdfs:label>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#yearFor" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#yearFor" />
<owl:allValuesFrom rdf:resource="#CarAds" />
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>

<owl:DatatypeProperty rdf:ID="yearValue">
<rdfs:domain rdf:resource="#Year" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:Class rdf:ID="Mileage">
<rdfs:label xml:lang="en">Mileage</rdfs:label>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#mileageFor" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#mileageFor" />
<owl:allValuesFrom rdf:resource="#CarAds" />
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>

<owl:DatatypeProperty rdf:ID="mileageValue">
<rdfs:domain rdf:resource="#Mileage" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:Class rdf:ID="Price">
<rdfs:label xml:lang="en">Price</rdfs:label>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#priceFor" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#priceFor" />
<owl:allValuesFrom rdf:resource="#CarAds" />
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>

<owl:DatatypeProperty rdf:ID="priceValue">
<rdfs:domain rdf:resource="#Price" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:Class rdf:ID="PhoneNr">
<rdfs:label xml:lang="en">PhoneNr</rdfs:label>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#phoneFor" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#phoneFor" />
<owl:allValuesFrom rdf:resource="#CarAds" />
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>

<owl:DatatypeProperty rdf:ID="phoneNrValue">
<rdfs:domain rdf:resource="#PhoneNr" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>

<owl:Class rdf:ID="Feature">
<rdfs:label xml:lang="en">Feature</rdfs:label>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#featureFor" />
<owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#featureFor" />
<owl:allValuesFrom rdf:resource="#CarAds" />
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>

<owl:DatatypeProperty rdf:ID="featureValue">
<rdfs:domain rdf:resource="#Feature" />
<rdfs:range rdf:resource="&xsd;string" />
</owl:DatatypeProperty>


<owl:ObjectProperty rdf:ID="hasMake">
<rdf:type rdf:resource="&owl;FunctionalProperty" />
<rdfs:domain rdf:resource="#CarAds" />
<rdfs:range rdf:resource="#Make" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="makeFor">
<owl:inverseOf rdf:resource="#hasMake" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="hasModel">
<rdf:type rdf:resource="&owl;FunctionalProperty" />
<rdfs:domain rdf:resource="#CarAds" />
<rdfs:range rdf:resource="#Model" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="modelFor">
<owl:inverseOf rdf:resource="#hasModel" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="hasYear">
<rdf:type rdf:resource="&owl;FunctionalProperty" />
<rdfs:domain rdf:resource="#CarAds" />
<rdfs:range rdf:resource="#Make" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="yearFor">
<owl:inverseOf rdf:resource="#hasYear" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="hasMileage">
<rdf:type rdf:resource="&owl;FunctionalProperty" />
<rdfs:domain rdf:resource="#CarAds" />
<rdfs:range rdf:resource="#Mileage" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="mileageFor">
<owl:inverseOf rdf:resource="#hasMileage" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="hasPrice">
<rdf:type rdf:resource="&owl;FunctionalProperty" />
<rdfs:domain rdf:resource="#CarAds" />
<rdfs:range rdf:resource="#Price" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="priceFor">
<owl:inverseOf rdf:resource="#hasPrice" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="hasPhoneNr">
<rdf:type rdf:resource="&owl;FunctionalProperty" />
<rdfs:domain rdf:resource="#CarAds" />
<rdfs:range rdf:resource="#PhoneNr" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="phoneFor">
<owl:inverseOf rdf:resource="#hasPhoneNr" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="hasFeature">
<rdfs:domain rdf:resource="#CarAds" />
<rdfs:range rdf:resource="#Feature" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="featureFor">
<owl:inverseOf rdf:resource="#hasFeature" />
</owl:ObjectProperty>



<CarAds rdf:ID="CarAdsIns1">
<carAdsValue rdf:datatype="&xsd;string">001</carAdsValue>
</CarAds>

<Make rdf:ID="MakeIns1">
<makeValue rdf:datatype="&xsd;string">&example;MakeIns1</makeValue>
</Make>

<Model rdf:ID="ModelIns1">
<modelValue rdf:datatype="&xsd;string">&example;ModelIns1</modelValue>
</Model>

<Year rdf:ID="YearIns1">
<yearValue rdf:datatype="&xsd;string">&example;YearIns1</yearValue>
</Year>

<Mileage rdf:ID="MileageIns1">
<mileageValue rdf:datatype="&xsd;string">&example;MileageIns1</mileageValue>
</Mileage>

<Price rdf:ID="PriceIns1">
<priceValue rdf:datatype="&xsd;string">&example;PriceIns1</priceValue>
</Price>

<PhoneNr rdf:ID="PhoneNrIns1">
<phoneNrValue rdf:datatype="&xsd;string">&example;PhoneNrIns1</phoneNrValue>
</PhoneNr>

<owl:Thing rdf:about="#CarAdsIns1">
<hasMake rdf:resource="#MakeIns1" />
<hasModel rdf:resource="#ModelIns1" />
<hasYear rdf:resource="#YearIns1" />
<hasMileage rdf:resource="#MileageIns1" />
<hasPrice rdf:resource="#PriceIns1" />
<hasPhoneNr rdf:resource="#PhoneNrIns1" />
</owl:Thing>

<owl:Thing rdf:about="#MakeIns1">
<makeFor rdf:resource="#CarAdsIns1" />
</owl:Thing>

<owl:Thing rdf:about="#ModelIns1">
<modelFor rdf:resource="#CarAdsIns1" />
</owl:Thing>

<owl:Thing rdf:about="#YearIns1">
<yearFor rdf:resource="#CarAdsIns1" />
</owl:Thing>

<owl:Thing rdf:about="#MileageIns1">
<mileageFor rdf:resource="#CarAdsIns1" />
</owl:Thing>

<owl:Thing rdf:about="#PriceIns1">
<priceFor rdf:resource="#CarAdsIns1" />
</owl:Thing>

<owl:Thing rdf:about="#PhoneNrIns1">
<phoneFor rdf:resource="#CarAdsIns1" />
</owl:Thing>

</rdf:RDF>
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
ritaing Messages postés 5 Date d'inscription lundi 5 avril 2010 Statut Membre Dernière intervention 11 mai 2010
11 mai 2010 à 12:15
salut ,
void loadFile m' ouvre,lit et affiche le fichier enregistré sous format .txt dans mon disque .
je veux le parcourir et extraire ................

merci
0