mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
preserve the order of the sentences in phrases.xml in the UI
This commit is contained in:
@@ -3,9 +3,8 @@ package se.chalmers.phrasebook.backend;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.grammaticalframework.pgf.Expr;
|
||||
import org.grammaticalframework.ui.android.R;
|
||||
@@ -33,8 +32,8 @@ public class Model {
|
||||
}
|
||||
|
||||
phrases = new ArrayList<SyntaxTree>();
|
||||
for (String s : parser.getSentencesData().keySet()) {
|
||||
phrases.add(parser.getSyntaxTree(s));
|
||||
for (Map.Entry<String,String> entry : parser.getSentencesData()) {
|
||||
phrases.add(parser.getSyntaxTree(entry.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,10 +51,10 @@ public class Model {
|
||||
currentPhrase.setSelectedChild(optionIndex, target, childIndex, isAdvanced);
|
||||
}
|
||||
|
||||
public ArrayList<String> getSentencesInCurrentPhrasebook() {
|
||||
public List<String> getSentencesInCurrentPhrasebook() {
|
||||
ArrayList<String> sentences = new ArrayList<String>();
|
||||
for (int i = 0; i < phrases.size(); i++) {
|
||||
sentences.add(parser.getSentencesData().get(phrases.get(i).getId()));
|
||||
for (Map.Entry<String,String> entry : parser.getSentencesData()) {
|
||||
sentences.add(entry.getValue());
|
||||
}
|
||||
return sentences;
|
||||
}
|
||||
@@ -67,15 +66,14 @@ public class Model {
|
||||
}
|
||||
|
||||
public String getDescFromPos(int pos) {
|
||||
return parser.getSentencesData()
|
||||
.get((String) (parser.getSentencesData().keySet().toArray()[pos]));
|
||||
return parser.getSentencesData().get(pos).getValue();
|
||||
}
|
||||
|
||||
public void setNumeralCurrentPhrase() {
|
||||
for (int i = 0; i < parser.getSentencesData().values().size(); i++) {
|
||||
if ((parser.getSentencesData().keySet().toArray()[i]).equals("NNumeral")) {
|
||||
currentPhrase = parser.getSyntaxTree((String) parser.getSentencesData()
|
||||
.keySet().toArray()[i]);
|
||||
for (int i = 0; i < parser.getSentencesData().size(); i++) {
|
||||
String key = parser.getSentencesData().get(i).getKey();
|
||||
if (key.equals("NNumeral")) {
|
||||
currentPhrase = parser.getSyntaxTree(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,8 @@ import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
@@ -41,20 +40,20 @@ public class XMLParser {
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, String> getSentencesData() {
|
||||
public List<Map.Entry<String, String>> getSentencesData() {
|
||||
String[] result;
|
||||
HashMap<String, String> sentenceMap = new HashMap<String, String>();
|
||||
List<Map.Entry<String, String>> sentences = new ArrayList<Map.Entry<String, String>>();
|
||||
|
||||
NodeList sentences = document.getElementsByTagName("sentence");
|
||||
int nbrOfSentences = sentences.getLength();
|
||||
NodeList sentencesList = document.getElementsByTagName("sentence");
|
||||
int nbrOfSentences = sentencesList.getLength();
|
||||
|
||||
for (int i = 0; i < nbrOfSentences; i++) {
|
||||
String desc = sentences.item(i).getAttributes().getNamedItem("desc").getNodeValue();
|
||||
String id = sentences.item(i).getAttributes().getNamedItem("id").getNodeValue();
|
||||
String desc = sentencesList.item(i).getAttributes().getNamedItem("desc").getNodeValue();
|
||||
String id = sentencesList.item(i).getAttributes().getNamedItem("id").getNodeValue();
|
||||
if (desc != null && id != null)
|
||||
sentenceMap.put(id, desc);
|
||||
sentences.add(new HashMap.SimpleEntry<String,String>(id, desc));
|
||||
}
|
||||
return sentenceMap;
|
||||
return sentences;
|
||||
}
|
||||
|
||||
public SyntaxTree getAdvancedOptionSyntaxTree() {
|
||||
|
||||
Reference in New Issue
Block a user