Skip to content
Snippets Groups Projects
Commit a9b2fe6e authored by Eike Cochu's avatar Eike Cochu
Browse files

removed articles from topic show

parent dbc61a66
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; ...@@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import de.vipra.cmd.ex.AnalyzerException; import de.vipra.cmd.ex.AnalyzerException;
import de.vipra.cmd.file.DTMVocabulary;
import de.vipra.util.Config; import de.vipra.util.Config;
import de.vipra.util.Constants; import de.vipra.util.Constants;
import de.vipra.util.ConvertStream; import de.vipra.util.ConvertStream;
...@@ -108,13 +109,23 @@ public class DTMAnalyzer extends Analyzer { ...@@ -108,13 +109,23 @@ public class DTMAnalyzer extends Analyzer {
@Override @Override
public ConvertStream<TopicFull> getTopicDefinitions() throws AnalyzerException { public ConvertStream<TopicFull> getTopicDefinitions() throws AnalyzerException {
// TODO Auto-generated method stub DTMVocabulary vocab;
try {
vocab = new DTMVocabulary(modelDir, false);
} catch (IOException e) {
throw new AnalyzerException(e);
}
return null; return null;
} }
@Override @Override
public ConvertStream<List<TopicRef>> getTopics() throws AnalyzerException { public ConvertStream<List<TopicRef>> getTopics() throws AnalyzerException {
// TODO Auto-generated method stub DTMVocabulary vocab;
try {
vocab = new DTMVocabulary(modelDir, false);
} catch (IOException e) {
throw new AnalyzerException(e);
}
return null; return null;
} }
......
...@@ -98,10 +98,14 @@ public class JGibbAnalyzer extends Analyzer { ...@@ -98,10 +98,14 @@ public class JGibbAnalyzer extends Analyzer {
} }
// get all lines that follow until the next topic is // get all lines that follow until the next topic is
// discovered (line does not start with a tab) // discovered (line does not start with a tab). Cut off
// after k words are gathered.
String nextLine; String nextLine;
int words = 0;
while ((nextLine = nextLine()) != null) { while ((nextLine = nextLine()) != null) {
if (nextLine.startsWith("\t")) { if (nextLine.startsWith("\t")) {
if (words > Constants.K_TOPIC_WORDS)
continue;
String[] parts = nextLine.trim().split("\\s+"); String[] parts = nextLine.trim().split("\\s+");
try { try {
Word word = wordMap.get(parts[0]); Word word = wordMap.get(parts[0]);
...@@ -109,6 +113,7 @@ public class JGibbAnalyzer extends Analyzer { ...@@ -109,6 +113,7 @@ public class JGibbAnalyzer extends Analyzer {
Constants.LIKELINESS_PRECISION); Constants.LIKELINESS_PRECISION);
TopicWord topicWord = new TopicWord(word, likeliness); TopicWord topicWord = new TopicWord(word, likeliness);
topicWords.add(topicWord); topicWords.add(topicWord);
words++;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
log.error("could not parse number in line: " + nextLine); log.error("could not parse number in line: " + nextLine);
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
......
...@@ -2,6 +2,6 @@ db.host=localhost ...@@ -2,6 +2,6 @@ db.host=localhost
db.port=27017 db.port=27017
db.name=test db.name=test
tm.processor=corenlp tm.processor=corenlp
tm.analyzer=dtm tm.analyzer=jgibb
tm.saveallwords=false tm.saveallwords=false
tm.dtmpath=/home/eike/Downloads/dtm_release/dtm/main tm.dtmpath=/home/eike/Downloads/dtm_release/dtm/main
\ No newline at end of file
...@@ -32,6 +32,7 @@ import de.vipra.util.StringUtils; ...@@ -32,6 +32,7 @@ import de.vipra.util.StringUtils;
import de.vipra.util.ex.ConfigException; import de.vipra.util.ex.ConfigException;
import de.vipra.util.ex.DatabaseException; import de.vipra.util.ex.DatabaseException;
import de.vipra.util.model.ArticleFull; import de.vipra.util.model.ArticleFull;
import de.vipra.util.model.Topic;
import de.vipra.util.model.TopicFull; import de.vipra.util.model.TopicFull;
import de.vipra.util.service.MongoService; import de.vipra.util.service.MongoService;
import de.vipra.util.service.Service.QueryBuilder; import de.vipra.util.service.Service.QueryBuilder;
...@@ -109,9 +110,6 @@ public class TopicResource { ...@@ -109,9 +110,6 @@ public class TopicResource {
} }
if (topic != null) { if (topic != null) {
List<ArticleFull> articles = dbArticles.getMultiple(QueryBuilder.builder().criteria("topics.topic", topic));
topic.setArticles(articles);
return res.ok(topic); return res.ok(topic);
} else { } else {
res.addError(new APIError(Response.Status.NOT_FOUND, "Resource not found", res.addError(new APIError(Response.Status.NOT_FOUND, "Resource not found",
...@@ -120,6 +118,24 @@ public class TopicResource { ...@@ -120,6 +118,24 @@ public class TopicResource {
} }
} }
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("{id}/articles")
public Response getArticles(@PathParam("id") String id, @QueryParam("fields") String fields) {
Wrapper<List<ArticleFull>> res = new Wrapper<>();
try {
Topic topic = new Topic(MongoUtils.objectId(id));
List<ArticleFull> articles = dbArticles.getMultiple(
QueryBuilder.builder().criteria("topics.topic", topic).fields(true, StringUtils.getFields(fields)));
return res.ok(articles);
} catch (Exception e) {
e.printStackTrace();
res.addError(new APIError(Response.Status.BAD_REQUEST, "Error", e.getMessage()));
return res.badRequest();
}
}
@PUT @PUT
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
......
...@@ -27,14 +27,6 @@ ...@@ -27,14 +27,6 @@
</tbody> </tbody>
</table> </table>
<h3>Articles <hide-link target="#articles"/></h3>
<ul class="dashed">
<li ng-repeat="article in ::topic.articles">
<article-link article="article"/>
</li>
</ul>
<h3>Words <hide-link target="#words"/></h3> <h3>Words <hide-link target="#words"/></h3>
<table class="table table-bordered table-condensed" id="words"> <table class="table table-bordered table-condensed" id="words">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment