prettyPrinter Ntriple + fonction de création de Ntriple

This commit is contained in:
Rochas
2025-02-13 23:49:35 +01:00
parent 2df633c6a1
commit 13dbf3882d
3 changed files with 69 additions and 13 deletions

View File

@@ -19,22 +19,22 @@ entity ::= Entity(String)
turtle ::= Turtle(phrase*)
phrase ::= Phrase(entity, aff*)
aff.s = entity.val
aff*.s = entity.val
aff ::= Aff(entity, complement*)
complement.s = aff.s
complement.v = entity.val
complement*.s = aff.s
complement*.v = entity.val
complement ::= Complement(entity)
phrase.c = entity.val
complement.c = entity.val
| Complement_Text(String)
phrase.c = String.self
complement.c = String.self
entity ::= Entity(String)
entity.val=String.self
```
|TAD |Nom d'attribut |Type | Polarité
|----------------|-----------------|---------------------|---------|
|phrase |s |String |H
|aff |s |String |H
|aff |v |String |H
|phrase | |String |H
|aff | |String |H
|complement |s |String |H
|complement |v |String |H
|complement |c |String |H/S

View File

@@ -22,6 +22,7 @@ options {
}
prog : bloc EOF
{$t = new TurtleAST()}
;
bloc : sujet listvc P // <entity> list.
;
@@ -47,6 +48,6 @@ comp : LC ID RC //<ID>
entity : ID
;
turtle
returns[TurtleAST t]: EOF { $t = null ; };
turtle returns[TurtleAST t]:
EOF { $t = null ; }
;

View File

@@ -1,8 +1,63 @@
package TP1;
public class TurtleAST {
public TurtleAST(){
import java.util.ArrayList;
import java.util.List;
public class TurtleAST {
sealed interface Ntriple{}
sealed interface Phrase{}
sealed interface Entity{}
record NtripleImp(List<PhraseImp> phrases) implements Ntriple{
public String toString(){
String str = "";
for (PhraseImp phrase : this.phrases) {
str += phrase.toString() + ".\n" ;
}
return str;
}
}
record PhraseImp(EntityImp s, EntityImp v, EntityImp c) implements Phrase{
public String toString(){
return s.toString() + " " + v.toString() + " " + c.toString();
}
}
record EntityImp(String val, Boolean isText) implements Entity{
public String toString(){
String str="";
if(isText) str = "\"" + val + "\"";
else str = "<" + val + ">";
return str;
}
}
String currentSujet;
String currentVerbe;
List<PhraseImp> listPhrases;
Ntriple ntriple;
public TurtleAST(){
this.listPhrases = new ArrayList<>();
}
public void addSujet(String sujet){
this.currentSujet=sujet;
}
public void addVerbe(String verbe){
this.currentVerbe=verbe;
}
public void addComplement(String complement, Boolean isText){
EntityImp s = new EntityImp(currentSujet, false);
EntityImp v = new EntityImp(currentVerbe, false);
EntityImp c = new EntityImp(complement, isText);
PhraseImp phrase = new PhraseImp(s,v,c);
this.listPhrases.add(phrase);
}
public void finishNtriple(){
this.ntriple = new NtripleImp(listPhrases);
}
}