How can I use Distinct on a group of bags in pig - nested

This is my input as described below:
({(Fish M.),(Fish M.),(Fish M.),(Fish M.),(Fish M.)},{(Acasuso J.),(Acasuso J.),(Acasuso J.),(Acasuso J.),(Acasuso J.)},{(8/23/2007),(8/23/2007),(8/23/2007),(8/23/2007),(8/23/2007)},{(99.84002222685783),(58.173357215875676),(PSL),(41.66666501098216),(EXW)})
I would like to do a distinct on the first and second bags to get one result each to produce an output like this:
(Fish M., Acasuso J., 8/23/2007, 99.84002222685783, 58.173357215875676, PSL, 41.66666501098216, EXW)

This script should work, I have ignored the last bag in your entry for brevity.
rr = load 'data/pig/input/Pig_DataSets/six' using CustomLoadFunction() as (one:bag{tup1:(c1:chararray)},two:bag{tup2:(c2:chararray)},three:bag{tup3:(c3:chararray)});
tt = foreach rr {
mm = two;
nn = distinct mm;
oo = one;
pp = distinct oo;
generate three,pp,nn;
};
You might have to use a custom load function because the the default loader wont work (unless you do some data cleansing). This post talks about a custom loader that might fit your scenario.

Related

How to set compound structure for two different layers if I used 2 different categories of material for wall structure , using revit api

I am trying to create a wall with 2 layers and each layer materials are different. When I try to set the CompoundStructure for the wall I am getting an exception that CompoundStructure is not valid.
CompoundStructure cStructure = CompoundStructure.CreateSimpleCompoundStructure(clayer);
wallType.SetCompoundStructure(cStructure);
Can anyone tell me how I can create compound structure for layers with different materials?
First of all, solve your task manually through the end user interface and verify that it works at all.
Then, use RevitLookup and other database exploration tools to examine the results in the BIM elements, their properties and relationships.
Once you have done that, you will have a good idea how to address the task programmatically – and have confidence that it will work as expected:
How to research to find a Revit API solution
Intimate Revit database exploration with the Python Shell
newWallMaterial = wallMaterial.Duplicate("newCreatedMaterial");
newWallmaterial2 = wallMaterial.Duplicate("NewCreatedMAterial2");
//roofMaterial3 = roofMaterial2.Duplicate("NewCreatedMAterial3");
bool usr = newWallMaterial.UseRenderAppearanceForShading;
//newWallMaterial.Color = BuiltInTypeParam.materialCol;
foreach (Layers layer in layers)
{
if (layer.layerId == 0)
{
c = new CompoundStructureLayer(layer.width, layer.materialAssignement, newWallMaterial.Id);
newWallMaterial.Color = color;
clayer.Add(c);
}
if (layer.layerId == 1)
{
c1 = new CompoundStructureLayer(layer.width, layer.materialAssignement, newWallmaterial2.Id);
newWallmaterial2.Color = color;
clayer.Add(c1);
}

Append a number to a variable name in GDScript

I'd like to append an integer to the end of several variable names in GDSCript.
I'm working on a roguelike and I've decided to organise themed tilesets and NPC's and group them in folders by number (ie, theme 1 may be a crypt filled with undead, theme 2 a forest filled with animals).
The idea is that at the start of level generation I can randomly select a number, generate a level and fill it with corresponding enemies.
For example (assuming the random number is 1)
tileset_to_use = tileset_1
NPC_mid_boss = folder_1/mid_boss
NPC_end_boss = folder_1/end_boss
Aside from a series of nested IF statements along the lines of:
if RNG = 1:
tileset_to_use = tileset_1
NPC_mid_boss = folder_1/mid_boss
NPC_end_boss = folder_1/end_boss
elif RNG = 2:
tileset_to_use = tileset_2
etc...
...what would be a more efficient way of doing this? Something like tileset+RNG
I've looked into using dictionaries but, unless I've misunderstood them, they seem to be used for accessing values rather than generating variable names.
If all your themes share the same exact structure, you can do something similar to what Christopher Bennett proposes. Another option that may give you more flexibility, at the expense of possibly more repetition, is something like this:
# Defined at class level
const THEMES = [
# Theme 1
{
tileset = 'tileset_1',
NPC_mid_boss = 'folder_1/mid_boss',
NPC_end_boss = 'folder_1/end_boss',
# ...
},
# Theme 2
{
tileset = 'tileset_2',
NPC_mid_boss = 'folder_2/mid_boss',
NPC_end_boss = 'folder_2/end_boss',
# ...
},
# ...
]
func my_func():
# Pick a random theme
var theme = THEMES[randi() % THEMES.size()]
tileset_to_use = theme.tileset
# ...
This also allows you to add more properties like arbitrary strings (e.g. theme name) or other things, and can be externalized to something like a JSON document if you want. But again, it requires more manual setup.
Sorry, I think I misunderstood your question when I posted my first comment. Would something like this work?
var RNG = randi()%1-(total number of tilesets);
var tileset_to_use = (str("tileset_",RNG));
NPC_mid_boss = (str("folder_",RNG,"/mid_boss"));

Get the label of a MathJax equation

How can I get the label of an equation? I'm attempting to reprocess an equation with a label, but I have to delete the label from MathJax.Extension["TeX/AMSmath"].labels first, for which the label must be known...
I know I can scan through the source text for the label MathJax.Hub.getAllJax("mathDiv")[0}.SourceElement().find("\label(") (...), but this seems needlessly complicated. Is there a better way?
There's no built-in API for this.
If you don't need to keep labels, then the reset in the comment above is probably the best way to go about it:
MathJax.Extension["TeX/AMSmath"].labels = {}
A quick and dirty way to get the IDs is to leverage the fact that they end up in the output. So you can just get all the IDs in the output, e.g.,
const math = MathJax.Hub.getAllJax()[0];
const nodesWithIds = document.getElementById(math.root.inputID).previousSibling.querySelectorAll('[id]');
const ids = [];
for (node of nodesWithIds) ids.push(node.id);
A cleaner and perhaps conceptually easier way would be to leverage MathML (which is essentially the internal format): the \label{} always ends up on an mlabeledtr. The trouble is that you'd have to re-parse that, e.g.,
const temp = document.createElement('span');
temp.innerHTML = math.root.toMathML();
const nodesWithIds = temp.querySelectorAll('mlabeledtr [id]');
const ids = [];
for (node of nodesWithIds) ids.push(node.id);
This will make sure the array only has relevant IDs in them (and the contents of the nodes should correspond to \label{}.
I suppose with helper libraries it might be easier to dive into the math.root object directly and look for IDs recursively (in its data key).

Checking Ontology Consistency in Run Time

I have a program that uses Jena to load an .owl Ontology designed in Protege. I am trying to do reasoning over it using Pellet in a way that if I add some statements in run time to model be able to check its consistency. For example I have 'Method', 'Signature' and 'hasSignature' concepts in which hasSignature is an object property. I have following axiom:
Method hasSignature exactly 1 Signature
When I add some instance statements in order to violate above axiom no inconsistency is reported. Here is my code:
List<Statement> statements = new ArrayList<>();
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF);
FileManager.get().readModel(model, "Ontologies\\Ontology.owl");
OntClass Method = model.createClass( ns + "Method");
Individual method1 = Method.createIndividual(ns + "method1");
OntClass Signature = model.createClass( ns + "Signature");
Individual sign1 = Signature.createIndividual(ns + "sign1");
Individual sign2 = Signature.createIndividual(ns + "sign2");
Property hasSignature = model.createObjectProperty(ns + "hasSignature");
Statement st = model.createStatement(method1, hasSignature, sign1);
statements.add(st);
Statement st1 = model.createStatement(method1, hasSignature, sign2);
statements.add(st1);
Reasoner reasoner = PelletReasonerFactory.theInstance().create();
InfModel inf = ModelFactory.createInfModel(reasoner, model.add(statements));
System.out.println(inf.validate().isValid());
What's wrong? Why it doesn't work?
You have not declared sign1 and sign2 to be different from each other. So, since it is possible for the two individuals to be sameAs each other, the reasoner has determined that that's the only case not rising a clash. Therefore the ontology is consistent.

Construct Completely Ad-hoc Slick Query

Pardon my newbieness but im trying to build a completely ad-hoc query builder using slick. From our API, I will get a list of strings that is representative of the table, as well as another list that represents the filter for the tables, munge then together to create a query. The hope is that I can take these and create the inner join. A similar example of what i'm trying to do would be JIRA's advanced query builder.
I've been trying to build it using reflection but I've come across so many blocking issues i'm wondering if this is even possible at all.
In code this is what I want to do:
def getTableQueryFor(tbl:String):TableQuery[_] = {
... a matcher that returns a tableQueries?
... i think the return type is incorrect b/c erasure?
}
def getJoinConditionFor:(tbl1:String, tbl2:String) => scala.slick.lifted.Column[Boolean] = (l:Coffees,r:Suppies) => {
...a matcher
}
Is the Following even possible?
val q1 = getTableQueryFor("coffee")
val q2 = getTableQueryFor("supply")
val q3 = q1.innerJoin.q2.on(getJoinCondition("coffee", "supply")
edit: Fixed grammar issue.

Resources